トップ 一覧 ping 検索 ヘルプ RSS ログイン

Google App Engine webapp ユーザーサービスの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!!Google App Engine webapp ユーザーサービス
[Google App Engine][Python]

http://code.google.com/intl/ja/appengine/docs/gettingstarted/usingusers.html
*http://code.google.com/intl/ja/appengine/docs/python/gettingstarted/usingusers.html

::実装
{{ref_image userservice01.jpg}}
 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のログインページが表示されるはず。
{{ref_image userservice02.jpg}}
ユーザー固有のメッセージ表示
{{ref_image userservice03.jpg}}