diff --git a/app/forms/account.py b/app/forms/account.py index 8a0e404..9e6f7ca 100644 --- a/app/forms/account.py +++ b/app/forms/account.py @@ -1,7 +1,8 @@ from flask_wtf import FlaskForm -from wtforms import StringField, PasswordField, BooleanField, TextAreaField, SubmitField, FileField +from wtforms import StringField, PasswordField, BooleanField, TextAreaField, SubmitField from wtforms.fields.html5 import DateField from wtforms.validators import DataRequired, Optional, Email, EqualTo +from flask_wtf.file import FileField # Cuz' wtforms' FileField is shitty import app.utils.validators as vd class RegistrationForm(FlaskForm): @@ -26,6 +27,6 @@ class UpdateAccountForm(FlaskForm): submit = SubmitField('Mettre à jour') class DeleteAccountForm(FlaskForm): - delete = BooleanField('Supprimer le compte', validators=[DataRequired()], description='Attention, cette opération est irréversible !') + delete = BooleanField('Confirmer la suppression', validators=[DataRequired()], description='Attention, cette opération est irréversible !') old_password = PasswordField('Mot de passe', validators=[DataRequired(), vd.old_password]) submit = SubmitField('Supprimer le compte') \ No newline at end of file diff --git a/app/models/users.py b/app/models/users.py index 20597e0..d896dd0 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -1,5 +1,5 @@ from datetime import date, datetime -from app import db +from app import app, db from flask_login import UserMixin from app.models.contents import Content from app.models.privs import SpecialPrivilege, Group, GroupMember, \ @@ -89,6 +89,11 @@ class Member(User, db.Model): innovation = db.Column(db.Integer) register_date = db.Column(db.Date, default=date.today) + # Avatars # TODO: rendre ça un peu plus propre + @property + def avatar(self): + return 'avatars/' + str(self.id) + '.png' + # Groups and related privileges groups = db.relationship('Group', secondary=GroupMember, back_populates='members') diff --git a/app/routes/account.py b/app/routes/account.py index a068999..aab1d20 100644 --- a/app/routes/account.py +++ b/app/routes/account.py @@ -9,45 +9,42 @@ from app.utils.render import render @login_required def account(): form = UpdateAccountForm() - del_form = DeleteAccountForm() if request.method == "POST": if form.validate_on_submit(): - # 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) + if form.avatar.data: + f = form.avatar.data + f.save("./app/static/"+current_user.avatar) + current_user.update( + email = form.email.data or None, + password = form.password.data or None, + birthday = form.birthday.data, + signature = form.signature.data, + biography = form.biography.data, + newsletter = form.newsletter.data + ) db.session.merge(current_user) db.session.commit() flash('Modifications effectuées', 'ok') else: flash('Erreur lors de la modification', 'error') - return render('account.html', form=form, del_form=del_form) + return render('account.html', form=form) @app.route('/account/delete', methods=['GET', 'POST']) def delete_account(): del_form = DeleteAccountForm() - if del_form.validate_on_submit(): - db.session.delete(current_user) - logout_user() - db.session.commit() - flash('Compte supprimé', 'ok') - return redirect(url_for('index')) - else: - flash('Erreur lors de la suppression du compte', 'error') - return render('delete_account.html', del_form=del_form) + if request.method == "POST": + if del_form.validate_on_submit(): + db.session.delete(current_user) + logout_user() + db.session.commit() + flash('Compte supprimé', 'ok') + return redirect(url_for('index')) + else: + flash('Erreur lors de la suppression du compte', 'error') + del_form.delete.data = False # Force to check the case to delete the account + return render('delete_account.html', del_form=del_form) + @app.route('/register', methods=['GET', 'POST']) def register(): diff --git a/app/static/avatars/3.png b/app/static/avatars/3.png new file mode 100644 index 0000000..9a5e46c Binary files /dev/null and b/app/static/avatars/3.png differ diff --git a/app/static/css/container.css b/app/static/css/container.css index 3dbffbf..b742cd9 100644 --- a/app/static/css/container.css +++ b/app/static/css/container.css @@ -3,7 +3,10 @@ } section { - margin: 10px 5%; + min-width: 350px; + margin: 20px auto 0; padding: 20px; + background: #ffffff; + border: 1px solid #dddddd; border-radius: 5px; } section h1 { diff --git a/app/static/css/form.css b/app/static/css/form.css index 88ebc31..4706af7 100644 --- a/app/static/css/form.css +++ b/app/static/css/form.css @@ -1,10 +1,3 @@ -.form { - min-width: 350px; - margin: 20px auto 0; padding: 20px; - background: #ffffff; - border: 1px solid #dddddd; border-radius: 5px; -} - .form .avatar { display: inline-block; vertical-align: middle; border-radius: 100%; @@ -46,16 +39,7 @@ } .form input[type="submit"] { - width: 100%; - /*background-color: #149641; - border-color: #1e7408; - color: #ffffff;*/ -} -.form input[type="submit"]:hover, -.form input[type="submit"]:focus, -.form input[type="submit"]:active { - /*background-color: #0f7331; - border-color: #073617;*/ + /*width: 20%;*/ } .form form .msgerror { diff --git a/app/static/css/global.css b/app/static/css/global.css index e5195db..7eac437 100644 --- a/app/static/css/global.css +++ b/app/static/css/global.css @@ -66,13 +66,12 @@ textarea { } /* Buttons */ +.button, input[type="button"], input[type="submit"] { - padding: 6px 0; - border-radius: 3px; - font-size: 14px; - font-weight: 400; - border: 1px solid transparent; + padding: 6px 10px; + border: 1px solid transparent; border-radius: 3px; + font-family: 'DejaVu Sans', sans-serif; font-size: 14px; font-weight: 400; } /* Checkbox */ @@ -93,25 +92,21 @@ input[type="checkbox"] { .bg-green, .bg-green { background-color: #149641; - border-color: #0e692d; color: #ffffff; } .bg-green:hover, .bg-green:focus, .bg-green:active { background-color: #0f7331; - border-color: #073617; } .bg-red, .bg-red { background-color: #c0341d; - border-color: #a62d19; color: #ffffff; } .bg-red:hover, .bg-red:focus, .bg-red:active { - background-color: #7b2112; - border-color: #073617; + background-color: #aa3421; } diff --git a/app/templates/account.html b/app/templates/account.html index 7708fd9..0933334 100644 --- a/app/templates/account.html +++ b/app/templates/account.html @@ -4,14 +4,14 @@

