|
|
|
@ -40,9 +40,12 @@ def signup(): |
|
|
|
@bp.route('/signup', methods=['POST']) |
|
|
|
def signup_post(): |
|
|
|
username = request.form.get('username') |
|
|
|
email = request.form.get('email') |
|
|
|
password = request.form.get('password') |
|
|
|
confirm_password = request.form.get('confirm_password') |
|
|
|
photo = request.files['fotoperfil'] |
|
|
|
# photo = request.files['fotoperfil'] |
|
|
|
|
|
|
|
photo = request.files['photo'] |
|
|
|
|
|
|
|
if password != confirm_password: |
|
|
|
flash('Passwords do not match.') |
|
|
|
@ -53,6 +56,12 @@ def signup_post(): |
|
|
|
if user: # if a user is found, we want to redirect back to signup page so user can try again |
|
|
|
flash('Ese usuario ya existe') |
|
|
|
return redirect(url_for('auth.signup')) |
|
|
|
|
|
|
|
correo = User.query.filter_by(email=email).first() # if this returns a user, then the user already exists in database |
|
|
|
|
|
|
|
if correo: # if a user is found, we want to redirect back to signup page so user can try again |
|
|
|
flash('Ese correo ya existe') |
|
|
|
return redirect(url_for('auth.signup')) |
|
|
|
|
|
|
|
if photo: |
|
|
|
photo_filename = secure_filename(photo.filename) |
|
|
|
@ -63,7 +72,7 @@ def signup_post(): |
|
|
|
photo_filename = "" |
|
|
|
|
|
|
|
# create a new user with the form data. Hash the password so the plaintext version isn't saved. |
|
|
|
new_user = User(username=username, password=generate_password_hash(password, method='pbkdf2:sha256'), photo=photo_filename) |
|
|
|
new_user = User(email=email, username=username, password=generate_password_hash(password, method='pbkdf2:sha256'), photo=photo_filename) |
|
|
|
|
|
|
|
# add the new user to the database |
|
|
|
db.session.add(new_user) |
|
|
|
|