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