Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def login():
"""Login request."""
if app.config['TRACK_USER_INTERACTION']:
add_user_interaction(db.session, interaction='landing')
if flask_login.current_user.is_authenticated:
logger.info('User already logged-in')
session['logged_in'] = True
return redirect(url_for('ramp.problems'))
form = LoginForm()
if form.validate_on_submit():
user = get_user_by_name_or_email(db.session,
name=form.user_name.data)
if user is None:
msg = 'User "{}" does not exist'.format(form.user_name.data)
flash(msg)
logger.info(msg)
return redirect(url_for('auth.login'))
if not check_password(form.password.data,
user.hashed_password):
msg = 'Wrong password'
flash(msg)
logger.info(msg)
return redirect(url_for('auth.login'))
flask_login.login_user(user, remember=True)
session['logged_in'] = True