I'm fairly sure this is indeed a bug.
The problem is bigger than CSS styling tho : when using "login_form.custom"
it seems that pretty much all of the standard web2py auth methods are
broken.
For example, I have a 'default.py' controller like this:
> def user():
> if request.args[0] == 'login':
> response.view = 'user/login.load'
> return dict(form=auth())
And a view 'user/login.load' like this:
> {{ =login_form.custom.begin }}
> <div class="clearfix form-login-sign-up_row1">
> {{ =login_form.custom.widget.email }}
> </div>
> <div class="clearfix form-login-sign-up_row2">
> {{ =login_form.custom.widget.password }}
> </div>
> <div class="clearfix form-login-sign-up_row3">
> <button class="btn btn-pink btn-30" type="submit">Connexion</button>
> <span class="password-forgotten"><a href="#password-forget-content"
> id="password-forget-action">Mot de passe oublié ?</a></span>
> </div>
> <p class="error clearfix" id="login-error"></p>
> {{ #=login_form.custom.end # buggy }}
> <div style="display:none;">
> <input name="_formname" type="hidden" value="login">
> </div>
> </form>
Now when I go to '/user/login' (or use the LOADed ajax component), my form
gets styled properly but validation doesn't trigger out of the box.
I put my login & pwd but nothing happens.
If I further customize my controller and add a form.process(...) method,
errors are displayed but validation still doesn't occur : my pwd gets
hashed but isn't validated against the auth_user table. It seems I must
recode the whole login process which is possible but unpythonic ("don't
repeat yourself")
On the other hand, if I just remove the "response.view = 'user/login.load'"
in my controller then my form is ugly but actually works...
Question is : how do I customize my login form, while still benefitting
from web2py's auth mechanisms ?
On Monday, April 21, 2014 12:35:56 PM UTC+2, Marin Pranjić wrote:
>
> This sounds like a bug.
>
> Marin (mobile)
> On Apr 18, 2014 9:10 PM, "Louis Amon" <[email protected] <javascript:>>
> wrote:
>
>> I'm trying to build an Ajax-based login form using web2py's LOAD() helper.
>>
>> I made a controller named 'users.py', in which I defined a 'signin()'
>> function :
>>
>>> def signin():
>>> form=auth.login()
>>> if form.process(formname=None).accepted: #hideerrors=True
>>> response.flash = 'form accepted'
>>> print form.vars
>>> elif form.errors:
>>> print form.errors
>>> return dict(login_form=form)
>>
>>
>> The corresponding view ('users/signin.load') is as follows:
>>
>>> <h2 class="form-login-sign-up_title">S'identifier</h2>
>>> <p class="form-login-sign-up_subtitle">J'ai déjà un compte</p>
>>> {{ =login_form.custom.begin }}
>>> {{ =login_form.custom.widget.email }}
>>> {{ =login_form.custom.widget.password }}
>>> {{ =login_form.custom.end }}
>>
>>
>> Now if I go to the url : [...]/users/signin.load, my form displays
>> correctly but validation doesn't occur upon submitting the form. It's as
>> though the displayed form isn't linked to the one defined in the controller.
>>
>>
>> After some research, I found that if I change my view to
>>
>>> {{=login_form}}
>>
>>
>> Then validation occurs correctly. My form isn't customized correctly
>> though (obviously).
>>
>> Further research indicates that, using the first view, the rendered html
>> code actually contains two signatures for the FORM (just before the </form>
>> tag):
>>
>>> <div style="display:none;">
>>> <input name="_next" type="hidden" value="/">
>>> <input name="_formkey" type="hidden"
>>> value="c33c0072-ac25-461f-8e37-0ba48cc53dc2">
>>> </div>
>>
>>
>> And:
>>
>> <div style="display:none;">
>>> <input name="_next" type="hidden" value="/">
>>> <input name="_formkey" type="hidden"
>>> value="553bae82-7864-4620-93ee-d54eeea366bf">
>>> <input name="_formname" type="hidden" value="login">
>>> </div>
>>
>>
>>
>> My guess is that, having two different signatures, web2py gets confused
>> about how to manage this form.
>> I tried several things like putting "formname=None" in the process()
>> function, but the only way I got my ajax component to work so far is by not
>> customizing my form.
>>
>> Any workaround ?
>>
>> --
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.