开发者

action after sign in with google account

I'm new in google app engine, so my question may be kind of stupid or trivial, but anyway... For each user (for each google acc) I have an entity in my datastore. So when a new user logs 开发者_Python百科in I want to add him to database. I use:

- url: /.*
  login: required

To make sure user is logged in with his google acc. The problem is when someone signs in from a subpage (blabla.appspot.com/something) then after log in he will be redirected to blabla.appspot.com/something and I have to verify in Request handler for "something" if the current user is already stored in database. How to do it without adding the same code to each request handler? Maybe it's possible to redirect to the main page after log in or something similar?


Here's a simple approach: If you create a subclass of webapp.RequestHandler that your handlers will then subclass, you can provide it with a convenience method for getting or creating a UserInfo object given users.get_current_user().user_id() (or .user_email(), if that's what you prefer to use as a key). Your handlers then call the convenience method in their get() and post() methods.

class MyRequestHandler(webapp.RequestHandler):
  def setup_user_info(self):
    # left as an exercise
    self.user_info = user_info

and then

class MyHandler(MyRequestHandler):
  def get(self):
    self.setup_user_info()
    ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