Python flask_login.current_user.is_active() Examples
The following are 23
code examples of flask_login.current_user.is_active().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_login.current_user
, or try the search function
.
Example #1
Source File: test_extension.py From flask-bitmapist with MIT License | 6 votes |
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)
Example #2
Source File: test_user.py From cookiecutter-flask-skeleton with MIT License | 6 votes |
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)
Example #3
Source File: security.py From flask-react-spa with MIT License | 5 votes |
def is_accessible(self): if user.is_active and user.is_authenticated and user.has_role('ROLE_ADMIN'): return True return False
Example #4
Source File: test_user.py From flask-registration with MIT License | 5 votes |
def test_reset_forgotten_password_valid_token_correct_login(self): # Ensure user can confirm account with valid token. with self.client: self.client.post('/forgot', data=dict( email='test@user.com', ), follow_redirects=True) token = generate_confirmation_token('test@user.com') response = self.client.get('/forgot/new/'+token, follow_redirects=True) self.assertTemplateUsed('user/forgot_new.html') self.assertIn( b'You can now change your password.', response.data ) response = self.client.post( '/forgot/new/'+token, data=dict(password="new-password", confirm="new-password"), follow_redirects=True ) self.assertIn( b'Password successfully changed.', response.data ) self.assertTemplateUsed('user/profile.html') self.assertTrue(current_user.is_authenticated()) self.client.get('/logout') self.assertFalse(current_user.is_authenticated()) response = self.client.post( '/login', data=dict(email="test@user.com", password="new-password"), follow_redirects=True ) self.assertTrue(response.status_code == 200) self.assertTrue(current_user.email == "test@user.com") self.assertTrue(current_user.is_active()) self.assertTrue(current_user.is_authenticated()) self.assertTemplateUsed('main/index.html')
Example #5
Source File: test_user.py From flask-registration with MIT License | 5 votes |
def test_incorrect_login(self): # Ensure login behaves correctly with incorrect credentials. with self.client: response = self.client.post( '/login', data=dict(email="not@correct.com", password="incorrect"), follow_redirects=True ) self.assertTrue(response.status_code == 200) self.assertIn(b'Invalid email and/or password.', response.data) self.assertFalse(current_user.is_active()) self.assertFalse(current_user.is_authenticated()) self.assertTemplateUsed('user/login.html')
Example #6
Source File: test_user.py From flask-registration with MIT License | 5 votes |
def test_correct_login(self): # Ensure login behaves correctly with correct credentials. with self.client: response = self.client.post( '/login', data=dict(email="test@user.com", password="just_a_test_user"), follow_redirects=True ) self.assertTrue(response.status_code == 200) self.assertTrue(current_user.email == "test@user.com") self.assertTrue(current_user.is_active()) self.assertTrue(current_user.is_authenticated()) self.assertTemplateUsed('main/index.html')
Example #7
Source File: test_user.py From openci with MIT License | 5 votes |
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'Projects', response.data) self.assertTrue(current_user.email == "test@tester.com") self.assertTrue(current_user.is_active()) self.assertEqual(response.status_code, 200)
Example #8
Source File: test_user.py From openci with MIT License | 5 votes |
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)
Example #9
Source File: test_user.py From openci with MIT License | 5 votes |
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'Projects', response.data) self.assertTrue(current_user.email == "ad@min.com") self.assertTrue(current_user.is_active()) self.assertEqual(response.status_code, 200)
Example #10
Source File: test_extension.py From flask-bitmapist with MIT License | 5 votes |
def test_flask_login_user_logout(app): login_manager = LoginManager() login_manager.init_app(app) user_id = datetime.now().microsecond with app.test_request_context(): # set up, log in, and log out user user = User() user.id = user_id login_user(user) logout_user() # test that user was logged out assert not current_user.is_active assert not current_user.is_authenticated assert not current_user == user # test that user id was marked with 'user:logged_out' event assert user_id in MonthEvents('user:logged_out', now.year, now.month) # SQLALCHEMY # TODO: Instead of sqlalchemy fixture (return: db, User), # each test could use sqlalchemy fixture (return: # db) and sqlalchemy_user fixture (return: User); # tests should use whichever is better practice.
Example #11
Source File: test_user.py From cookiecutter-flask-skeleton with MIT License | 5 votes |
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)
Example #12
Source File: test_user.py From cookiecutter-flask-skeleton with MIT License | 5 votes |
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)
Example #13
Source File: rules.py From flask-restplus-server-example with MIT License | 5 votes |
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
Example #14
Source File: test_integration.py From doorman with MIT License | 5 votes |
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
Example #15
Source File: ctf.py From CTF with MIT License | 5 votes |
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
Example #16
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
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)
Example #17
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
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)
Example #18
Source File: test_user.py From docker-cloud-flask-demo with MIT License | 5 votes |
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)
Example #19
Source File: views.py From yeti with Apache License 2.0 | 5 votes |
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)
Example #20
Source File: views.py From yeti with Apache License 2.0 | 5 votes |
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()
Example #21
Source File: webapp.py From yeti with Apache License 2.0 | 5 votes |
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
Example #22
Source File: webapp.py From yeti with Apache License 2.0 | 5 votes |
def frontend_login_required(): if not current_user.is_active and (request.endpoint and request.endpoint != 'frontend.static'): return login_manager.unauthorized()
Example #23
Source File: accounts.py From DIVE-backend with GNU General Public License v3.0 | 5 votes |
def logged_in(): return current_user.is_authenticated and current_user.is_active()