I apologize it has taken me so long to get back to this. I have had
other more high priority projects the last few weeks.

While I didn't know about raise web.seeother(), my code replicates the
flow you described:

def POST(self):
i = web.input()
if users.loginUsers(i.email, i.password, db):
    cookie = web.cookies()
    name = cookie.first_name
    return render.index(1, name)

loginUsers() sets the cookie and returns a true value if the user's
login information is correct, therefore cookie.first_name will not
even be called upon unless the cookie was successfully set. . When
logging in, however, "<type 'exceptions.AttributeError'> at /
'first_name'" is returned the first time. However, I simply reload the
page, it displays correctly.

For completeness, the loginUser function:
def loginUser (username, password, db):
   query = "database query goes here; not replicating in full..."
   result = db.query(query)
   if result:
          for row in result:  #will only be one row in the result
              user_id = row.user_id
              name = row.first_name
          from web import setcookie
          setcookie('user_id', user_id)
          setcookie('first_name', name)
          return True
   else:
        return False

So, the page will not load unless the cookie has already been set.
But again, it does set the cookie. It just almost as if "return True"
is being called "too fast"; like the browser is still storing the
cookie while the server is trying to call it? Because again, if I
reload, everything is fine.


On Oct 31, 2:05 am, Justin Davis <jedavi...@gmail.com> wrote:
> The typical flow that's used with login forms (and any form that
> ultimately changes client-side state via cookies) is this:
>
> - User performs an http GET on the page with the form -- let's say /
> login
> - User enters data, and submits form via the http POST method
> - webpy POST method checks user credentials:
>   - If user login fails, it displays the web page with appropriate
> error
>   - Otherwise, it sets acookieand redirects the user to some other
> page. This is typically done by calling "raise web.seeother('/
> postlogin')"
>
> Since a successful call results in a redirect, the next page will send
> back the sessioncookiecorrectly.
>
> Hope this helps,
> Justin
>
> On Oct 26, 10:23 am, Tom <tom.thorog...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Greetings; awhile back I was having issues with web.py not retrieving
> > cookies properly. That works now. However, if I try to set them and
> > retrieve them within the same request, the retrieval fails, but
> > reloading brings up the information just fine.
>
> > For instance:
>
> > Index, with POST submission -> Web.py verifies form and logs user in,
> > setting a sessioncookie->
> > web.py renders index again, this time passing thecookieinformation
> > (as the $def with parameter).
>
> > Doing this will set thecookie, but raises an AttributeError when
> > retreiving it to pass to the page. However, if I reload the page, it
> > pulls it up just fine. Any workaround for this?
>
> > Thanks,
>
> > Tom

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to webpy@googlegroups.com.
To unsubscribe from this group, send email to 
webpy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to