本文整理汇总了Python中django.contrib.auth.tokens.PasswordResetTokenGenerator.secret方法的典型用法代码示例。如果您正苦于以下问题:Python PasswordResetTokenGenerator.secret方法的具体用法?Python PasswordResetTokenGenerator.secret怎么用?Python PasswordResetTokenGenerator.secret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.tokens.PasswordResetTokenGenerator
的用法示例。
在下文中一共展示了PasswordResetTokenGenerator.secret方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_token_with_different_secret
# 需要导入模块: from django.contrib.auth.tokens import PasswordResetTokenGenerator [as 别名]
# 或者: from django.contrib.auth.tokens.PasswordResetTokenGenerator import secret [as 别名]
def test_token_with_different_secret(self):
"""
A valid token can be created with a secret other than SECRET_KEY by
using the PasswordResetTokenGenerator.secret attribute.
"""
user = User.objects.create_user('tokentestuser', '[email protected]', 'testpw')
new_secret = 'abcdefghijkl'
# Create and check a token with a different secret.
p0 = PasswordResetTokenGenerator()
p0.secret = new_secret
tk0 = p0.make_token(user)
self.assertTrue(p0.check_token(user, tk0))
# Create and check a token with the default secret.
p1 = PasswordResetTokenGenerator()
self.assertEqual(p1.secret, settings.SECRET_KEY)
self.assertNotEqual(p1.secret, new_secret)
tk1 = p1.make_token(user)
# Tokens created with a different secret don't validate.
self.assertFalse(p0.check_token(user, tk1))
self.assertFalse(p1.check_token(user, tk0))