Overall linting #3
@@ -1,6 +1,6 @@
|
||||
from . import (
|
||||
ldap_client
|
||||
)
|
||||
"""
|
||||
Module that represents the /password route
|
||||
"""
|
||||
from flask import (
|
||||
Blueprint,
|
||||
render_template,
|
||||
@@ -25,10 +25,19 @@ from wtforms.validators import (
|
||||
Email
|
||||
)
|
||||
|
||||
from . import (
|
||||
ldap_client
|
||||
)
|
||||
|
||||
|
||||
bp = Blueprint('password', __name__, url_prefix='/password')
|
||||
|
||||
|
||||
class ChangePasswordForm(FlaskForm):
|
||||
"""
|
||||
A Flask form that asks users about various informations needed
|
||||
to change their password.
|
||||
"""
|
||||
# Minimal password length
|
||||
minlength = 9
|
||||
|
||||
@@ -61,7 +70,10 @@ class ChangePasswordForm(FlaskForm):
|
||||
"onclick": f"validate_username_form({minlength})"})
|
||||
|
||||
# Validators
|
||||
def validate_username(self, username):
|
||||
def validate_username(self):
|
||||
"""
|
||||
A validation function for the username input field
|
||||
"""
|
||||
excluded_chars = " *?!'^+%&/()=}][{$#;\\\""
|
||||
for char in self.username.data:
|
||||
if char in excluded_chars:
|
||||
@@ -70,6 +82,10 @@ class ChangePasswordForm(FlaskForm):
|
||||
|
||||
|
||||
class ResetPasswordForm(FlaskForm):
|
||||
"""
|
||||
A Flask form that asks users about their email, used to
|
||||
reset their passwords.
|
||||
"""
|
||||
email = EmailField(label=('Email address'),
|
||||
validators=[DataRequired(), Email()],
|
||||
render_kw={"onkeyup": "validate_email()"})
|
||||
@@ -83,20 +99,26 @@ class ResetPasswordForm(FlaskForm):
|
||||
|
||||
@bp.route('/change', methods=["GET", "POST"])
|
||||
def change():
|
||||
"""
|
||||
The /password/change route method
|
||||
"""
|
||||
form = ChangePasswordForm()
|
||||
if form.validate_on_submit():
|
||||
client = ldap_client.Client(address=current_app.config["LDAP_ADDR"],
|
||||
ldap_params = ldap_client.ClientParams(
|
||||
address=current_app.config["LDAP_ADDR"],
|
||||
port=current_app.config["LDAP_PORT"],
|
||||
base_dn=current_app.config["BASE_DN"],
|
||||
tls=current_app.config["LDAP_TLS"])
|
||||
client = ldap_client.Client(ldap_params)
|
||||
|
||||
bind_status = client.bind(
|
||||
form.username._value(), form.currentpassword._value())
|
||||
form.username.data, form.currentpassword.data)
|
||||
|
||||
if bind_status[0] is False:
|
||||
flash("Connection failed, are you sure that your login and"
|
||||
f" password are correct ? ({client.link.last_error})")
|
||||
elif client.change_pwd(bind_status[1],
|
||||
form.newpassword._value()) is False:
|
||||
form.newpassword.data) is False:
|
||||
flash("An error occured and your password was not changed, sorry."
|
||||
f"({client.link.last_error})")
|
||||
client.unbind()
|
||||
@@ -109,4 +131,7 @@ def change():
|
||||
|
||||
@bp.route('/reset', methods=["GET"])
|
||||
def reset():
|
||||
"""
|
||||
The /password/reset route method
|
||||
"""
|
||||
return render_template('reset.html')
|
||||
|
||||
Reference in New Issue
Block a user