class LoginView(MethodView): """The view to login.""" def prepare(self): self.form = LoginForm() def _render_page(self): return render_template("login.html", **vars(self)) def get(self): return self._render_page() def post(self): #: validate input if not self.form.validate(): return self._render_page() #: try to authenticate try: user = User.query.authenticate(self.form.login.data, self.form.password.data) except (UserNotFoundError, PasswordWrongError): message = _(u"The user is not found or the password is wrong.") flash(message, "error") return self._render_page() else: session_login(user) flash(_(u"Welcome %(name)s.", name=user.nickname), "info") #: redirect to user's person page return redirect(url_for("master.home"))
def prepare(self): self.form = LoginForm()