如何使用webapp2添加auth_id?

2024-09-30 03:25:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用webapp2中的auth模块,我想知道如何添加auth_id,如'facebook:fbuserid12121212'并将其添加到用户的auth_id:s列表中。但是我看不到API中允许我这样做的函数。你能告诉我怎么做吗?在

谢谢


Tags: 模块函数用户authapiid列表facebook
1条回答
网友
1楼 · 发布于 2024-09-30 03:25:55

这就是手术室找到的答案。我把它复制到这里,这样就不会有人回答这个问题了:

This was answered in the google group,我要找的函数是用户身份证.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'

相关问题 更多 >

    热门问题