Notify the user when their account needs verification.
This commit is contained in:
parent
cbe0590ce5
commit
a713555915
2 changed files with 22 additions and 10 deletions
|
@ -25,6 +25,7 @@ class _LoginWrappedDBUser(UserMixin):
|
|||
|
||||
@login_manager.user_loader
|
||||
def load_user(username):
|
||||
logger.debug('Loading user: %s' % username)
|
||||
db_user = model.get_user(username)
|
||||
if db_user:
|
||||
return _LoginWrappedDBUser(db_user)
|
||||
|
@ -38,9 +39,14 @@ def index():
|
|||
|
||||
|
||||
def common_login(db_user):
|
||||
logger.debug('Successfully signed in as: %s' % db_user.username)
|
||||
login_user(_LoginWrappedDBUser(db_user))
|
||||
identity_changed.send(app, identity=Identity(db_user.username, 'username'))
|
||||
if login_user(_LoginWrappedDBUser(db_user)):
|
||||
logger.debug('Successfully signed in as: %s' % db_user.username)
|
||||
identity_changed.send(app,
|
||||
identity=Identity(db_user.username, 'username'))
|
||||
return True
|
||||
else:
|
||||
logger.debug('User could not be logged in, inactive?.');
|
||||
return False
|
||||
|
||||
|
||||
@app.route('/signin', methods=['GET'])
|
||||
|
@ -56,14 +62,16 @@ def signin():
|
|||
#TODO Allow email login
|
||||
verified = model.verify_user(username, password)
|
||||
if verified:
|
||||
common_login(verified)
|
||||
|
||||
return redirect(request.args.get('next') or url_for('index'))
|
||||
if common_login(verified):
|
||||
return redirect(request.args.get('next') or url_for('index'))
|
||||
else:
|
||||
return render_template('signin.html',
|
||||
needs_email_verification=True)
|
||||
|
||||
else:
|
||||
return render_template('signin.html',
|
||||
username=username,
|
||||
error='Invalid username or password.')
|
||||
invalid_credentials=True)
|
||||
|
||||
|
||||
@app.route('/confirm', methods=['GET'])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Quay Sign In</title>
|
||||
<title>Sign In - Quay</title>
|
||||
|
||||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.no-icons.min.css">
|
||||
|
||||
|
@ -15,8 +15,12 @@
|
|||
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign In</button>
|
||||
</form>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger">{{ error }}</div>
|
||||
{% if invalid_credentials %}
|
||||
<div class="alert alert-danger">Invalid username or password.</div>
|
||||
{% endif %}
|
||||
|
||||
{% if needs_email_verification %}
|
||||
<div class="alert alert-danger">You must verify your email address before you can sign in.</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
|
|
Reference in a new issue