def validate(self): if not super(ChangePasswordForm, self).validate(): return False valid = True if not check_login(current_user.username, self.password.data): self.password.errors.append('Incorrect password.') valid = False if self.password.data == self.new_password.data: self.new_password.errors.append('Same as current password.') valid = False return valid
def login(): form = LoginForm() if form.validate_on_submit(): username = form.username.data password = form.password.data user = check_login(username, password) if user is not None: login_user(user) flash('Logged in successfully.', 'success') return redirect(request.args.get('next') or url_for('radar.index')) else: form.username.errors.append('Incorrect username or password.') return render_template('login.html', form=form)