Overall linting #3
@@ -1,21 +1,33 @@
|
|||||||
from . import ldap_client
|
from . import (
|
||||||
|
ldap_client
|
||||||
|
)
|
||||||
from flask import (
|
from flask import (
|
||||||
Blueprint, render_template, flash,
|
Blueprint,
|
||||||
|
render_template,
|
||||||
|
flash,
|
||||||
current_app
|
current_app
|
||||||
)
|
)
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import (
|
||||||
|
FlaskForm
|
||||||
|
)
|
||||||
from wtforms import (
|
from wtforms import (
|
||||||
StringField, PasswordField,
|
StringField,
|
||||||
SubmitField, EmailField
|
PasswordField,
|
||||||
|
SubmitField,
|
||||||
|
EmailField
|
||||||
)
|
)
|
||||||
from wtforms.validators import (
|
from wtforms.validators import (
|
||||||
ValidationError, DataRequired,
|
ValidationError,
|
||||||
EqualTo, Length, Regexp, Email
|
DataRequired,
|
||||||
|
EqualTo,
|
||||||
|
Length,
|
||||||
|
Regexp,
|
||||||
|
Email
|
||||||
)
|
)
|
||||||
|
|
||||||
bp = Blueprint('password', __name__, url_prefix='/password')
|
bp = Blueprint('password', __name__, url_prefix='/password')
|
||||||
|
|
||||||
|
|
||||||
class ChangePasswordForm(FlaskForm):
|
class ChangePasswordForm(FlaskForm):
|
||||||
# Minimal password length
|
# Minimal password length
|
||||||
minlength = 9
|
minlength = 9
|
||||||
@@ -33,18 +45,19 @@ class ChangePasswordForm(FlaskForm):
|
|||||||
Regexp("^(?=.*[a-z])"),
|
Regexp("^(?=.*[a-z])"),
|
||||||
Regexp("^(?=.*[A-Z])"),
|
Regexp("^(?=.*[A-Z])"),
|
||||||
Regexp("^(?=.*\\d)"),
|
Regexp("^(?=.*\\d)"),
|
||||||
#Regexp(
|
|
||||||
# "(?=.*[@$!%*#?&])", message="Password must contain a special character"
|
|
||||||
#),],
|
|
||||||
],
|
],
|
||||||
render_kw={"onkeyup": f"validate_username_form({minlength})"})
|
render_kw={"onkeyup": "validate_username_form"
|
||||||
|
f"({minlength})"})
|
||||||
confirm_password = PasswordField(
|
confirm_password = PasswordField(
|
||||||
label=('Confirm Password'),
|
label=('Confirm Password'),
|
||||||
validators=[DataRequired(message='* Required'),
|
validators=[DataRequired(message='* Required'),
|
||||||
EqualTo('newpassword')],
|
EqualTo('newpassword')],
|
||||||
render_kw={"onkeyup": f"validate_username_form({minlength})"})
|
render_kw={"onkeyup": f"validate_username_form({minlength})"})
|
||||||
|
|
||||||
submit = SubmitField(label=('Change my password'), render_kw={"disabled": "true",
|
submit = SubmitField(
|
||||||
|
label=('Change my password'),
|
||||||
|
render_kw={
|
||||||
|
"disabled": "true",
|
||||||
"onclick": f"validate_username_form({minlength})"})
|
"onclick": f"validate_username_form({minlength})"})
|
||||||
|
|
||||||
# Validators
|
# Validators
|
||||||
@@ -55,25 +68,37 @@ class ChangePasswordForm(FlaskForm):
|
|||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
f"Character {char} is not allowed in an username.")
|
f"Character {char} is not allowed in an username.")
|
||||||
|
|
||||||
|
|
||||||
class ResetPasswordForm(FlaskForm):
|
class ResetPasswordForm(FlaskForm):
|
||||||
email = EmailField(label=('Email address'),
|
email = EmailField(label=('Email address'),
|
||||||
validators=[DataRequired(), Email()],
|
validators=[DataRequired(), Email()],
|
||||||
render_kw={"onkeyup": f"validate_email()"})
|
render_kw={"onkeyup": "validate_email()"})
|
||||||
|
|
||||||
|
submit = SubmitField(
|
||||||
|
label=('Change my password'),
|
||||||
|
render_kw={
|
||||||
|
"disabled": "true",
|
||||||
|
"onclick": "validate_email()"})
|
||||||
|
|
||||||
submit = SubmitField(label=('Change my password'), render_kw={"disabled": "true",
|
|
||||||
"onclick": f"validate_email()"})
|
|
||||||
|
|
||||||
@bp.route('/change', methods=["GET", "POST"])
|
@bp.route('/change', methods=["GET", "POST"])
|
||||||
def change():
|
def change():
|
||||||
form = ChangePasswordForm()
|
form = ChangePasswordForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
client = ldap_client.Client(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(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"])
|
||||||
|
|
||||||
bind_status = client.bind(form.username._value(), form.currentpassword._value())
|
bind_status = client.bind(
|
||||||
if bind_status[0] == False:
|
form.username._value(), form.currentpassword._value())
|
||||||
flash(f"Connection failed, are you sure that your login and password are correct ? ({client.link.last_error})")
|
if bind_status[0] is False:
|
||||||
elif client.change_pwd(bind_status[1], form.newpassword._value()) == False:
|
flash("Connection failed, are you sure that your login and"
|
||||||
flash(f"An error occured and your password was not changed, sorry. ({client.link.last_error})")
|
f" password are correct ? ({client.link.last_error})")
|
||||||
|
elif client.change_pwd(bind_status[1],
|
||||||
|
form.newpassword._value()) is False:
|
||||||
|
flash("An error occured and your password was not changed, sorry."
|
||||||
|
f"({client.link.last_error})")
|
||||||
client.unbind()
|
client.unbind()
|
||||||
else:
|
else:
|
||||||
flash('Your password has been changed !')
|
flash('Your password has been changed !')
|
||||||
@@ -81,6 +106,7 @@ def change():
|
|||||||
|
|
||||||
return render_template('change.html', form=form)
|
return render_template('change.html', form=form)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/reset', methods=["GET"])
|
@bp.route('/reset', methods=["GET"])
|
||||||
def reset():
|
def reset():
|
||||||
return render_template('reset.html')
|
return render_template('reset.html')
|
||||||
@@ -11,3 +11,5 @@ zipp==3.6.0
|
|||||||
ldap3
|
ldap3
|
||||||
Flask-WTF==1.0.0
|
Flask-WTF==1.0.0
|
||||||
email-validator
|
email-validator
|
||||||
|
flake8
|
||||||
|
bandit
|
||||||
Reference in New Issue
Block a user