~fnux/meta.sr.ht

7ca5b840472c986caa5ff6239e3d1da8e95b1f5a — Timothée Floure 8 months ago e929d46
Make email change logic more generic
3 files changed, 9 insertions(+), 2 deletions(-)

M metasrht/auth/__init__.py
M metasrht/auth/base.py
M metasrht/blueprints/auth.py
M metasrht/auth/__init__.py => metasrht/auth/__init__.py +3 -0
@@ 39,3 39,6 @@ def prepare_user(user: str) -> User:

def set_user_password(user: User, password: str) -> None:
    return _auth_method.set_user_password(user, password)

def set_user_email(user: User, email: str) -> None:
    return _auth_method.set_user_email(user, email)

M metasrht/auth/base.py => metasrht/auth/base.py +4 -0
@@ 22,3 22,7 @@ class AuthMethod:

    def set_user_password(self, user: User, password: str) -> bool:
        raise NotImplementedError()

    def set_user_email(self, user: User, email: str) -> bool:
        user.email = email
        db.session.commit()

M metasrht/blueprints/auth.py => metasrht/blueprints/auth.py +2 -2
@@ 3,7 3,7 @@ from flask import Blueprint, render_template, abort, request, redirect
from flask import url_for
from metasrht.audit import audit_log
from metasrht.auth import allow_registration, user_valid, prepare_user
from metasrht.auth import is_external_auth, set_user_password
from metasrht.auth import is_external_auth, set_user_password, set_user_email
from metasrht.auth.builtin import hash_password, check_password
from metasrht.auth_validation import validate_password
from metasrht.auth_validation import validate_username, validate_email


@@ 213,7 213,7 @@ def confirm_account(token):
        user.confirmation_hash = None
        audit_log("email updated",
            "{} became {}".format(user.email, user.new_email), user=user)
        user.email = user.new_email
        set_user_email(user, user.new_email)
        user.new_email = None
        db.session.commit()