Useful Links‎ > ‎

Enforcing User Login

Enforcing User Login

Once you have read these instructions, your first goal should be to enforce user log in and create a welcome message using Google's "Users" library. You will need to import this library:

from google.appengine.api import users

and check if the user has logged in inside get(self):

user = users.get_current_user()
if user:
     welcome = "<p>Welcome, {0} (<a href=\"{1}\">sign out</a>)</p> ".format(user.nickname(), users.create_logout_url('/'))
     [... display the welcome message using self.response.write(...)]
else:
     self.redirect(users.create_login_url(self.request.uri))

Try this out. When you load the application locally (mine is at http://localhost:9080, note the change in URL), you should see: 

Which changes to the following once you log in:

Comments