mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
108536490: Implement locked out function.
User is locked if they fail to login 10 times or more.
This commit is contained in:
@@ -24,3 +24,9 @@ def get_all_users():
|
||||
|
||||
def get_user_by_email(email_address):
|
||||
return User.query.filter_by(email_address=email_address).first()
|
||||
|
||||
|
||||
def increment_failed_login_count(id):
|
||||
user = User.query.filter_by(id=id).first()
|
||||
user.failed_login_count += 1
|
||||
db.session.commit()
|
||||
|
||||
@@ -20,11 +20,14 @@ def process_sign_in():
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
user = users_dao.get_user_by_email(form.email_address.data)
|
||||
if user.is_locked():
|
||||
return jsonify(locked_out=True), 401
|
||||
if user is None:
|
||||
return jsonify(authorization=False), 401
|
||||
if checkpw(form.password.data, user.password):
|
||||
login_user(user)
|
||||
else:
|
||||
users_dao.increment_failed_login_count(user.id)
|
||||
return jsonify(authorization=False), 401
|
||||
else:
|
||||
return jsonify(form.errors), 400
|
||||
|
||||
@@ -56,7 +56,7 @@ class User(db.Model):
|
||||
return self.id
|
||||
|
||||
def is_locked(self):
|
||||
if self.failed_login_count <= current_app.config['MAX_FAILED_LOGIN_COUNT']:
|
||||
if self.failed_login_count < current_app.config['MAX_FAILED_LOGIN_COUNT']:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user