トップ 差分 一覧 ping ソース 検索 ヘルプ PDF RSS ログイン

Google App Engine webapp ユーザーサービス



目次



記事一覧

キーワード

Google App Engine webapp ユーザーサービス

[Google App Engine][Python]


実装
import wsgiref.handlers

from google.appengine.api import users
from google.appengine.ext import webapp

class MainPage(webapp.RequestHandler):
    def get(self):
        # ユーザーがアプリケーションにログインしている場合、
        # ユーザーの User オブジェクトを返す
        user = users.get_current_user()
        if user:
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('Hello,' + user.nickname())
        else:
            # ユーザーがログインしていない場合、ユーザーのブラウザを
            # Google アカウントのログイン ページにリダイレクトするように指示
            # リダイレクトには、このページへの URL (self.request.uri) が
            # 含まれているため、ユーザーは Google アカウント ログイン
            # システムにより、ログインまたは新規アカウントの作成後、このページへ戻される
            self.redirect(users.create_login_url(self.request.uri))

def main():
    application = webapp.WSGIApplication(
                                         [('/', MainPage)],
                                         debug=True)
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
    main()

実行

ダミーログインページが表示された(ローカルテスト環境のため)
リリース後は、Googleのログインページが表示されるはず。

ユーザー固有のメッセージ表示



YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto

Copyright© 矢木 浩人 All Rights Reserved.