Burathar
4 years ago
6 changed files with 106 additions and 28 deletions
@ -1,3 +1,6 @@
@@ -1,3 +1,6 @@
|
||||
from .project import Project |
||||
from .user import User |
||||
from .yaml_serializable import YamlSerializable |
||||
|
||||
User.initialize() |
||||
Project.initialize() |
||||
|
@ -1,17 +1,39 @@
@@ -1,17 +1,39 @@
|
||||
from pathlib import Path |
||||
from werkzeug.security import generate_password_hash, check_password_hash |
||||
|
||||
from biscd import config |
||||
from biscd.models import YamlSerializable |
||||
from .yaml_serializable import YamlSerializable |
||||
from biscd import login |
||||
|
||||
class User(YamlSerializable): |
||||
|
||||
class Project(YamlSerializable): |
||||
@property |
||||
def _storage_file(self): |
||||
return Path(config.config_dir()) / 'users.yaml' |
||||
|
||||
@property |
||||
@classmethod |
||||
def _yaml_object_name(self): |
||||
return 'users' |
||||
|
||||
def __init__(self, name=None, password=None, email=None): |
||||
def __init__(self, id=None, name=None, email=None, password=None, password_hash=None): |
||||
super().__init__(id) |
||||
self.name = name |
||||
self.password = password |
||||
self.password_hash = set_password(password, password_hash) |
||||
self.email = email |
||||
|
||||
def set_password(password, password_hash): |
||||
if password_hash: |
||||
return password_hash |
||||
if password: |
||||
return generate_password_hash(password) |
||||
return None |
||||
|
||||
def check_password(self, password): |
||||
if not password: |
||||
return False |
||||
return check_password_hash(self.password_hash, password) |
||||
|
||||
@login.user_loader |
||||
def load_user(id): |
||||
return super.get(int(id)) |
||||
|
Loading…
Reference in new issue