def update(self, request: Request, validate: Validator): errors = request.validate( validate.required("password"), validate.confirmed("password"), validate.length( "password", min=config("auth.password_min_length"), max=config("auth.password_max_length"), ), ) if errors: request.session.flash("error", errors) return request.back() user = AUTH["model"].where("remember_token", request.param("token")).first() if user: user.password = bcrypt_password(request.input("password")) user.remember_token = None user.save() if request.user(): auth.sign_out() request.session.flash( "success", "Your password has been reset. Login below.") return request.redirect("/users/sign-in")
def store( self, request: Request, mail_manager: MailManager, auth: Auth, validate: Validator, ): errors = request.validate( validate.required(["name", "email", "password"]), validate.email("email"), validate.not_in_database( "email", table="users", column="email", messages={"email": "This email address is already registered"}, ), validate.confirmed("password"), validate.length( "password", min=config("auth.password_min_length"), max=config("auth.password_max_length"), ), ) if errors: return return_with_errors(errors) auth.register({ "name": request.input("name"), "password": request.input("password"), "email": request.input("email"), }) user = User.where("email", request.input("email")).first() if isinstance(user, MustVerifyEmail): user.verify_email(mail_manager, request) # Login the user if auth.login(user.email, request.input("password")): request.session.flash( "success", "Your account has been successfully created. Check your email to verify your email address.", ) return request.redirect("/")