Browse Source

resolving issue with login redirects going to wrong hostname

joel
Simon Bowie 2 years ago
parent
commit
33d8be3193
1 changed files with 5 additions and 5 deletions
  1. +5
    -5
      web/app/auth.py

+ 5
- 5
web/app/auth.py View File

# take the user-supplied password, hash it, and compare it to the hashed password in the database # take the user-supplied password, hash it, and compare it to the hashed password in the database
if not user or not check_password_hash(user.password, password): if not user or not check_password_hash(user.password, password):
flash('Please check your login details and try again.') flash('Please check your login details and try again.')
return redirect(url_for('auth.login')) # if the user doesn't exist or password is wrong, reload the page
return redirect(url_for('auth.login',_external=True)) # if the user doesn't exist or password is wrong, reload the page


# if the above check passes, then we know the user has the right credentials # if the above check passes, then we know the user has the right credentials
login_user(user, remember=remember) login_user(user, remember=remember)
return redirect(url_for('main.profile'))
return redirect(url_for('main.profile',_external=True))


# routes for signup page # routes for signup page
@auth.route('/signup') @auth.route('/signup')


if user: # if a user is found, we want to redirect back to signup page so user can try again if user: # if a user is found, we want to redirect back to signup page so user can try again
flash('Email address already exists') flash('Email address already exists')
return redirect(url_for('auth.signup'))
return redirect(url_for('auth.signup',_external=True))


# create a new user with the form data. Hash the password so the plaintext version isn't saved. # create a new user with the form data. Hash the password so the plaintext version isn't saved.
new_user = User(email=email, name=name, password=generate_password_hash(password, method='sha256')) new_user = User(email=email, name=name, password=generate_password_hash(password, method='sha256'))
db.session.add(new_user) db.session.add(new_user)
db.session.commit() db.session.commit()


return redirect(url_for('auth.login'))
return redirect(url_for('auth.login',_external=True))


# route for logout function # route for logout function
@auth.route('/logout') @auth.route('/logout')
@login_required @login_required
def logout(): def logout():
logout_user() logout_user()
return redirect(url_for('main.index'))
return redirect(url_for('main.index',_external=True))

Loading…
Cancel
Save