Gestion du compte

-
+ {{ form.hidden_tag() }}

Général

{{ form.avatar.label }}
- + {{ form.avatar }}
@@ -80,24 +80,7 @@

Supprimer le compte

-
- {{ del_form.hidden_tag() }} -
- {{ del_form.delete.label }} - {{ del_form.delete }} -
{{ del_form.delete.description }}
- {% for error in del_form.delete.errors %} - {{ error }} - {% endfor %} -
-
- {{ del_form.old_password.label }} - {{ del_form.old_password(placeholder='************') }} - {% for error in del_form.old_password.errors %} - {{ error }} - {% endfor %} -
-
{{ del_form.submit(class_="bg-red") }}
-
+ Supprimer le compte +
{% endblock %} diff --git a/app/templates/base/navbar/account.html b/app/templates/base/navbar/account.html index d69ba41..a2c67f3 100644 --- a/app/templates/base/navbar/account.html +++ b/app/templates/base/navbar/account.html @@ -1,7 +1,7 @@ {% if current_user.is_authenticated %}

- + {{ current_user.name }}

diff --git a/app/templates/delete_account.html b/app/templates/delete_account.html index 92d6bbe..70abe34 100644 --- a/app/templates/delete_account.html +++ b/app/templates/delete_account.html @@ -2,12 +2,12 @@ {% block content %}
-

Supprimer le compte

+

Suppression du compte

{{ del_form.hidden_tag() }}
{{ del_form.delete.label }} - {{ del_form.delete }} + {{ del_form.delete(checked=False) }}
{{ del_form.delete.description }}
{% for error in del_form.delete.errors %} {{ error }} diff --git a/config.py b/config.py index be42965..415e58a 100644 --- a/config.py +++ b/config.py @@ -5,6 +5,7 @@ class Config(object): SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ 'postgresql+psycopg2://' + os.environ.get('USER') + ':@/pcv5' SQLALCHEMY_TRACK_MODIFICATIONS = False + UPLOAD_FOLDER = './app/static/avatars' class V5Config(object): # Length allocated to privilege names (slugs)