~sircmpwn/meta.sr.ht

ref: 72548bd7545f78670878667674cc7645835a17bd meta.sr.ht/metasrht/auth/base.py -rw-r--r-- 780 bytes
72548bd7Drew DeVault API: Updates per core-go auth changes 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import Optional

from srht.database import db
from srht.validation import Validation

from metasrht.types.user import User


def get_user(username: str) -> Optional[User]:
    return User.query.filter(
        (User.username == username.lower()) |
        (User.email == username.strip())).one_or_none()


class AuthMethod:
    def user_valid(self, valid: Validation, username: str, password: str) \
            -> bool:
        raise NotImplementedError()

    def prepare_user(self, username: str) -> User:
        raise NotImplementedError()

    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()