def index(): account_form = AccountForm() if account_form.validate_on_submit(): email_changed = account_form.email.data != current_user.email current_user.update({ "name": account_form.name.data, "email": account_form.email.data, "email_verified_at": None if email_changed else current_user.email_verified_at, "confirmation_token": generate_random_str(40) if email_changed else None }) flash("Votre compte a été mis à jour avec succès", "success") if email_changed: flash( "Your account has been disabled, you must validate your email", "warning") send_validation_email(current_user) return redirect(url_for("settings.index")) account_form.name.data = current_user.name account_form.email.data = current_user.email return render_template("settings/index.html", form=account_form)
def avatar(): avatar_file = request.files['avatar'] if not avatar_file: return _error_response("Please provide an image") extension = avatar_file.filename.split(".")[-1] if not extension or not extension in avatar_extensions: return _error_response("Please provide a valid image") avatar_name = generate_random_str(20) + '.' + extension.lower() avatar_file.save(os.path.join(app.config['AVATAR_FOLDER'], avatar_name)) current_user.update({"avatar": avatar_name}) return jsonify({"avatar": current_user.profile_picture})
def register(): registration_form = RegistrationForm() if registration_form.validate_on_submit(): name = registration_form.name.data email = registration_form.email.data password = bcrypt.generate_password_hash( registration_form.password.data).decode('utf-8') user = User.create(name=name, email=email, password=password, confirmation_token=generate_random_str(length=50), created_at=datetime.utcnow()) registration_mail = RegistrationMail(recipient=user) registration_mail.send() flash("You have been registered successfully. Please valid your email", "success") return redirect(url_for("main.index")) return render_template('auth/register.html', form=registration_form)