diff --git a/login-mecanics/content/forms.py b/login-mecanics/content/forms.py index a54e6fc..63937f4 100644 --- a/login-mecanics/content/forms.py +++ b/login-mecanics/content/forms.py @@ -1,9 +1,9 @@ # coding: utf-8 from flask_wtf import FlaskForm -from wtforms import StringField, PasswordField, SubmitField, BooleanField +from wtforms import StringField, PasswordField, SubmitField, BooleanField, HiddenField from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError from flask_login import current_user -from webinterface.models.system import Persona +from webinterface.models.system import Persona, Correo import pwnedpasswords class LoginForm(FlaskForm): @@ -53,3 +53,32 @@ class RegistrationForm(FlaskForm): def validate_password(self, clave): if pwnedpasswords.check(clave.data): raise ValidationError(u'La clave ingresada es insegura. Verifíquelo en \';--have i been pwned?') + + +class mMiCuenta(FlaskForm): + id = HiddenField() + login = StringField('Usuario', render_kw={'readonly': True}) + nombrecompleto = StringField('Nombre', render_kw={'readonly': True}) + + + correo = StringField('Correo Principal', validators=[DataRequired(), Email()]) + clave = PasswordField('Clave') + fono = StringField('Telefono', render_kw={"placeholder": "+569 8765 4321"}) + + submit = SubmitField('Modificar') + + def validate_fono(self, field): + parsed = field.data.replace(" ", "") + + if not parsed: + raise ValidationError(u'Debe ingresar un número de teléfono.') + if not parsed.startswith('+'): + raise ValidationError(u'Ingrese el número completo "+569XYZWABCD".') + if len(parsed) < 11: + raise ValidationError(u'Ingrese el número completo "+569XYZWABCD".') + if not parsed[1:].isdigit(): + raise ValidationError(u'El número ingresado no es válido, contiene caracteres no-numéricos.') + + def validate_clave(self, field): + if field.data and pwnedpasswords.check(field.data): + raise ValidationError(u'La clave ingresada es insegura. Verifíque la seguridad de su clave en \';--have i been pwned?') diff --git a/login-mecanics/content/main.py b/login-mecanics/content/main.py index 0817679..ee673f0 100644 --- a/login-mecanics/content/main.py +++ b/login-mecanics/content/main.py @@ -8,7 +8,7 @@ from webinterface import db, bcrypt from sqlalchemy import func from datetime import datetime, date from webinterface.models.system import Persona, Ipaddr, Dispositivo, Identidad, Sesion, Registro, Conexion, Ruta, Sitio, Correo -from webinterface.content.forms import RegistrationForm, LoginForm, RequestResetForm, ResetPasswordForm +from webinterface.content.forms import mMiCuenta, LoginForm, RequestResetForm, ResetPasswordForm from webinterface.content.utils import clean_str, es_local main = Blueprint('main', __name__) @@ -23,7 +23,7 @@ else: def login(): if current_user.is_authenticated: - return redirect(url_for('main.dashboard')) + return redirect(systemuri) form = LoginForm() if form.validate_on_submit(): @@ -52,12 +52,41 @@ def logout(): return redirect('https://tpmc.ilab.cl/') -@main.route("/me") +@main.route("/system/me", methods=['GET', 'POST']) @login_required -def me(): - image_file = url_for('static', filename='profile_pics/' + current_user.foto) - return render_template('system/me.html', title=u'¿Quién soy?', - image_file=image_file) +def micuenta(): + form = mMiCuenta() + + if form.validate_on_submit(): + if form.clave.data: + hashed_password = bcrypt.generate_password_hash(form.clave.data).decode('utf-8') + current_user.clave = hashed_password + + trimmed = form.correo.data.strip().lower() + + correo = Correo.query.filter_by(correo=trimmed).first() + if correo is None: + correo = Correo(correo=trimmed, cuenta=current_user) + + current_user.correodefecto=correo + current_user.telefono = form.fono.data.replace(" ", "") + db.session.commit() + + flash(u'Los datos de tu cuenta han sido actualizados.', 'success') + return redirect(url_for('main.micuenta')) + + elif request.method == 'GET': + + if current_user.correodefecto is not None: + form.correo.data = current_user.correodefecto.correo + + form.id.data = current_user.id + form.login.data = current_user.rut + form.nombrecompleto.data = current_user.nombrecompleto + form.fono.data = current_user.telefono + + return render_template('system/me.html', title='Mi Cuenta', form=form) + @main.before_app_request def registra_sesion(): diff --git a/login-mecanics/templates/system/me.html b/login-mecanics/templates/system/me.html index a2f4239..2e48a61 100644 --- a/login-mecanics/templates/system/me.html +++ b/login-mecanics/templates/system/me.html @@ -1,43 +1,65 @@ {% extends "layout.html" %} {% block content %} -

{{ title }}

-
- -
- {% if not current_user.alias %} - - {% else %} - - {% endif %} -

{{ current_user.correodefecto.correo }}

-
-
-
- Información de la Cuenta -
- Nombre: - {{ current_user.nombrecompleto }} -
-
- Login: - {{ current_user.login }} -
-
- Correo: - {{ current_user.correodefecto.correo }} -
- Personalización -
- Alias: - {{ current_user.alias }} -
-
+
+ {{ form.hidden_tag() }} +
+ Datos del usuario +
+ {{ form.nombrecompleto.label() }} + {{ form.nombrecompleto(class="form-control form-control-lg") }} +
+
+ {{ form.login.label(class="form-control-label") }} + {{ form.login(class="form-control form-control-lg") }} +
+ Actualizar Información +
+ {{ form.correo.label(class="form-control-label") }} (obligatorio) + {% if form.correo.errors %} + {{ form.correo(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.correo.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.correo(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.fono.label(class="form-control-label") }} (obligatorio) + {% if form.fono.errors %} + {{ form.fono(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.fono.errors %} + {{ error }} + {% endfor %} +
+ {% else %} + {{ form.fono(class="form-control form-control-lg") }} + {% endif %} +
+
+ {{ form.clave.label(class="form-control-label") }} + {% if form.clave.errors %} + {{ form.clave(class="form-control form-control-lg is-invalid") }} +
+ {% for error in form.clave.errors %} + {{ error|safe }} + {% endfor %} +
+ {% else %} + {{ form.clave(class="form-control form-control-lg") }} + {% endif %}
+
+ {{ form.submit(class="btn btn-lg btn-primary") }} + Volver +
-Volver {% endblock content %} diff --git a/private-dynamic/templates/layout.html b/private-dynamic/templates/layout.html index de4d393..78a40e1 100644 --- a/private-dynamic/templates/layout.html +++ b/private-dynamic/templates/layout.html @@ -10,9 +10,9 @@ {% if title %} - iLab Gestión Académica - {{ title }} + Gestión del Transporte Público del Gran Concepción - {{title}} {% else %} - iLab Gestión Académica + Gestión del Transporte Público del Gran Concepción {% endif %} @@ -34,7 +34,7 @@ - + @@ -111,7 +111,7 @@