本文整理汇总了Python中app.userprofile.User.check_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.check_password方法的具体用法?Python User.check_password怎么用?Python User.check_password使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.userprofile.User
的用法示例。
在下文中一共展示了User.check_password方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reset_password_post_failure_invalid_input
# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import check_password [as 别名]
def test_reset_password_post_failure_invalid_input(self):
"""
Test posting to the password reset form with an anonymous user, a valid token, and an invalid form.
Expected result: The password is not updated and the user is shown the reset password form.
"""
email = '[email protected]'
password = '123456'
name = 'John Doe'
user_id = 1
user = User(email, name)
user.set_password(password)
db.session.add(user)
db.session.commit()
self.assertEqual(user_id, user.id)
token_obj = ResetPasswordToken()
token_obj.user_id = user_id
token = token_obj.create()
new_password = 'abcdef'
response = self.client.post(f'/user/reset-password/{token}', follow_redirects=True, data=dict(
password=new_password,
password_confirmation=new_password + 'ghi'
))
data = response.get_data(as_text=True)
self.assertIn('Reset Your Password', data)
self.assertNotIn('The token is invalid.', data)
self.assertNotIn('Your password has successfully been changed.', data)
self.assertFalse(user.check_password(new_password))
self.assertTrue(user.check_password(password))
示例2: test_reset_password_post_failure_invalid_token
# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import check_password [as 别名]
def test_reset_password_post_failure_invalid_token(self):
"""
Test posting to the password reset form with an anonymous user, an invalid token, and a valid form.
Expected result: The password is not updated and the user is shown a 404 error page.
"""
email = '[email protected]'
password = '123456'
name = 'John Doe'
user_id = 1
user = User(email, name)
user.set_password(password)
db.session.add(user)
db.session.commit()
self.assertEqual(user_id, user.id)
new_password = 'abcdef'
response = self.client.post('/user/reset-password/just-some-token', follow_redirects=True, data=dict(
password=new_password,
password_confirmation=new_password
))
data = response.get_data(as_text=True)
self.assertEqual(404, response.status_code)
self.assertNotIn('Your password has successfully been changed.', data)
self.assertFalse(user.check_password(new_password))
self.assertTrue(user.check_password(password))
示例3: test_user_profile_post_name_and_password_and_email
# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import check_password [as 别名]
def test_user_profile_post_name_and_password_and_email(self):
"""
Test posting to the user profile page with the name, the password, and the email changed.
Expected result: The form is shown with the new data. The user's name and password are changed, the email
is not, but a mail has been sent to the new address.
"""
email = '[email protected]'
name = 'John Doe'
password = '123456'
user = User(email, name)
user.set_password(password + '!')
with mail.record_messages() as outgoing:
user.set_password(password)
self.assertEqual(1, len(outgoing))
self.assertIn('Your Password Has Been Changed', outgoing[0].subject)
db.session.add(user)
db.session.commit()
user_id = user.id
self.client.post('/user/login', follow_redirects=True, data=dict(
email=email,
password=password
))
new_name = 'Jane Doe'
new_password = '654321'
new_email = '[email protected]'
with mail.record_messages() as outgoing:
response = self.client.post('/user/profile', follow_redirects=True, data=dict(
name=new_name,
email=new_email,
password=new_password,
password_confirmation=new_password
))
data = response.get_data(as_text=True)
self.assertEqual(2, len(outgoing))
self.assertIn('Change Your Email Address', outgoing[1].subject)
self.assertEqual([new_email], outgoing[1].recipients)
self.assertIn('User Profile', data)
self.assertIn(f'value="{new_name}"', data)
self.assertIn(f'value="{email}"', data)
self.assertIn('Your changes have been saved.', data)
self.assertIn('An email has been sent to the new address', data)
user = User.load_from_id(user_id)
self.assertEqual(new_name, user.name)
self.assertEqual(email, user.get_email())
self.assertTrue(user.check_password(new_password))
示例4: test_user_profile_post_only_name
# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import check_password [as 别名]
def test_user_profile_post_only_name(self):
"""
Test posting to the user profile page with only the name changed.
Expected result: The form is shown with the new data. The user's name is changed, everything else is not.
"""
email = '[email protected]'
name = 'John Doe'
password = '123456'
user = User(email, name)
user.set_password(password)
db.session.add(user)
db.session.commit()
user_id = user.id
self.client.post('/user/login', follow_redirects=True, data=dict(
email=email,
password=password
))
new_name = 'Jane Doe'
with mail.record_messages() as outgoing:
response = self.client.post('/user/profile', follow_redirects=True, data=dict(
name=new_name,
email=email
))
data = response.get_data(as_text=True)
self.assertEqual(0, len(outgoing))
self.assertIn('User Profile', data)
self.assertIn(f'value="{new_name}"', data)
self.assertIn(f'value="{email}"', data)
self.assertIn('Your changes have been saved.', data)
self.assertNotIn('An email has been sent to the new address', data)
user = User.load_from_id(user_id)
self.assertEqual(new_name, user.name)
self.assertEqual(email, user.get_email())
self.assertTrue(user.check_password(password))
示例5: test_reset_password_post_logged_in
# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import check_password [as 别名]
def test_reset_password_post_logged_in(self):
"""
Test posting to the password reset form with a user who is logged in, and a valid token.
Expected result: The user is redirected to the home page without changing the password.
"""
email = '[email protected]'
password = '123456'
name = 'John Doe'
user_id = 1
user = User(email, name)
user.set_password(password)
db.session.add(user)
db.session.commit()
self.assertEqual(user_id, user.id)
self.client.post('/user/login', follow_redirects=True, data=dict(
email=email,
password=password
))
token_obj = ResetPasswordToken()
token_obj.user_id = user_id
token = token_obj.create()
new_password = 'abcdef'
response = self.client.post(f'/user/reset-password/{token}', follow_redirects=True, data=dict(
password=new_password,
password_confirmation=new_password
))
data = response.get_data(as_text=True)
self.assertIn('Dashboard', data)
self.assertNotIn('The token is invalid.', data)
self.assertNotIn('Reset Your Password', data)
self.assertNotIn('Your password has successfully been changed.', data)
self.assertTrue(user.check_password(password))