5

webapp2のauthモジュールを使用していますが、「facebook:fbuserid12121212」のようなauth_idを追加して、ユーザーのauth_id:sのリストに追加する方法を知りたいです。しかし、これを可能にするAPIの関数は見当たりません。やり方を教えてください。

ありがとう

4

1 に答える 1

2

これがOPが見つけた答えです。この質問が未回答にならないように、ここにコピーします。

これは google groupで回答されました。私が探していた関数は user.auth_ids.append で、それを利用するために現在使用しているコードは次のとおりです。

@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'
于 2012-07-08T19:49:54.140 に答える