Cloud Computing Search Engine

Loading

Using the Users Service [GAE]

The SDK provides several Add-On API libraries that interact with Google's infrastructure to provide several kinds of services. One of these is the Users service that we will concentrate on today. It allows users to authenticate to the system using their Google Service IDs (Gmail, GTalk etc). If the Users API is used on the local development server, the system uses a dummy login page, once deployed, the system uses the standard Google login page.
(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/
 

blogger templates 3 columns | Make Money Online