def test_change_password(self): user = PortalUser(email="*****@*****.**", first_name="Test", last_name="User") user.set_password("password") user.save() login_data = {"email": "*****@*****.**", "password": "******"} response = self.client.post('/login', data=login_data, follow_redirects=True) response = self.client.get('/user/[email protected]/change_password/') assert response.status_code == 200 pw_data = {"password": "******", "confirm": "newpassword"} response = self.client.post('/user/[email protected]/change_password/', data=pw_data, follow_redirects=True) assert response.status_code == 200 assert PortalUser.check_login("*****@*****.**", "newpassword") assert not PortalUser.check_login("*****@*****.**", "password") self.client.get("/logout") login_data = {"email": "*****@*****.**", "password": "******"} response = self.client.post('/login', data=login_data, follow_redirects=True) assert "Invalid" not in response.data assert "You were logged in" in response.data
def test_passwords(self): user = PortalUser(email="*****@*****.**", first_name="Test", last_name="User") user.set_password("password") user.save() assert PortalUser.check_login("*****@*****.**", "password") assert not PortalUser.check_login("*****@*****.**", "password") assert not PortalUser.check_login("*****@*****.**", "wrong")
def login(): error = None if request.method == 'POST': if PortalUser.check_login(request.form['email'], request.form['password']): session['logged_in'] = True flash('You were logged in') return redirect(url_for('users.list_users')) error = "Invalid email or password" form = LoginForm() return render_template('login.html', form=form, error=error)
def test_change_password(self): user = PortalUser(email="*****@*****.**", first_name="Test", last_name="User") user.set_password("password") user.save() login_data = { "email": "*****@*****.**", "password": "******"} response = self.client.post('/login', data=login_data, follow_redirects=True) response = self.client.get('/user/[email protected]/change_password/') assert response.status_code == 200 pw_data = {"password": "******", "confirm": "newpassword"} response = self.client.post('/user/[email protected]/change_password/', data=pw_data, follow_redirects=True) assert response.status_code == 200 assert PortalUser.check_login("*****@*****.**", "newpassword") assert not PortalUser.check_login("*****@*****.**", "password") self.client.get("/logout") login_data = { "email": "*****@*****.**", "password": "******"} response = self.client.post('/login', data=login_data, follow_redirects=True) assert "Invalid" not in response.data assert "You were logged in" in response.data
def test_change_email(self): user = PortalUser(email="*****@*****.**", first_name="Test", last_name="User") user.set_password("password") user.save() login_data = { "email": "*****@*****.**", "password": "******"} response = self.client.post('/login', data=login_data, follow_redirects=True) test_data = { "email": '*****@*****.**', "first_name": "Test", "last_name": "User", "id": str(user.id), } response = self.client.post('/user/save/', data=test_data, follow_redirects=False) assert PortalUser.find_by_email("*****@*****.**") assert PortalUser.check_login("*****@*****.**", "password")
def test_change_email(self): user = PortalUser(email="*****@*****.**", first_name="Test", last_name="User") user.set_password("password") user.save() login_data = {"email": "*****@*****.**", "password": "******"} response = self.client.post('/login', data=login_data, follow_redirects=True) test_data = { "email": '*****@*****.**', "first_name": "Test", "last_name": "User", "id": str(user.id), } response = self.client.post('/user/save/', data=test_data, follow_redirects=False) assert PortalUser.find_by_email("*****@*****.**") assert PortalUser.check_login("*****@*****.**", "password")