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
|
@login_manager.user_loader
|
||||||
def load_user(username):
|
def load_user(username):
|
||||||
|
logger.debug('Loading user: %s' % username)
|
||||||
db_user = model.get_user(username)
|
db_user = model.get_user(username)
|
||||||
if db_user:
|
if db_user:
|
||||||
return _LoginWrappedDBUser(db_user)
|
return _LoginWrappedDBUser(db_user)
|
||||||
|
@ -38,9 +39,14 @@ def index():
|
||||||
|
|
||||||
|
|
||||||
def common_login(db_user):
|
def common_login(db_user):
|
||||||
logger.debug('Successfully signed in as: %s' % db_user.username)
|
if login_user(_LoginWrappedDBUser(db_user)):
|
||||||
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'))
|
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'])
|
@app.route('/signin', methods=['GET'])
|
||||||
|
@ -56,14 +62,16 @@ def signin():
|
||||||
#TODO Allow email login
|
#TODO Allow email login
|
||||||
verified = model.verify_user(username, password)
|
verified = model.verify_user(username, password)
|
||||||
if verified:
|
if verified:
|
||||||
common_login(verified)
|
if common_login(verified):
|
||||||
|
return redirect(request.args.get('next') or url_for('index'))
|
||||||
return redirect(request.args.get('next') or url_for('index'))
|
else:
|
||||||
|
return render_template('signin.html',
|
||||||
|
needs_email_verification=True)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return render_template('signin.html',
|
return render_template('signin.html',
|
||||||
username=username,
|
username=username,
|
||||||
error='Invalid username or password.')
|
invalid_credentials=True)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/confirm', methods=['GET'])
|
@app.route('/confirm', methods=['GET'])
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<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">
|
<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>
|
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign In</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if error %}
|
{% if invalid_credentials %}
|
||||||
<div class="alert alert-danger">{{ error }}</div>
|
<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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
Reference in a new issue