| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

「Google App Engine webapp ユーザーサービス」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
1行目: 1行目:
 
==Google App Engine webapp ユーザーサービス==
 
==Google App Engine webapp ユーザーサービス==
[[Google App Engine]][[Python]]
+
[[Google App Engine]] | [[Python]] |
  
 
*http://code.google.com/intl/ja/appengine/docs/python/gettingstarted/usingusers.html
 
*http://code.google.com/intl/ja/appengine/docs/python/gettingstarted/usingusers.html

2020年2月15日 (土) 08:36時点における版

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

Google App Engine | Python |

実装

0602 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のログインページが表示されるはず。 0603 userservice02.jpg ユーザー固有のメッセージ表示 0604 userservice03.jpg