def confirm(id): """The view to confirm a new account's email.""" #: get resources user = User.query.get_or_404(id) service = SignUpService(user) input_token = request.args['token'] #: active current account try: service.active(input_token) except TokenUsedError: message = _(u"The account had been actived.") return render_template("confirm-failed.html", message=message), 403 except TokenWrongError: message = _(u"The active token is invalid.") return render_template("confirm-failed.html", message=message), 403 #: automatic sign in session_login(user) #: output a success message message = _(u"The account has been actived successfully.") return render_template("confirm-success.html", message=message)
class SignUpView(MethodView): """The view to sign up.""" def prepare(self): self.form = SignUpForm() self.user = User() self.service = SignUpService(self.user) def get(self): return render_template("signup.html", **vars(self)) def post(self): #: validate input if not self.form.validate(): return render_template("signup.html", **vars(self)) #: inject data self.form.populate_obj(self.user) #: call the sign up service self.service.signup() self.service.send_confirm_mail() #: redirect to user's person page return redirect(url_for("account.person", id=self.user.id))
def prepare(self): self.form = SignUpForm() self.user = User() self.service = SignUpService(self.user)