本文整理汇总了Python中app.user.models.User.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python User.set_password方法的具体用法?Python User.set_password怎么用?Python User.set_password使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.user.models.User
的用法示例。
在下文中一共展示了User.set_password方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_verify_password
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import set_password [as 别名]
def test_verify_password(self):
pwd1 = "password1"
pwd2 = "password2"
user = User(email="[email protected]")
user.set_password(pwd1)
self.assertTrue(user.verify_password(pwd1))
self.assertFalse(user.verify_password(pwd2))
示例2: user_register
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import set_password [as 别名]
def user_register():
data = json.loads(request.data)
errors = validate(username = data['username'], email = data['email'], password = data['password'])
if len(errors) == 0:
user = User(data['username'], data['email'])
user.set_password(data['password'])
db.session.add(user)
try:
db.session.commit()
except Exception, e:
return jsonify(result = 'error', exists = True)
login.login_user(user)
return jsonify(result = 'success', user = user.json())
示例3: test_password_reset
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import set_password [as 别名]
def test_password_reset(self):
user = User(email='[email protected]')
user.set_password('_foobar_')
user.put()
rv = self.app.post('/password/reset', data={'email': '[email protected]'})
self.assertEqual(rv.status, '200 OK')
messages = self.mail_stub.get_sent_messages(to='[email protected]')
self.assertEqual(1, len(messages))
self.assertEqual('[email protected]', messages[0].to)
token = self.get_token_from_message(str(messages[0].body))
rv = self.app.post(
'/password/reset/confirm',
data={'password': '_foobar_new_', 'reset_token': token}
)
self.assertEqual(rv.status, '200 OK')
self.assertFalse(user.verify_password('_foobar_'))
self.assertTrue(user.verify_password('_foobar_new_'))
示例4: test_set_password
# 需要导入模块: from app.user.models import User [as 别名]
# 或者: from app.user.models.User import set_password [as 别名]
def test_set_password(self):
pwd = "password"
user = User(email="[email protected]")
user.set_password(pwd)
self.assertNotEqual(user.password, None)
self.assertNotEqual(user.password, pwd)