本文整理汇总了Python中app.userprofile.User.login方法的典型用法代码示例。如果您正苦于以下问题:Python User.login方法的具体用法?Python User.login怎么用?Python User.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.userprofile.User
的用法示例。
在下文中一共展示了User.login方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_permission_required_one_of_has_permission
# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import login [as 别名]
def test_permission_required_one_of_has_permission(self):
"""
Test the `permission_required` decorator if the user has one of the requested permission, but not all.
Expected result: The decorated view function is returned.
"""
email = '[email protected]'
name = 'Jane Doe'
password = '123456'
user = User(email, name)
user.set_password(password)
user.role = Role('Administrator')
user.role.permissions = Permission.EditRole
db.session.add(user)
db.session.commit()
user.login(email, password)
self.assertTrue(user.role.has_permission(Permission.EditRole))
self.assertFalse(user.role.has_permission(Permission.EditUser))
view_function = permission_required_one_of(Permission.EditRole, Permission.EditUser)(self.view_function)
response = view_function()
self.assertEqual(self.view_function(), response)
示例2: test_permission_required_all_not_all_permissions
# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import login [as 别名]
def test_permission_required_all_not_all_permissions(self):
"""
Test the `permission_required_all` decorator if the user does not have all the requested permissions.
Expected result: The request is aborted with an error 403.
"""
email = '[email protected]'
name = 'Jane Doe'
password = '123456'
user = User(email, name)
user.set_password(password)
user.role = Role('Administrator')
user.role.permissions = Permission.EditRole
db.session.add(user)
db.session.commit()
user.login(email, password)
self.assertTrue(user.role.has_permission(Permission.EditRole))
self.assertFalse(user.role.has_permission(Permission.EditUser))
with self.assertRaises(Forbidden):
permission_required_all(Permission.EditRole, Permission.EditUser)(self.view_function)()
示例3: login
# 需要导入模块: from app.userprofile import User [as 别名]
# 或者: from app.userprofile.User import login [as 别名]
def login() -> str:
"""
Show a login form to the user. If they submitted the login form, try to log them in and redirect them to the
homepage.
:return: The HTML response.
"""
form = LoginForm()
if form.validate_on_submit():
# Try to login the user.
user = User.login(email=form.email.data, password=form.password.data, remember_me=form.remember_me.data)
if user:
# Login succeeded.
flash(_('Welcome, %(name)s!', name=user.name))
next_page = get_next_page()
return redirect(next_page)
# Login failed. Just show the login form again.
flash(_('Invalid email address or password.'), 'error')
return render_template('userprofile/login.html', title=_('Log In'), form=form)