如何使用 webapp2 添加 auth_id?

发布于 2024-12-23 07:22:55 字数 152 浏览 2 评论 0原文

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

谢谢

I use the auth module from webapp2 and I want to know how to add an auth_id like 'facebook:fbuserid12121212' and add that to the list of auth_id:s for a user. But I see no function from the API that allows me to do this. Could you please tell me how to do it?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

檐上三寸雪 2024-12-30 07:22:55

这是OP找到的答案。我将其复制到此处,以便这个问题不会得不到解答:

此问题已在google组,我正在寻找的函数是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'

This is the answer that the OP found. I'm copying it here so that this question will not be unanswered:

This was answered in the google group, the function I was looking for is user.auth_ids.append and the code I use now to make use of it is:

@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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文