(Note: I am using the same code file structure as in my previous posts).
The code file looks like this:
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, ' + user.nickname())
else:
self.redirect(users.create_login_url(self.request.uri))
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
user = users.get_current_user()
This line returns a 'User' object if you are already signed into the application. Our program in this case simply prints a customized greeting. Otherwise, it redirects to the login page
self.redirect(users.create_login_url(self.request.uri))
We pass 'self.request.uri' so that the system know where to redirect AFTER successful login.
For more info on the Users API, see this link
http://code.google.com/appengine/docs/python/users/