def user_admin_reset_password(self): """ Reset the password :returns string: The new password string """ try: id = request.form.get("id") user = User.get(id) if not user: raise UserError("Invalid User") method_ = self.get_config("LOGIN_RESET_PASSWORD_METHOD", "").upper() new_password = None if method_ == "TOKEN": token = user.set_temp_login() url = url_for(endpoint_namespace % "temp_login_token", token=token, _external=True) else: new_password = user.set_password(password=None, random=True) url = url_for(endpoint_namespace % "login", _external=True) mailer.send_template("reset-password.txt", method_=method_, to=user.email, name=user.email, url=url, new_password=new_password) flash("Password Reset instruction is sent to email", "success") except ApplicationError as ex: flash("Error: %s " % ex.message, "error") return redirect(url_for("UserAdmin:get", id=id))
def lost_password(self): self._login_enabled() logout_user() self.meta_tags(title="Lost Password") if request.method == "POST": email = request.form.get("email") user = User.get_by_email(email) if user: delivery = self._package_conf.get("password_reset_method") new_password = None if delivery.upper() == "TOKEN": token = user.set_temp_login() url = url_for(endpoint_namespace % "reset_password", token=token, _external=True) else: new_password = user.set_password(password=None, random=True) url = url_for(endpoint_namespace % "login", _external=True) mailer.send_template("reset-password.txt", method_=delivery, to=user.email, name=user.email, url=url, new_password=new_password) flash("A new password has been sent to '%s'" % email, "success") else: flash("Invalid email address", "error") return redirect(url_for(login_view)) else: return {}
def contact_page(self): # Email to email_to = kwargs.pop("email_to", self.get_config("APPLICATION_CONTACT_EMAIL", None)) if mailer.validated is not True: abort("MailerMisconfiguredError") elif not email_to: abort("ContactPageMissingEmailToError") if request.method == "POST": email = request.form.get("email") subject = request.form.get("subject") message = request.form.get("message") name = request.form.get("name") flash_message = "Message sent. Thank you!" flash_type = "success" if recaptcha.verify(): if not email or not subject or not message: flash_message = "All fields are required" flash_type = "error" elif not utils.is_valid_email(email): flash_message = "Invalid email address" flash_type = "error" else: try: mailer.send_template("contact-us.txt", to=email_to, reply_to=email, mail_from=email, mail_subject=subject, mail_message=message, mail_name=name) except Exception as ex: abort("MailerMisconfiguredError") else: flash_message = "Security code is invalid" flash_type = "error" flash(flash_message, flash_type) return redirect(url_for(return_to)) self.meta_tags(title="Contact Us") return {}