Browse Source

Updates sur le formulaire de gestion du compte

master
Dark-Storm 8 months ago
parent
commit
1e28547b9e
Signed by: Dark-Storm <l.gatin@neuf.fr> GPG Key ID: F61F10FA138E797C

+ 4
- 4
app/forms/account.py View File

@@ -14,13 +14,13 @@ class RegistrationForm(FlaskForm):
submit = SubmitField('S\'enregistrer')

class UpdateAccountForm(FlaskForm):
avatar = FileField('Avatar :', validators=[])
email = StringField('Adresse Email :', validators=[Optional(), Email(), vd.email])
password = PasswordField('Mot de passe :', validators=[Optional(), vd.password])
avatar = FileField('Avatar :', validators=[Optional(), vd.avatar])
email = StringField('Adresse Email :', validators=[Optional(), Email(), vd.email, vd.old_password])
password = PasswordField('Mot de passe :', validators=[Optional(), vd.password, vd.old_password])
password2 = PasswordField('Répéter le mot de passe', validators=[Optional(), EqualTo('password')])
old_password = PasswordField('Ancien mot de passe :', validators=[Optional()])
birthday = DateField('Anniversaire', validators=[Optional()])
signature = TextAreaField('Signature', validators=[Optional()])
biography = TextAreaField('Présentation', validators=[Optional()])
newsletter = BooleanField('Inscription à la newsletter', description='Un mail par trimestre environ, pour être prévenu des concours, évènements et nouveautés.')
old_password = PasswordField('Ancien mot de passe :', validators=[DataRequired(), vd.authentication])
submit = SubmitField('Mettre à jour')

+ 17
- 9
app/routes/account.py View File

@@ -11,15 +11,23 @@ def account():
form = UpdateAccountForm()
if request.method == "POST":
if form.validate_on_submit():
current_user.update(
email= form.email.data,
password= form.password.data,
signature= form.signature.data,
bio= form.biography.data,
birthday= form.birthday.data,
newsletter= form.newsletter.data
)
db.session.add(current_user)
# Updates to do
updates = {}
# Optional updates (do not update if blank)
if form.email.data:
updates['email'] = form.email.data
if form.password.data:
updates['password'] = form.password.data
# Required updates (update if blank)
updates.update({
"signature": form.signature.data,
"bio": form.biography.data,
"birthday": form.birthday.data,
"newsletter": form.newsletter.data
})
# Do the fucking updates
current_user.update(**updates)
db.session.merge(current_user)
db.session.commit()
flash('Modifications effectuées', 'ok')
else:

+ 8
- 1
app/static/css/container.css View File

@@ -10,7 +10,14 @@ section h1 {
margin-top: 0;
border-bottom: 1px solid #a0a0a0;
font-family: Raleway; font-size: 32px;
font-weight: 200; color: #242424;
font-weight: 300; color: #242424;
}

section h2 {
margin-top: 0;
border-bottom: 1px solid #a0a0a0;
font-family: Raleway; font-size: 26px;
font-weight: 300; color: #242424;
}

/* #container h1 {

+ 6
- 2
app/static/css/form.css View File

@@ -10,7 +10,7 @@
border-radius: 100%;
width: 150px; height: 150px;
}
.form input[type="file"] {
.form .avatar + input[type="file"] {
display: inline-block; margin-left: 20px;
vertical-align: middle;
}
@@ -24,6 +24,10 @@
margin-bottom: 5px;
}

.form input {
cursor: pointer; /* don't know why it is not a cursor by default */
}

.form input[type='text'],
.form input[type='email'],
.form input[type='date'],
@@ -44,7 +48,7 @@
.form input[type="submit"] {
width: 100%;
background-color: #149641;
border-color: #0e692d;
border-color: #1e7408;
color: #ffffff;
}
.form input[type="submit"]:hover,

+ 1
- 1
app/static/css/global.css View File

@@ -25,7 +25,7 @@

body {
margin: 0;
background: #fbfbfb;
background: #ffffff;
font-family: 'DejaVu Sans', sans-serif;
}


+ 13
- 8
app/templates/account.html View File

@@ -7,6 +7,7 @@
<form action="" method="post">
{{ form.hidden_tag() }}

<h2>Général</h2>
<div>
{{ form.avatar.label }}
<div>
@@ -35,6 +36,15 @@
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form.old_password.label }}
{{ form.old_password(placeholder='************') }}
{% for error in form.old_password.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>

<h2>À propos</h2>
<div>
{{ form.birthday.label }}
{{ form.birthday(value=current_user.birthday) }}
@@ -56,21 +66,16 @@
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>

<h2>Préférences</h2>
<div>
{{ form.newsletter.label }}
{{ form.newsletter() }}
{{ form.newsletter(checked=current_user.newsletter) }}
<div style="font-size:80%;color:rgba(0,0,0,.5)">{{ form.newsletter.description }}</div>
{% for error in form.newsletter.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form.old_password.label }}
{{ form.old_password(placeholder='************') }}
{% for error in form.old_password.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>{{ form.submit(class_="bg-green") }}</div>
</form>
</section>

+ 12
- 4
app/utils/validators.py View File

@@ -1,4 +1,6 @@
from flask_login import current_user
from wtforms.validators import ValidationError
from app.models.users import Member

def name(form, name):
member = Member.query.filter_by(name=name.data).first()
@@ -14,9 +16,15 @@ def email(form, email):

def password(form, password):
if len(password.data) != 0 and len(password.data) < 10:
raise ValidationError('Mot de passe est trop court (10 caractères minimum)')
raise ValidationError('Mot de passe est trop court (10 caractères minimum).')
# TODO: add more rules >:]

def authentication(form, old_password):
if not current_user.check_password(old_password.data):
raise ValidationError('Mot de passe erroné')
def avatar(form, avatar):
pass

def old_password(form, field):
if field.data:
if not form.old_password.data:
raise ValidationError('Votre ancien mot de passe est requis pour cette modification.')
if not current_user.check_password(form.old_password.data):
raise ValidationError('Mot de passe actuel erroné.')

Loading…
Cancel
Save