本文整理汇总了Python中auth.models.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类auth.models.User
的用法示例。
在下文中一共展示了User.set_password方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_change_password_form
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def test_change_password_form(self):
# Set up a test user
user = User(email='[email protected]')
user.set_password('password')
# The form should fail to validate if the current password is wrong.
form = auth_forms.ChangePasswordForm({
'current_password': 'incorrect password',
'new_password': 'foo',
'confirm_new_password': 'foo',
})
form.set_user(user)
self.assertFalse(form.is_valid())
# The form should fail to validate if the two versions of the
# new password do not agree.
form = auth_forms.ChangePasswordForm({
'current_password': 'password',
'new_password': 'foo',
'confirm_new_password': 'bar',
})
form.set_user(user)
self.assertFalse(form.is_valid())
# This should work.
form = auth_forms.ChangePasswordForm({
'current_password': 'password',
'new_password': 'foo',
'confirm_new_password': 'foo',
})
form.set_user(user)
self.assertTrue(form.is_valid())
示例2: test_login_form
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def test_login_form(self):
# Set up a test user.
email = '[email protected]'
user = User(email=email)
user.set_password('password')
user.save()
# Missing required data
form = auth_forms.LoginForm({'redirect': '/'})
self.assertFalse(form.is_valid())
form = auth_forms.LoginForm({'redirect': '/', 'email': email})
self.assertFalse(form.is_valid())
# Form should fail to validate if password is incorrect.
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'incorrect password'})
self.assertFalse(form.is_valid())
# This should succeed.
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'password'})
self.assertTrue(form.is_valid())
# The form should reject inactive users.
user.is_active = False
user.save()
form = auth_forms.LoginForm({'redirect': '/',
'email': email,
'password': 'password'})
self.assertFalse(form.is_valid())
# The form should reject unknown users.
form = auth_forms.LoginForm({'redirect': '/',
'email': '[email protected]',
'password': 'password'})
self.assertFalse(form.is_valid())
示例3: test_forgot_password_form_case_insensitive_email
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def test_forgot_password_form_case_insensitive_email(self):
# Set up a test user
user = User(email='[email protected]')
user.set_password('password')
user.save()
form = auth_forms.ForgotPasswordForm({'email': '[email protected]'})
self.assertTrue(form.is_valid())
示例4: test_login_with_case_insensitive_email
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def test_login_with_case_insensitive_email(self):
# Set up a test user.
email = '[email protected]'
user = User(email=email)
user.set_password('password')
user.save()
# This should succeed.
form = auth_forms.LoginForm({'redirect': '/',
'email': '[email protected]',
'password': 'password'})
self.assertTrue(form.is_valid())
示例5: test_forgot_password_form
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def test_forgot_password_form(self):
# Set up a test user
user = User(email='[email protected]')
user.set_password('password')
user.save()
# The form will validate if given a known email address.
form = auth_forms.ForgotPasswordForm({'email': user.email})
self.assertTrue(form.is_valid())
# Check that the user gets attached to the form's user
# property.
self.assertEqual(user.email, form.user.email)
# The form will not validate for an unknown email address.
form = auth_forms.ForgotPasswordForm({'email': '[email protected]'})
self.assertFalse(form.is_valid())
self.assertEqual(None, form.user)
示例6: bootstrap
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def bootstrap(request):
"""If the visitor is a chirpradio admin, create a user for them."""
if request.user is None:
g_user = google_users.get_current_user()
if g_user is None:
return http.HttpResponseRedirect(
google_users.create_login_url(request.path))
if not google_users.is_current_user_admin():
return http.HttpResponseForbidden('Not a chirpradio project admin')
user = User.get_by_email(g_user.email())
if user:
return http.HttpResponseForbidden(
'User %s already exists' % user.email)
user = User(email=g_user.email(), is_superuser=True)
user.set_password("test")
user.save()
return http.HttpResponseRedirect(auth.create_login_url('/'))
return http.HttpResponseForbidden("Already logged in")
示例7: CoreTest
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
class CoreTest(unittest.TestCase):
def setUp(self):
self.user = User(username="core_tester",
first_name="first",
last_name="last",
email="[email protected]")
self.user.set_password("test")
self.user.save()
def tearDown(self):
self.user.delete()
def test_email_backend(self):
#from django.contrib.auth import login
request = object()
request.POST = {'username': 'core_tester',
'password': 'test'}
from auth import login
login(request, self.user)
示例8: to_user
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def to_user(self):
data = self.cleaned_data.copy()
user_roles = []
for r in roles.ALL_ROLES:
key = "is_" + r
if key in data:
if data[key]:
user_roles.append(r)
del data[key]
data["roles"] = user_roles
if data["original_email"]:
# update the user (edit form)...
user = User.get_by_email(data["original_email"])
for key, val in data.items():
# update all attributes with form values except our
# placeholder field, original_email; also handle password as a special case
if key == "password":
if val:
# only change the password if it was filled in on the edit form:
user.set_password(val)
elif key != "original_email":
setattr(user, key, val)
user.save()
else:
# creating new user...
del data["original_email"]
initial_password = None
if data["password"]:
# this is uncommon
initial_password = data["password"]
del data["password"]
user = User(**data)
if initial_password:
user.set_password(initial_password)
user.save()
return user
示例9: test_user_password_checks
# 需要导入模块: from auth.models import User [as 别名]
# 或者: from auth.models.User import set_password [as 别名]
def test_user_password_checks(self):
user = User(email='[email protected]')
self.assertFalse(user.check_password('foo'))
user.set_password('foo')
self.assertTrue(user.check_password('foo'))
self.assertFalse(user.check_password('bar'))