• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tokens.get_token_for_user函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中taiga.auth.tokens.get_token_for_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_token_for_user函数的具体用法?Python get_token_for_user怎么用?Python get_token_for_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_token_for_user函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _execute_requests

    def _execute_requests(self, reqs):
        admin = User.objects.get(username="admin")
        user = User.objects.get(id=USER_ID)
        user.token = "password-token"
        user.email_token = "email-token"
        user.new_email = "[email protected]"
        user.save()

        user_token = get_token_for_user(user, "authentication")
        admin_token = get_token_for_user(admin, "authentication")
        os.environ["AUTH_TOKEN"] = user_token
        os.environ["ADMIN_AUTH_TOKEN"] = admin_token

        host = "http://localhost:8000"

        for (key, req) in reqs.items():
            print("Generate", key)

            cmd_path = os.path.join("output", key + "-cmd.adoc")
            os.makedirs("output", exist_ok=True)
            curl_cmd = self._build_curl_cmd(host, req)
            with open(cmd_path, "w") as fd:
                fd.write("[source,bash]\n")
                fd.write("----\n")
                fd.write(curl_cmd.replace("$$INCLUDE_FILE$$", "@"))
                fd.write("\n----\n")

            if req['method'] == "DELETE":
                continue

            curl_cmd = curl_cmd.replace("$$INCLUDE_FILE$$", "@{}/".format(os.path.dirname(__file__)))

            output_path = os.path.join("output", key + "-output.adoc")
            if "response" in req:
                response_data = req['response']
            else:
                result = subprocess.run(curl_cmd + " -f", shell=True, stdout=subprocess.PIPE)

                if result.returncode != 0:
                    result = subprocess.run(curl_cmd, shell=True, stdout=subprocess.PIPE)
                    print("ERROR on key: ", key)
                    print(result)

                if result.stdout == b'':
                    response_data = None
                else:
                    response_data = json.loads(result.stdout.decode('utf-8'))
                    if req.get('index', None) is not None:
                        response_data = response_data[req['index']]

            if not response_data:
                continue

            with open(output_path, "w") as fd:
                fd.write("[source,json]\n")
                fd.write("----\n")
                json.dump(response_data, fd, sort_keys=True, indent=4)
                fd.write("\n----\n")
开发者ID:taigaio,项目名称:taiga-doc,代码行数:58,代码来源:generate_api_examples.py


示例2: test_cancel_self_user_with_valid_token

def test_cancel_self_user_with_valid_token(client):
    user = f.UserFactory.create()
    url = reverse('users-cancel')
    cancel_token = get_token_for_user(user, "cancel_account")
    data = {"cancel_token": cancel_token}
    client.login(user)
    response = client.post(url, json.dumps(data), content_type="application/json")

    assert response.status_code == 204
    user = models.User.objects.get(pk=user.id)
    assert user.full_name == "Deleted user"
开发者ID:SKOx0,项目名称:taiga-back,代码行数:11,代码来源:test_users.py


示例3: test_response_200_in_public_registration

def test_response_200_in_public_registration(client, settings):
    settings.PUBLIC_REGISTER_ENABLED = True
    form = {
        "type": "public",
        "username": "mmcfly",
        "full_name": "martin seamus mcfly",
        "email": "[email protected]",
        "password": "password",
    }

    response = client.post(reverse("auth-register"), form)
    assert response.status_code == 201
    assert response.data["username"] == "mmcfly"
    assert response.data["email"] == "[email protected]"
    assert response.data["full_name"] == "martin seamus mcfly"
    assert len(mail.outbox) == 1
    assert mail.outbox[0].subject == "You've been Taigatized!"
    user = models.User.objects.get(username="mmcfly")
    cancel_token = get_token_for_user(user, "cancel_account")
    cancel_url = resolve_front_url("cancel-account", cancel_token)
    assert mail.outbox[0].body.index(cancel_url) > 0
开发者ID:BWStearns,项目名称:taiga-back,代码行数:21,代码来源:test_auth_api.py


示例4: save

 def save(self, *args, **kwargs):
     get_token_for_user(self, "cancel_account")
     super().save(*args, **kwargs)
开发者ID:BWStearns,项目名称:taiga-back,代码行数:3,代码来源:models.py


示例5: test_invalid_token_scope

def test_invalid_token_scope():
    user = f.UserFactory.create(email="[email protected]")
    token = get_token_for_user(user, "testing_scope")
    get_user_for_token(token, "testing_invalid_scope")
开发者ID:cubettech,项目名称:taiga-back,代码行数:4,代码来源:test_tokens.py


示例6: test_invalid_token_expiration

def test_invalid_token_expiration():
    user = f.UserFactory.create(email="[email protected]")
    token = get_token_for_user(user, "testing_scope")
    get_user_for_token(token, "testing_scope", max_age=1)
开发者ID:cubettech,项目名称:taiga-back,代码行数:4,代码来源:test_tokens.py


示例7: test_valid_token

def test_valid_token():
    user = f.UserFactory.create(email="[email protected]")
    token = get_token_for_user(user, "testing_scope")
    user_from_token = get_user_for_token(token, "testing_scope")
    assert user.id == user_from_token.id
开发者ID:cubettech,项目名称:taiga-back,代码行数:5,代码来源:test_tokens.py



注:本文中的taiga.auth.tokens.get_token_for_user函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.get_object_or_404函数代码示例发布时间:2022-05-27
下一篇:
Python tagutils.component_context函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap