2011-12-30 22 views
5

私はwebapp2のauthモジュールを使用しています。「facebook:fbuserid12121212」のようなauth_idを追加して、それをユーザのauth_id:sのリストに追加する方法を知りたいと思います。しかし私はこれを行うことを可能にするAPIから何の機能も見ません。どうやったらそれを教えてください。webapp2でauth_idを追加するにはどうすればよいですか?

ありがとうございます。

+1

あなたのアップデート/アンサーを実際のアンサーに移動することは価値があるかもしれません(アンサーに質問が表示されないように)。これを整理していただきありがとうございます:) –

+1

@jgeewax私は答えのセクションへの答えを移動しました。 – allyourcode

答えて

2

これは、OPが見つけた回答です。この質問は未回答ではありませんように、私はここでそれをコピーしています:、私が探していた機能がuser.auth_ids.appendは

This was answered in the google groupであり、私はそれを利用するようになりました使用コードは次のとおりです。

@user_required 
def post(self, **kwargs): 
    email = self.request.POST.get('email') 
    auser = self.auth.get_user_by_session() 
    userid = auser['user_id'] 
    user = auth_models.User.get_by_id(auser['user_id']) 
    existing_user = auth_models.User.get_by_auth_id(email) 

    if existing_user is not None: 
     # You need to handle duplicates. 
     # Maybe you merge the users? Maybe you return an error? 
     pass 

    # Test the uniqueness of the auth_id. We must do this to 
    # be consistent with User.user_create() 
    unique = '{0}.auth_id:{1}'.format(auth_models.__class__.__name__, email) 

    if auth_models.User.unique_model.create(unique): 
     # Append email to the auth_ids list 
     user.auth_ids.append(email) 
     user.put() 
     return "Email updated" 
    else: 
     return 'some error' 
+0

ユーザーのauth_idを取得する方法はありますか? – deltanine

関連する問題