Browse Source

Avancées sur la page de modification du profil

pull/12/head
Dark-Storm 2 years ago
parent
commit
04c2bd50c4
Signed by: Darks GPG Key ID: F61F10FA138E797C
7 changed files with 100 additions and 42 deletions
  1. +12
    -6
      app/forms.py
  2. +9
    -9
      app/models/users.py
  3. +16
    -4
      app/routes.py
  4. +31
    -15
      app/static/css/global.css
  5. +1
    -1
      app/static/css/header.css
  6. +6
    -3
      app/static/css/register.css
  7. +25
    -4
      app/templates/account.html

+ 12
- 6
app/forms.py View File

@ -1,9 +1,12 @@
from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import ValidationError, DataRequired, Email, EqualTo
from wtforms import StringField, PasswordField, BooleanField, TextAreaField, SubmitField
from wtforms.fields.html5 import DateField
from wtforms.validators import ValidationError, DataRequired, Optional, Email, EqualTo
from app.models.users import Member
from wtforms.meta import DefaultMeta
# TODO: Put those validators into a specific file
def validate_username(self, username):
@ -34,7 +37,7 @@ class LoginForm(FlaskForm):
class RegistrationForm(FlaskForm):
username = StringField('Pseudonyme :', validators=[DataRequired()], validate_username)
username = StringField('Pseudonyme :', validators=[DataRequired(), validate_username])
email = StringField('Adresse Email :', validators=[DataRequired(), Email(), validate_email])
password = PasswordField('Mot de passe', validators=[DataRequired(), validate_password])
password2 = PasswordField('Répéter le mot de passe', validators=[DataRequired(), EqualTo('password')])
@ -43,9 +46,12 @@ class RegistrationForm(FlaskForm):
submit = SubmitField('S\'enregistrer')
class UpdateAccountForm(FlaskForm):
email = StringField('Adresse Email :', validators=[Email(), validate_email])
password = PasswordField('Mot de passe :', validators=[validate_password])
password2 = PasswordField('Répéter le mot de passe', validators=[EqualTo('password')])
email = StringField('Adresse Email :', validators=[Optional(), Email(), validate_email])
password = PasswordField('Mot de passe :', validators=[Optional(), validate_password])
password2 = PasswordField('Répéter le mot de passe', validators=[Optional(), EqualTo('password')])
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(), verify_authentication])
submit = SubmitField('Mettre à jour')

+ 9
- 9
app/models/users.py View File

