Hi Massimo,
Your suggestion is very neat and beyond my limited web2py knowledge:
--------------------------------------------------------------------------------
Mind that you do not need anything like this if your purpose is login.
In that case web2py already provides method for login and the user
info is simply in
{{=auth.user.first_name}} {{=auth.user.last_name}}
------------------------------------------------------------------------------
I tried the above code in the View <p> Hi, {{=auth.user.first_name}}</
p> unfortunately got an error;
AttributeError: 'NoneType' object has no attribute 'first_name'
-------------------------------------------------------------------------------
I searched and found this at Mark Mail:
auth.user.id  -- this is the global variable 'auth' which has a
variable named 'user' which in turn has a named  variable called
'id'.  This variable is valid only after a user is logged on and it
refers to the id of the current user.  If no one is logged in,
auth.user does not exist and has the value of 'None'.  But None has no
named variable 'id' so you get an error if you try to use it.
------------------------------------------------------------------------------
So, definitely with the following Controller code i was not able to
logged in since my View encountered an "Attribute error: Nonetype
object has no attribute 'first_name' " and failed to display
{{=auth.user.first_name}}? The following is the actual code:
Controller:
def user:
    if request.args(0)=='login':
        form = SQLFORM.factory(
        Field('emailad', 'emailad',requires=[IS_LENGTH
(maxsize=30,error_message='Maximum length 30 chars..'),IS_EMAIL(),
IS_IN_DB(db,'auth_user.email',error_message='Email address does not
exist.')], required=True, label='Email Address'),
        Field('password', 'password', requires=[IS_IN_DB
(db,'auth_user.password',error_message='Password is not the
same.')],label='Password'))
        form[0][-1][1].append(INPUT
(_type='button',_value='Cancel',_onclick="window.location='%s';"%URL
(r=request,f='index')))

        if form.accepts(request.vars, session):
            em=request.vars.emailad
            session.flash = 'You are now logged in %s .' %
name
            redirect(URL(r=request,f='loggedin'))
            return dict(form=form)
View:
{{extend 'layout2.html'}}
<p>
<p><h3>Hi {{=auth.user.first_name}}</h3></p>
<p>
.................
Massimo, i tried to adopt your code but an error was encountered
during the run. What shall i do to adopt your code which is very
simple? Thank you again for your patience and very prompt responses.

On Oct 9, 8:59 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> Something like this?
>
> def page1():
>     form=SQLFORM.factory(Field('email',requires=IS_IN_DB
> (db,'auth_user.email')))
>     if form.accepts(request.vars, session):
>           redirect(URL(r=request,f='page2',dict(em=form.vars.email))
>     return dict(form=form)
>
> {{extend 'layout.html'}}{{=form}}
>
> def page2():
>     rows=db(db.auth_user.email==request.vars.em).select()
>     if not rows: redirect(URL(r=request,f='page1'))
>     return dict(name=rows.first().first_name)
>
> {{extend 'layout.html'}}Hello {{=name}}
>
> Mind that you do not need anything like this if your purpose is login.
> In that case web2py already provides method for login and the user
> info is simply in
> {{=auth.user.first_name}} {{=auth.user.last_name}}
>
> On Oct 9, 1:34 am, ed <edbi...@rocketmail.com> wrote:
>
> > Hi Massimo,
> > Okay, redirect returns page but without any variable. Any hint how to
> > render a page name "loggedin" that says; "Hi Ed, welcome!" after a
> > succesful login using the code i created?. Sorry, i'm a newbie with
> > very limited web2py knowledge and stucked on this.  Thank you in
> > advance Massimo.
>
> > On Oct 9, 11:58 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > mind that redirect is a function that raises an HTTP exception which
> > > causes the server to send and HTTP 303 response. redirect never
> > > returns and your view is never rendered.
>
> > > Massimo
>
> > > On Oct 8, 9:22 pm, ed <edbi...@rocketmail.com> wrote:
>
> > > > The display went well because i filled a session with a constant "Ed"
> > > > and not a result of a db().select(). So, the constant variable was
> > > > displayed without a hitch. When i used db().select() the display went
> > > > like:
> > > > [{'first_name': 'Ed'}]
> > > > The above display is the result of the following code:
> > > > Controller:
> > > > if form.accepts(request.vars, session):
> > > >     em=request.vars.emailad
> > > >     name1 = db(db.auth_user.email==em).select(db.auth_user.first_name)
> > > > [0]
> > > >     name=name1.first_name
> > > >     return dict(red=redirect(URL(r=request,f='loggedin')), name=name)
> > > > ..................
> > > > View:
> > > > {{extend 'layout2.html'}}
> > > > <p>
> > > > <p><h3>Hi {{=name}}</h3></p>
> > > > <p>
> > > > .................
> > > >  This was the result of the view, "Hi [{'first_name': 'Ed'}]". I've
> > > > googled and searched the manual and tried examples but to no avail.
> > > > Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to