如何在webapp2中添加auth_id?
我在用webapp2的认证模块,想知道怎么添加一个像'facebook:fbuserid12121212'这样的认证ID,并把它加到用户的认证ID列表里。但是我在API里找不到可以做到这一点的函数。你能告诉我该怎么做吗?
谢谢
1 个回答
2
这是提问者找到的答案。我把它复制过来,以便这个问题不会没有答案:
这个问题在谷歌小组里已经有人回答过了,我想要的函数是 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'