def login(): if current_user.is_authenticated: flash('You are already logged in.') return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): user = studentList.find_one({'email': form.email.data}) student = Student() student.buildFromDict(user) if user is None or not student.check_password( form.password.data): #checks that password matches input flash('Invalid email or password') return redirect(url_for('login')) login_user(student, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template('login.html', title='Sign In', form=form)
def test_password_hashing(self): u = Student(student_full_name='susan') u.set_password('cat') self.assertFalse(u.check_password('dog')) self.assertTrue(u.check_password('cat'))