@ -28,8 +28,8 @@ class Member(User, db.Model):
password_hash = db.Column(db.String(255))
xp_points = db.Column(db.Integer)
innovation_points = db.Column(db.Integer)
biography = db.column(db.Text(convert_unicode=True))
signature = db.column(db.Text(convert_unicode=True))
biography = db.Column(db.Text(convert_unicode=True))
signature = db.Column(db.Text(convert_unicode=True))
birthday = db.Column(db.Date)
register_date = db.Column(db.Date, default=date.today)
# Relations
@ -48,19 +48,19 @@ class Member(User, db.Model):
biography=None, signature=None, birthday=None,
receive_newsletter=None):
# TODO: verify good type of those args, think about the password mgt
if username != None:
if username:
self.username = username
if email != None:
if email:
self.email = email
if password != None:
if password:
self.set_password(password)
if biography != None:
if biography:
self.biography = biography
if signature != None:
if signature:
self.signature = signature
if birthday != None:
if birthday:
self.birthday = birthday
if receive_newsletter != None:
if receive_newsletter:
self.receive_newsletter = receive_newsletter
def get_public_data(self, username=False, xp_points=False,


+ 16
- 4
app/routes.py View File

@ -39,10 +39,20 @@ def account():
return redirect(url_for('index'))
form = LoginForm()
form2 = UpdateAccountForm()
if form2.validate_on_submit():
flash('Modifications pas encore effectuées', 'ok')
else:
flash('Erreur quelque part', 'error')
if request.method == "POST":
if form2.validate_on_submit():
current_user.update(
email = form2.email.data,
password = form2.password.data,
signature = form2.signature.data,
biography = form2.biography.data,
birthday = form2.birthday.data,
receive_newsletter = form2.newsletter.data)
db.session.add(current_user)
db.session.commit()
flash('Modifications effectuées', 'ok')
else:
flash('Erreur lors de la modification', 'error')
return render_template('account.html', form=form, form2=form2)
@app.route('/register', methods=['GET', 'POST'])
@ -53,6 +63,8 @@ def register():
form2 = RegistrationForm()
if form2.validate_on_submit():
member = Member(form2.username.data, form2.email.data, form2.password.data)
member.biography = ""
member.signature = ""
db.session.add(member)
db.session.commit()
flash('Inscription réussie', 'ok')


+ 31
- 15
app/static/css/global.css View File

@ -7,17 +7,20 @@
@font-face { font-family: Raleway; font-weight: 300; src: url(../fonts/raleway_300.ttf); }
/*
ALL
*/
* {
box-sizing: border-box;
transition: .15s ease;
}
/*
body
Body
*/
body {
@ -27,8 +30,9 @@ body {
}
/*
links
Links
*/
a {
@ -40,6 +44,27 @@ a:focus {
/*
Inputs
*/
input,
textarea {
display: block;
background: #FFFFFF; color: #000000;
border: none;
}
input:focus:not(type="button"),
textarea:focus {
box-shadow: 0 0 0 0.2rem rgba(0,123,255,0.25);
}
/* Textarea */
textarea {
width: 100%;
border: 1px solid #eeeeee;
}
/* Buttons */
input[type="button"],
input[type="submit"] {
@ -52,24 +77,15 @@ input[type="submit"] {
/* Checkbox */
input[type="checkbox"] {
display: inline;
vertical-align: middle;
}
/* Input text */
input[type="text"],
input[type="search"],
input[type="password"] {
background: #FFFFFF; color: #000000;
}
input[type="text"]:focus,
input[type="search"]:focus,
input[type="password"]:focus {
box-shadow: :0 0 0 0.2rem rgba(0,123,255,0.25);
}
/* Bootstrap-style rules */
/*
Bootstrap-style rules
*/
.flex {
display: flex;
}


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

@ -21,7 +21,7 @@ header a:hover > svg, header a:focus > svg {
}
header input[type="search"] {
width: 250px;
display: inline-block; width: 250px;
padding: 5px 35px 5px 10px;
border: 0; border-radius: 1px;
font-family: "Segoe UI", Helvetica, "Droid Sans", Arial,sans-serif;


+ 6
- 3
app/static/css/register.css View File

@ -14,15 +14,18 @@
#register form > div > input[type='text'],
#register form > div > input[type='email'],
#register form > div > input[type='password'] {
#register form > div > input[type='date'],
#register form > div > input[type='password'],
#register form > div > textarea {
display: block;
width: 100%; padding: 6px 2.5%;
border: 1px solid #abcdef;
}
#register form > div > input[type='text']:focus,
#register form > div > input[type='email']:focus,
#register form > div > input[type='password']:focus {
#register form > div > input[type='date']:focus,
#register form > div > input[type='password']:focus,
#register form > div > textarea:focus {
box-shadow: 0 0 4px rgba(0, 102, 255, .9);
}


+ 25
- 4
app/templates/account.html View File

@ -9,25 +9,46 @@
{{ form2.hidden_tag() }}
<div>
{{ form2.email.label }}
{{ form2.email() }}
{{ form2.email(placeholder=current_user.email) }}
{% for error in form2.email.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form2.password.label }}
{{ form2.password() }}
{{ form2.password(placeholder='************') }}
{% for error in form2.password.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form2.password2.label }}
{{ form2.password2() }}
{{ form2.password2(placeholder='************') }}
{% for error in form2.password2.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form2.birthday.label }}
{{ form2.birthday(value=current_user.birthday) }}
{% for error in form2.birthday.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form2.signature.label }}
<textarea id="{{ form2.signature.name }}" name="{{ form2.signature.name }}">{{ current_user.signature }}</textarea>
{% for error in form2.signature.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form2.biography.label }}
<textarea id="{{ form2.biography.name }}" name="{{ form2.biography.name }}">{{ current_user.biography }}</textarea>
{% for error in form2.biography.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}
</div>
<div>
{{ form2.newsletter.label }}
{{ form2.newsletter() }}
@ -38,7 +59,7 @@
</div>
<div>
{{ form2.old_password.label }}
{{ form2.old_password() }}
{{ form2.old_password(placeholder='************') }}
{% for error in form2.old_password.errors %}
<span class="msgerror">{{ error }}</span>
{% endfor %}


Loading…
Cancel
Save