本文整理汇总了Python中flask_login.current_user.is_active方法的典型用法代码示例。如果您正苦于以下问题:Python current_user.is_active方法的具体用法?Python current_user.is_active怎么用?Python current_user.is_active使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_login.current_user
的用法示例。
在下文中一共展示了current_user.is_active方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_registration
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def test_user_registration(self):
# Ensure registration behaves correctlys.
with self.client:
response = self.client.post(
"/register",
data=dict(
email="test@tester.com",
password="testing",
confirm="testing",
),
follow_redirects=True,
)
self.assertIn(b"Welcome", response.data)
self.assertTrue(current_user.email == "test@tester.com")
self.assertTrue(current_user.is_active())
self.assertEqual(response.status_code, 200)
示例2: test_flask_login_user_login
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def test_flask_login_user_login(app):
# LoginManager could be set up in app fixture in conftest.py instead
login_manager = LoginManager()
login_manager.init_app(app)
# TODO: once event is marked, user id exists in MonthEvents and test will
# continue to pass, regardless of continued success; set to current
# microsecond to temporarily circumvent, but there should be a better
# way to fix user_id assignment (or tear down redis or something)
user_id = datetime.now().microsecond
with app.test_request_context():
# set up and log in user
user = User()
user.id = user_id
login_user(user)
# test that user was logged in
assert current_user.is_active
assert current_user.is_authenticated
assert current_user == user
# test that user id was marked with 'user:logged_in' event
assert user_id in MonthEvents('user:logged_in', now.year, now.month)
示例3: check
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def check(self):
# Do not override DENY_ABORT_HTTP_CODE because inherited classes will
# better use HTTP 403/Forbidden code on denial.
self.DENY_ABORT_HTTP_CODE = HTTPStatus.UNAUTHORIZED
# NOTE: `is_active` implies `is_authenticated`.
return current_user.is_active
示例4: logged_in
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def logged_in():
return current_user.is_authenticated and current_user.is_active()
示例5: frontend_login_required
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def frontend_login_required():
if not current_user.is_active and (request.endpoint and
request.endpoint != 'frontend.static'):
return login_manager.unauthorized()
示例6: api_login_required
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def api_login_required():
if not current_user.is_active and not request.method == "OPTIONS":
return dumps({"error": "X-Api-Key header missing or invalid"}), 401
示例7: new_user
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def new_user():
username = request.form.get("username")
password = request.form.get("password")
admin = request.form.get("admin") is not None
if current_user.has_role('admin') and current_user.is_active:
create_user(username, password, admin=admin)
return redirect(request.referrer)
logout_user()
示例8: new_group
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def new_group():
groupname = request.form.get("groupname")
if current_user.has_role('admin') and current_user.is_active:
create_group(groupname)
return redirect(request.referrer)
示例9: test_correct_login
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def test_correct_login(self):
# Ensure login behaves correctly with correct credentials.
with self.client:
response = self.client.post(
'/login',
data=dict(email="ad@min.com", password="admin_user"),
follow_redirects=True
)
self.assertIn(b'Welcome', response.data)
self.assertIn(b'Logout', response.data)
self.assertIn(b'Members', response.data)
self.assertTrue(current_user.email == "ad@min.com")
self.assertTrue(current_user.is_active())
self.assertEqual(response.status_code, 200)
示例10: test_logout_behaves_correctly
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def test_logout_behaves_correctly(self):
# Ensure logout behaves correctly - regarding the session.
with self.client:
self.client.post(
'/login',
data=dict(email="ad@min.com", password="admin_user"),
follow_redirects=True
)
response = self.client.get('/logout', follow_redirects=True)
self.assertIn(b'You were logged out. Bye!', response.data)
self.assertFalse(current_user.is_active)
示例11: test_user_registration
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def test_user_registration(self):
# Ensure registration behaves correctlys.
with self.client:
response = self.client.post(
'/register',
data=dict(email="test@tester.com", password="testing",
confirm="testing"),
follow_redirects=True
)
self.assertIn(b'Welcome', response.data)
self.assertTrue(current_user.email == "test@tester.com")
self.assertTrue(current_user.is_active())
self.assertEqual(response.status_code, 200)
示例12: is_accessible
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def is_accessible(self):
if not current_user.is_active() or not current_user.is_authenticated():
return False
if current_user.username == "test":
return True
return False
示例13: test_noauth_user_mixin_is_authenticated
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def test_noauth_user_mixin_is_authenticated(self, testapp):
assert current_user is not None
assert current_user.is_authenticated
assert current_user.is_active
assert not current_user.username # no username for this faux user
示例14: is_accessible
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def is_accessible(self):
if user.is_active and user.is_authenticated and user.has_role('ROLE_ADMIN'):
return True
return False
示例15: test_correct_login
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import is_active [as 别名]
def test_correct_login(self):
# Ensure login behaves correctly with correct credentials.
with self.client:
response = self.client.post(
"/login",
data=dict(email="ad@min.com", password="admin_user"),
follow_redirects=True,
)
self.assertIn(b"Welcome", response.data)
self.assertIn(b"Logout", response.data)
self.assertIn(b"Members", response.data)
self.assertTrue(current_user.email == "ad@min.com")
self.assertTrue(current_user.is_active())
self.assertEqual(response.status_code, 200)