thirdparty/google_appengine/google/appengine/ext/webapp/util.py
changeset 1278 a7766286a7be
parent 686 df109be0567c
child 3031 7678f72140e6
equal deleted inserted replaced
1277:5c931bd3dc1e 1278:a7766286a7be
    36 
    36 
    37   To use it, decorate your get() method like this:
    37   To use it, decorate your get() method like this:
    38 
    38 
    39     @login_required
    39     @login_required
    40     def get(self):
    40     def get(self):
    41       user = users.GetCurrentUser(self)
    41       user = users.get_current_user(self)
    42       self.response.out.write('Hello, ' + user.nickname())
    42       self.response.out.write('Hello, ' + user.nickname())
    43 
    43 
    44   We will redirect to a login page if the user is not logged in. We always
    44   We will redirect to a login page if the user is not logged in. We always
    45   redirect to the request URI, and Google Accounts only redirects back as a GET
    45   redirect to the request URI, and Google Accounts only redirects back as a GET
    46   request, so this should not be used for POSTs.
    46   request, so this should not be used for POSTs.
    47   """
    47   """
    48   def check_login(self, *args):
    48   def check_login(self, *args):
    49     if self.request.method != 'GET':
    49     if self.request.method != 'GET':
    50       raise webapp.Error('The check_login decorator can only be used for GET '
    50       raise webapp.Error('The check_login decorator can only be used for GET '
    51                          'requests')
    51                          'requests')
    52     user = users.GetCurrentUser()
    52     user = users.get_current_user()
    53     if not user:
    53     if not user:
    54       self.redirect(users.CreateLoginURL(self.request.uri))
    54       self.redirect(users.create_login_url(self.request.uri))
    55       return
    55       return
    56     else:
    56     else:
    57       handler_method(self, *args)
    57       handler_method(self, *args)
    58   return check_login
    58   return check_login
    59 
    59