[web2py] Re: Auth.user is still NULL after a successful login
Hi, I studied the source code of auth.login() and found that all the validations are applied within the login method itself. The error message is automatically written to an element of class flash via setting session.flash to auth.messages.invalid_login. I modified my view code to include the class attribute of the and set its value to "flash" as below: {{=response.flash}} Now one can modify the CSS and JS to control how the element is displayed. As far as I understand, to achieve the required functionality of displaying form errors via form.errors.email etc., one can either extend Auth and override the login() method or build a custom login functionality. Let me know if there is an easier way On Tuesday, March 13, 2012 11:02:54 AM UTC+5:30, Sushant Taneja wrote: > > Hi, > > Ah, I forget that form.custom.begin is an XML object (more like a string) >> and doesn't change when you directly manipulate the form object itself. You >> could do: >> >> f.custom.begin = '%s id="login">' % f.custom.begin[:-1] >> > > I added the above code line in controller. The attribute id was added to > the form element, but the whole being tag was rendered as : > > *"* > *"* > * > * > i.e form is displayed a text element and hence JS was not working on it. > > > >> if login_form.errors: >>> login_form.errors.email='Email/Password does not match' >>> >>> return dict(login_form=login_form) >>> >>> In the view I have : >>> >>> >>> >>> >>> >> >> Maybe something like: >> >> {{if login_form.errors.email:}} >> >> {{=login_form.errors.email}} >> >> {{pass}} >> >> > I didn't want to render the element dynamically, so I tried the > following: > > > > {{if login_form.errors:}} > {{=login_form.errors.email}} > {{pass}} > > > > But nothing is happening. > In usual cases, if I leave the field empty or enter an invalid email > address, an error is displayed but not in this case. > Even if there are errors, the *login_form.errors* object is empty and > nothing is displayed. > > How does auth handle authentication errors ? > >
[web2py] Re: Auth.user is still NULL after a successful login
Hi, Ah, I forget that form.custom.begin is an XML object (more like a string) > and doesn't change when you directly manipulate the form object itself. You > could do: > > f.custom.begin = '%s id="login">' % f.custom.begin[:-1] > I added the above code line in controller. The attribute id was added to the form element, but the whole being tag was rendered as : *"* *"* * * i.e form is displayed a text element and hence JS was not working on it. > if login_form.errors: >> login_form.errors.email='Email/Password does not match' >> >> return dict(login_form=login_form) >> >> In the view I have : >> >> >> >> >> > > Maybe something like: > > {{if login_form.errors.email:}} > > {{=login_form.errors.email}} > > {{pass}} > > I didn't want to render the element dynamically, so I tried the following: {{if login_form.errors:}} {{=login_form.errors.email}} {{pass}} But nothing is happening. In usual cases, if I leave the field empty or enter an invalid email address, an error is displayed but not in this case. Even if there are errors, the *login_form.errors* object is empty and nothing is displayed. How does auth handle authentication errors ?
[web2py] Re: Auth.user is still NULL after a successful login
> > I found a workaround to the problem. I need to assign the id "login" to > the form so that certain CSS and JS can be applied to the form elements. > Since I was unable to assign id to the form, I assigned the id "login" to > the table element. The login is now working. > Ah, I forget that form.custom.begin is an XML object (more like a string) and doesn't change when you directly manipulate the form object itself. You could do: f.custom.begin = '%s id="login">' % f.custom.begin[:-1] if login_form.errors: > login_form.errors.email='Email/Password does not match' > > return dict(login_form=login_form) > > In the view I have : > > > > > Maybe something like: {{if login_form.errors.email:}} {{=login_form.errors.email}} {{pass}} Anthony
[web2py] Re: Auth.user is still NULL after a successful login
Hi, I found a workaround to the problem. I need to assign the id "login" to the form so that certain CSS and JS can be applied to the form elements. Since I was unable to assign id to the form, I assigned the id "login" to the table element. The login is now working. But another problem has surfaced. Now whenever I enter correct the credentials I am successfully able to login but whenever I enter false credentials, I am unable to see any form errors. How invalid login is handled by Auth ? I want to show the error "Email/Password not matching" below my form. How could I do that ? My controller code is : def index(): login_form = auth.login() # Configure form fields login_form.custom.widget.email['_value']='Email' login_form.custom.widget.email['_data']='Email' login_form.custom.widget.password['_value']='Password' login_form.custom.widget.password['_data']='Password' login_form.custom.submit['_value']='Login' # Configure form properties # login_form['_id']='login' if login_form.errors: login_form.errors.email='Email/Password does not match' return dict(login_form=login_form) In the view I have : {{=login_form.custom.begin}} {{=login_form.custom.widget.email}} {{=login_form.custom.widget.password}} Forgot Password? {{=login_form.custom.submit}} {{=login_form.custom.end}} On Tuesday, March 13, 2012 12:25:53 AM UTC+5:30, Anthony wrote: > > Hmm, works when I try it. Can you show the full controller code you have > now? > > On Monday, March 12, 2012 2:46:57 PM UTC-4, Sushant Taneja wrote: >> >> The rendered form is as: >> >> >> ... >> >> >> It has no attribute id. >> >> On Tuesday, March 13, 2012 12:05:02 AM UTC+5:30, Anthony wrote: >>> >>> What's not working? When you view the HTML code of the rendered page in >>> the browser, is the id not there, or is it just that some client-side CSS >>> or JS isn't working as expected? If the latter, the problem could be that >>> you have put the form beginning and ending code inside the >>> tags rather than outside, where they belong. Should be: >>> >>> {{=login_form.custom.begin}} >>> >>> [snip] >>> >>> {{=login_form.custom.end}} >>> >>> Anthony >>> >>> On Monday, March 12, 2012 2:07:20 PM UTC-4, Sushant Taneja wrote: Hi, I tried both but none seems to be working. Here's my view code: {{=login_form.custom.begin}} >>> colspan='2'>{{=login_form.custom.widget.email}} >>> colspan='2'>{{=login_form.custom.widget.password}} >>> class="flipLink">Forgot Password? {{=login_form.custom.submit}} {{=login_form.custom.end}} Please suggest. On Monday, March 12, 2012 11:32:04 PM UTC+5:30, Anthony wrote: > > That should work. Can you show the view code? Also, note you can just > do: > > login_form['_id'] = 'login' > > Anthony > > On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: >> >> I tried customizing the form. I have to set the id of the form >> element to login. >> To achieve the above I used the following statement in controller: >> >> login_form = auth.login() >> >> # Configure form properties >> login_form.attributes['_id']='login' >> >> But it's not working. The generated form does not contain any id >> attribute. >> Is there another way to do it ? >> >> Thanks, >> Sushant >> >> On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: >>> >>> Thanks for an explanatory answer. >>> I will try this out. >>> >>> On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: def index(): > > login_form = auth.login() > if login_form.process(session=None,formname='login').accepted: > pass > elif login_form.errors: > response.write(request.vars) > return dict() > > to display the form I have used the SQLForm in HTML technique as > mentioned in the web2py book > > Whenever user enters the correct email and password. auth_event > registers a login event with the description *User 1 Logged In*. > The next pr
[web2py] Re: Auth.user is still NULL after a successful login
Hmm, works when I try it. Can you show the full controller code you have now? On Monday, March 12, 2012 2:46:57 PM UTC-4, Sushant Taneja wrote: > > The rendered form is as: > > > ... > > > It has no attribute id. > > On Tuesday, March 13, 2012 12:05:02 AM UTC+5:30, Anthony wrote: >> >> What's not working? When you view the HTML code of the rendered page in >> the browser, is the id not there, or is it just that some client-side CSS >> or JS isn't working as expected? If the latter, the problem could be that >> you have put the form beginning and ending code inside the >> tags rather than outside, where they belong. Should be: >> >> {{=login_form.custom.begin}} >> >> [snip] >> >> {{=login_form.custom.end}} >> >> Anthony >> >> On Monday, March 12, 2012 2:07:20 PM UTC-4, Sushant Taneja wrote: >>> >>> Hi, >>> >>> I tried both but none seems to be working. Here's my view code: >>> >>> >>> >>> {{=login_form.custom.begin}} >>> >>> >> colspan='2'>{{=login_form.custom.widget.email}} >>> >>> >>> >> colspan='2'>{{=login_form.custom.widget.password}} >>> >>> >>> >> class="flipLink">Forgot Password? >>> {{=login_form.custom.submit}} >>> >>> {{=login_form.custom.end}} >>> >>> >>> Please suggest. >>> >>> On Monday, March 12, 2012 11:32:04 PM UTC+5:30, Anthony wrote: That should work. Can you show the view code? Also, note you can just do: login_form['_id'] = 'login' Anthony On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: > > I tried customizing the form. I have to set the id of the form element > to login. > To achieve the above I used the following statement in controller: > > login_form = auth.login() > > # Configure form properties > login_form.attributes['_id']='login' > > But it's not working. The generated form does not contain any id > attribute. > Is there another way to do it ? > > Thanks, > Sushant > > On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: >> >> Thanks for an explanatory answer. >> I will try this out. >> >> On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: >>> >>> def index(): login_form = auth.login() if login_form.process(session=None,formname='login').accepted: pass elif login_form.errors: response.write(request.vars) return dict() to display the form I have used the SQLForm in HTML technique as mentioned in the web2py book Whenever user enters the correct email and password. auth_event registers a login event with the description *User 1 Logged In*. The next property redirects the URL to /user/profile but auth.user object is *None.* >>> >>> auth.login() handles it's own form processing, and it uses the >>> session when calling form.accepts (which adds a hidden _formkey field >>> to >>> the form, which must be present upon form submission). In your code, >>> you do >>> not return the form object to the view, which means your view cannot >>> include the hidden _formkey field, which is therefore not submitted >>> with >>> the form. So, when the form is submitted, the form.accepts in >>> auth.login() >>> fails, which means the user object is never stored in session.auth.user >>> -- >>> hence, auth.user is None. The reason the login submission is successful >>> is >>> that your index() function then does its own processing of the login >>> form, >>> which is successful -- but your explicit call to login_form.process() >>> does >>> not do anything to set auth.user, so it is never set. >>> >>> In short, you should not be doing your own processing of the login >>> form -- let auth.login() handle that. And if you want to customize the >>> form >>> display in the view, you still have to return the form to the view so >>> you >>> can include the hidden _formkey and _formname fields in the form (you >>> can >>> use form.custom.end to do that). >>> >>> Anthony >>> >> On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: > > I tried customizing the form. I have to set the id of the form element > to login. > To achieve the above I used the following statement in controller: > > login_form = auth.login() > > # Configure form properties > login_form.attributes['_id']='login' > > But it's not working. The generated form
[web2py] Re: Auth.user is still NULL after a successful login
The rendered form is as: ... It has no attribute id. On Tuesday, March 13, 2012 12:05:02 AM UTC+5:30, Anthony wrote: > > What's not working? When you view the HTML code of the rendered page in > the browser, is the id not there, or is it just that some client-side CSS > or JS isn't working as expected? If the latter, the problem could be that > you have put the form beginning and ending code inside the > tags rather than outside, where they belong. Should be: > > {{=login_form.custom.begin}} > > [snip] > > {{=login_form.custom.end}} > > Anthony > > On Monday, March 12, 2012 2:07:20 PM UTC-4, Sushant Taneja wrote: >> >> Hi, >> >> I tried both but none seems to be working. Here's my view code: >> >> >> >> {{=login_form.custom.begin}} >> >> > colspan='2'>{{=login_form.custom.widget.email}} >> >> >> > colspan='2'>{{=login_form.custom.widget.password}} >> >> >> > class="flipLink">Forgot Password? >> {{=login_form.custom.submit}} >> >> {{=login_form.custom.end}} >> >> >> Please suggest. >> >> On Monday, March 12, 2012 11:32:04 PM UTC+5:30, Anthony wrote: >>> >>> That should work. Can you show the view code? Also, note you can just do: >>> >>> login_form['_id'] = 'login' >>> >>> Anthony >>> >>> On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: I tried customizing the form. I have to set the id of the form element to login. To achieve the above I used the following statement in controller: login_form = auth.login() # Configure form properties login_form.attributes['_id']='login' But it's not working. The generated form does not contain any id attribute. Is there another way to do it ? Thanks, Sushant On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: > > Thanks for an explanatory answer. > I will try this out. > > On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: >> >> def index(): >>> >>> login_form = auth.login() >>> if login_form.process(session=None,formname='login').accepted: >>> pass >>> elif login_form.errors: >>> response.write(request.vars) >>> return dict() >>> >>> to display the form I have used the SQLForm in HTML technique as >>> mentioned in the web2py book >>> >>> Whenever user enters the correct email and password. auth_event >>> registers a login event with the description *User 1 Logged In*. >>> The next property redirects the URL to /user/profile but auth.user >>> object is *None.* >>> >> >> auth.login() handles it's own form processing, and it uses the >> session when calling form.accepts (which adds a hidden _formkey field to >> the form, which must be present upon form submission). In your code, you >> do >> not return the form object to the view, which means your view cannot >> include the hidden _formkey field, which is therefore not submitted with >> the form. So, when the form is submitted, the form.accepts in >> auth.login() >> fails, which means the user object is never stored in session.auth.user >> -- >> hence, auth.user is None. The reason the login submission is successful >> is >> that your index() function then does its own processing of the login >> form, >> which is successful -- but your explicit call to login_form.process() >> does >> not do anything to set auth.user, so it is never set. >> >> In short, you should not be doing your own processing of the login >> form -- let auth.login() handle that. And if you want to customize the >> form >> display in the view, you still have to return the form to the view so >> you >> can include the hidden _formkey and _formname fields in the form (you >> can >> use form.custom.end to do that). >> >> Anthony >> > >>> On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: I tried customizing the form. I have to set the id of the form element to login. To achieve the above I used the following statement in controller: login_form = auth.login() # Configure form properties login_form.attributes['_id']='login' But it's not working. The generated form does not contain any id attribute. Is there another way to do it ? Thanks, Sushant On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: > > Thanks for an explanatory answer. > I will try this out. > > On Monday, March 12, 2012 7:49:28 PM UTC+5:30, An
[web2py] Re: Auth.user is still NULL after a successful login
What's not working? When you view the HTML code of the rendered page in the browser, is the id not there, or is it just that some client-side CSS or JS isn't working as expected? If the latter, the problem could be that you have put the form beginning and ending code inside the tags rather than outside, where they belong. Should be: {{=login_form.custom.begin}} [snip] {{=login_form.custom.end}} Anthony On Monday, March 12, 2012 2:07:20 PM UTC-4, Sushant Taneja wrote: > > Hi, > > I tried both but none seems to be working. Here's my view code: > > > > {{=login_form.custom.begin}} > > colspan='2'>{{=login_form.custom.widget.email}} > > > colspan='2'>{{=login_form.custom.widget.password}} > > > class="flipLink">Forgot Password? > {{=login_form.custom.submit}} > > {{=login_form.custom.end}} > > > Please suggest. > > On Monday, March 12, 2012 11:32:04 PM UTC+5:30, Anthony wrote: >> >> That should work. Can you show the view code? Also, note you can just do: >> >> login_form['_id'] = 'login' >> >> Anthony >> >> On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: >>> >>> I tried customizing the form. I have to set the id of the form element >>> to login. >>> To achieve the above I used the following statement in controller: >>> >>> login_form = auth.login() >>> >>> # Configure form properties >>> login_form.attributes['_id']='login' >>> >>> But it's not working. The generated form does not contain any id >>> attribute. >>> Is there another way to do it ? >>> >>> Thanks, >>> Sushant >>> >>> On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: Thanks for an explanatory answer. I will try this out. On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: > > def index(): >> >> login_form = auth.login() >> if login_form.process(session=None,formname='login').accepted: >> pass >> elif login_form.errors: >> response.write(request.vars) >> return dict() >> >> to display the form I have used the SQLForm in HTML technique as >> mentioned in the web2py book >> >> Whenever user enters the correct email and password. auth_event >> registers a login event with the description *User 1 Logged In*. >> The next property redirects the URL to /user/profile but auth.user >> object is *None.* >> > > auth.login() handles it's own form processing, and it uses the session > when calling form.accepts (which adds a hidden _formkey field to the > form, > which must be present upon form submission). In your code, you do not > return the form object to the view, which means your view cannot include > the hidden _formkey field, which is therefore not submitted with the > form. > So, when the form is submitted, the form.accepts in auth.login() fails, > which means the user object is never stored in session.auth.user -- > hence, > auth.user is None. The reason the login submission is successful is that > your index() function then does its own processing of the login form, > which > is successful -- but your explicit call to login_form.process() does not > do > anything to set auth.user, so it is never set. > > In short, you should not be doing your own processing of the login > form -- let auth.login() handle that. And if you want to customize the > form > display in the view, you still have to return the form to the view so you > can include the hidden _formkey and _formname fields in the form (you can > use form.custom.end to do that). > > Anthony > >> On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: >>> >>> I tried customizing the form. I have to set the id of the form element >>> to login. >>> To achieve the above I used the following statement in controller: >>> >>> login_form = auth.login() >>> >>> # Configure form properties >>> login_form.attributes['_id']='login' >>> >>> But it's not working. The generated form does not contain any id >>> attribute. >>> Is there another way to do it ? >>> >>> Thanks, >>> Sushant >>> >>> On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: Thanks for an explanatory answer. I will try this out. On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: > > def index(): >> >> login_form = auth.login() >> if login_form.process(session=None,formname='login').accepted: >> pass >> elif login_form.errors: >> response.write(request.vars) >> return dict() >> >> to displa
[web2py] Re: Auth.user is still NULL after a successful login
Hi, I tried both but none seems to be working. Here's my view code: {{=login_form.custom.begin}} {{=login_form.custom.widget.email}} {{=login_form.custom.widget.password}} Forgot Password? {{=login_form.custom.submit}} {{=login_form.custom.end}} Please suggest. On Monday, March 12, 2012 11:32:04 PM UTC+5:30, Anthony wrote: > > That should work. Can you show the view code? Also, note you can just do: > > login_form['_id'] = 'login' > > Anthony > > On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: >> >> I tried customizing the form. I have to set the id of the form element to >> login. >> To achieve the above I used the following statement in controller: >> >> login_form = auth.login() >> >> # Configure form properties >> login_form.attributes['_id']='login' >> >> But it's not working. The generated form does not contain any id >> attribute. >> Is there another way to do it ? >> >> Thanks, >> Sushant >> >> On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: >>> >>> Thanks for an explanatory answer. >>> I will try this out. >>> >>> On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: def index(): > > login_form = auth.login() > if login_form.process(session=None,formname='login').accepted: > pass > elif login_form.errors: > response.write(request.vars) > return dict() > > to display the form I have used the SQLForm in HTML technique as > mentioned in the web2py book > > Whenever user enters the correct email and password. auth_event > registers a login event with the description *User 1 Logged In*. > The next property redirects the URL to /user/profile but auth.user > object is *None.* > auth.login() handles it's own form processing, and it uses the session when calling form.accepts (which adds a hidden _formkey field to the form, which must be present upon form submission). In your code, you do not return the form object to the view, which means your view cannot include the hidden _formkey field, which is therefore not submitted with the form. So, when the form is submitted, the form.accepts in auth.login() fails, which means the user object is never stored in session.auth.user -- hence, auth.user is None. The reason the login submission is successful is that your index() function then does its own processing of the login form, which is successful -- but your explicit call to login_form.process() does not do anything to set auth.user, so it is never set. In short, you should not be doing your own processing of the login form -- let auth.login() handle that. And if you want to customize the form display in the view, you still have to return the form to the view so you can include the hidden _formkey and _formname fields in the form (you can use form.custom.end to do that). Anthony >>> > On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: >> >> I tried customizing the form. I have to set the id of the form element to >> login. >> To achieve the above I used the following statement in controller: >> >> login_form = auth.login() >> >> # Configure form properties >> login_form.attributes['_id']='login' >> >> But it's not working. The generated form does not contain any id >> attribute. >> Is there another way to do it ? >> >> Thanks, >> Sushant >> >> On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: >>> >>> Thanks for an explanatory answer. >>> I will try this out. >>> >>> On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: def index(): > > login_form = auth.login() > if login_form.process(session=None,formname='login').accepted: > pass > elif login_form.errors: > response.write(request.vars) > return dict() > > to display the form I have used the SQLForm in HTML technique as > mentioned in the web2py book > > Whenever user enters the correct email and password. auth_event > registers a login event with the description *User 1 Logged In*. > The next property redirects the URL to /user/profile but auth.user > object is *None.* > auth.login() handles it's own form processing, and it uses the session when calling form.accepts (which adds a hidden _formkey field to the form, which must be present upon form submission). In your code, you do not return the form object to the view, which means your view cannot include the hidden _formkey field, which is ther
[web2py] Re: Auth.user is still NULL after a successful login
That should work. Can you show the view code? Also, note you can just do: login_form['_id'] = 'login' Anthony On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: > > I tried customizing the form. I have to set the id of the form element to > login. > To achieve the above I used the following statement in controller: > > login_form = auth.login() > > # Configure form properties > login_form.attributes['_id']='login' > > But it's not working. The generated form does not contain any id attribute. > Is there another way to do it ? > > Thanks, > Sushant > > On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: >> >> Thanks for an explanatory answer. >> I will try this out. >> >> On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: >>> >>> def index(): login_form = auth.login() if login_form.process(session=None,formname='login').accepted: pass elif login_form.errors: response.write(request.vars) return dict() to display the form I have used the SQLForm in HTML technique as mentioned in the web2py book Whenever user enters the correct email and password. auth_event registers a login event with the description *User 1 Logged In*. The next property redirects the URL to /user/profile but auth.user object is *None.* >>> >>> auth.login() handles it's own form processing, and it uses the session >>> when calling form.accepts (which adds a hidden _formkey field to the form, >>> which must be present upon form submission). In your code, you do not >>> return the form object to the view, which means your view cannot include >>> the hidden _formkey field, which is therefore not submitted with the form. >>> So, when the form is submitted, the form.accepts in auth.login() fails, >>> which means the user object is never stored in session.auth.user -- hence, >>> auth.user is None. The reason the login submission is successful is that >>> your index() function then does its own processing of the login form, which >>> is successful -- but your explicit call to login_form.process() does not do >>> anything to set auth.user, so it is never set. >>> >>> In short, you should not be doing your own processing of the login form >>> -- let auth.login() handle that. And if you want to customize the form >>> display in the view, you still have to return the form to the view so you >>> can include the hidden _formkey and _formname fields in the form (you can >>> use form.custom.end to do that). >>> >>> Anthony >>> >> On Monday, March 12, 2012 1:19:45 PM UTC-4, Sushant Taneja wrote: > > I tried customizing the form. I have to set the id of the form element to > login. > To achieve the above I used the following statement in controller: > > login_form = auth.login() > > # Configure form properties > login_form.attributes['_id']='login' > > But it's not working. The generated form does not contain any id attribute. > Is there another way to do it ? > > Thanks, > Sushant > > On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: >> >> Thanks for an explanatory answer. >> I will try this out. >> >> On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: >>> >>> def index(): login_form = auth.login() if login_form.process(session=None,formname='login').accepted: pass elif login_form.errors: response.write(request.vars) return dict() to display the form I have used the SQLForm in HTML technique as mentioned in the web2py book Whenever user enters the correct email and password. auth_event registers a login event with the description *User 1 Logged In*. The next property redirects the URL to /user/profile but auth.user object is *None.* >>> >>> auth.login() handles it's own form processing, and it uses the session >>> when calling form.accepts (which adds a hidden _formkey field to the form, >>> which must be present upon form submission). In your code, you do not >>> return the form object to the view, which means your view cannot include >>> the hidden _formkey field, which is therefore not submitted with the form. >>> So, when the form is submitted, the form.accepts in auth.login() fails, >>> which means the user object is never stored in session.auth.user -- hence, >>> auth.user is None. The reason the login submission is successful is that >>> your index() function then does its own processing of the login form, which >>> is successful -- but your explicit call to login_form.process() does not do >>> anything to set auth.user, so it is never set. >>> >>> In short, you should not be doing your own processing of the login form >>> -- let auth.login() handle that. And if you want to customize the form >>> display in the view, you still have to return the form to the view so you >>> can include the hidden _formkey and _formname fie
[web2py] Re: Auth.user is still NULL after a successful login
I tried customizing the form. I have to set the id of the form element to login. To achieve the above I used the following statement in controller: login_form = auth.login() # Configure form properties login_form.attributes['_id']='login' But it's not working. The generated form does not contain any id attribute. Is there another way to do it ? Thanks, Sushant On Monday, March 12, 2012 8:01:33 PM UTC+5:30, Sushant Taneja wrote: > > Thanks for an explanatory answer. > I will try this out. > > On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: >> >> def index(): >>> >>> login_form = auth.login() >>> if login_form.process(session=None,formname='login').accepted: >>> pass >>> elif login_form.errors: >>> response.write(request.vars) >>> return dict() >>> >>> to display the form I have used the SQLForm in HTML technique as >>> mentioned in the web2py book >>> >>> Whenever user enters the correct email and password. auth_event >>> registers a login event with the description *User 1 Logged In*. >>> The next property redirects the URL to /user/profile but auth.user >>> object is *None.* >>> >> >> auth.login() handles it's own form processing, and it uses the session >> when calling form.accepts (which adds a hidden _formkey field to the form, >> which must be present upon form submission). In your code, you do not >> return the form object to the view, which means your view cannot include >> the hidden _formkey field, which is therefore not submitted with the form. >> So, when the form is submitted, the form.accepts in auth.login() fails, >> which means the user object is never stored in session.auth.user -- hence, >> auth.user is None. The reason the login submission is successful is that >> your index() function then does its own processing of the login form, which >> is successful -- but your explicit call to login_form.process() does not do >> anything to set auth.user, so it is never set. >> >> In short, you should not be doing your own processing of the login form >> -- let auth.login() handle that. And if you want to customize the form >> display in the view, you still have to return the form to the view so you >> can include the hidden _formkey and _formname fields in the form (you can >> use form.custom.end to do that). >> >> Anthony >> >
[web2py] Re: Auth.user is still NULL after a successful login
Thanks for an explanatory answer. I will try this out. On Monday, March 12, 2012 7:49:28 PM UTC+5:30, Anthony wrote: > > def index(): >> >> login_form = auth.login() >> if login_form.process(session=None,formname='login').accepted: >> pass >> elif login_form.errors: >> response.write(request.vars) >> return dict() >> >> to display the form I have used the SQLForm in HTML technique as >> mentioned in the web2py book >> >> Whenever user enters the correct email and password. auth_event registers >> a login event with the description *User 1 Logged In*. >> The next property redirects the URL to /user/profile but auth.user object >> is *None.* >> > > auth.login() handles it's own form processing, and it uses the session > when calling form.accepts (which adds a hidden _formkey field to the form, > which must be present upon form submission). In your code, you do not > return the form object to the view, which means your view cannot include > the hidden _formkey field, which is therefore not submitted with the form. > So, when the form is submitted, the form.accepts in auth.login() fails, > which means the user object is never stored in session.auth.user -- hence, > auth.user is None. The reason the login submission is successful is that > your index() function then does its own processing of the login form, which > is successful -- but your explicit call to login_form.process() does not do > anything to set auth.user, so it is never set. > > In short, you should not be doing your own processing of the login form -- > let auth.login() handle that. And if you want to customize the form display > in the view, you still have to return the form to the view so you can > include the hidden _formkey and _formname fields in the form (you can use > form.custom.end to do that). > > Anthony >
[web2py] Re: Auth.user is still NULL after a successful login
> > def index(): > > login_form = auth.login() > if login_form.process(session=None,formname='login').accepted: > pass > elif login_form.errors: > response.write(request.vars) > return dict() > > to display the form I have used the SQLForm in HTML technique as mentioned > in the web2py book > > Whenever user enters the correct email and password. auth_event registers > a login event with the description *User 1 Logged In*. > The next property redirects the URL to /user/profile but auth.user object > is *None.* > auth.login() handles it's own form processing, and it uses the session when calling form.accepts (which adds a hidden _formkey field to the form, which must be present upon form submission). In your code, you do not return the form object to the view, which means your view cannot include the hidden _formkey field, which is therefore not submitted with the form. So, when the form is submitted, the form.accepts in auth.login() fails, which means the user object is never stored in session.auth.user -- hence, auth.user is None. The reason the login submission is successful is that your index() function then does its own processing of the login form, which is successful -- but your explicit call to login_form.process() does not do anything to set auth.user, so it is never set. In short, you should not be doing your own processing of the login form -- let auth.login() handle that. And if you want to customize the form display in the view, you still have to return the form to the view so you can include the hidden _formkey and _formname fields in the form (you can use form.custom.end to do that). Anthony