From 8ebb288d1c616a5020bf3283d58c61f0e2cb6ffb Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 4 Jun 2021 19:47:07 -0700 Subject: [PATCH] Delete old user backend code --- amanuensis/server/home/__init__.py | 3 +- amanuensis/user/__init__.py | 12 ----- amanuensis/user/manage.py | 19 -------- amanuensis/user/signup.py | 77 ------------------------------ 4 files changed, 1 insertion(+), 110 deletions(-) delete mode 100644 amanuensis/user/__init__.py delete mode 100644 amanuensis/user/manage.py delete mode 100644 amanuensis/user/signup.py diff --git a/amanuensis/server/home/__init__.py b/amanuensis/server/home/__init__.py index 587ea81..68477ca 100644 --- a/amanuensis/server/home/__init__.py +++ b/amanuensis/server/home/__init__.py @@ -5,7 +5,6 @@ from amanuensis.config import RootConfigDirectoryContext from amanuensis.lexicon import create_lexicon, load_all_lexicons from amanuensis.models import UserModel, ModelFactory from amanuensis.server.helpers import admin_required -from amanuensis.user import load_all_users from .forms import LexiconCreateForm @@ -36,7 +35,7 @@ def home(): @admin_required def admin(): root: RootConfigDirectoryContext = current_app.config['root'] - users = list(load_all_users(root)) + users = [] lexicons = list(load_all_lexicons(root)) return render_template('home.admin.jinja', users=users, lexicons=lexicons) diff --git a/amanuensis/user/__init__.py b/amanuensis/user/__init__.py deleted file mode 100644 index 226e97c..0000000 --- a/amanuensis/user/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -from .manage import load_all_users -from .signup import ( - create_user, - valid_username, - valid_email) - -__all__ = [member.__name__ for member in [ - load_all_users, - create_user, - valid_username, - valid_email, -]] diff --git a/amanuensis/user/manage.py b/amanuensis/user/manage.py deleted file mode 100644 index 6440e97..0000000 --- a/amanuensis/user/manage.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -General functions for managing users -""" -from typing import Iterable - -from amanuensis.config import RootConfigDirectoryContext -from amanuensis.models import ModelFactory, UserModel - - -def load_all_users( - root: RootConfigDirectoryContext) -> Iterable[UserModel]: - """ - Iterably loads every lexicon in the config store - """ - model_factory: ModelFactory = ModelFactory(root) - with root.user.read_index() as index: - for uid in index.values(): - user: UserModel = model_factory.user(uid) - yield user diff --git a/amanuensis/user/signup.py b/amanuensis/user/signup.py deleted file mode 100644 index ff24577..0000000 --- a/amanuensis/user/signup.py +++ /dev/null @@ -1,77 +0,0 @@ -""" -Submodule encapsulating functionality pertaining to creating users in -an Amanuensis instance. -""" -import os -import re -import time -from typing import Tuple -import uuid - -from amanuensis.config import RootConfigDirectoryContext -from amanuensis.errors import ArgumentError -from amanuensis.models import ModelFactory, UserModel -from amanuensis.resources import get_stream - - -def valid_username(username: str) -> bool: - """ - A valid username is at least three characters long and composed solely of - alpahnumerics, dashes, and underscores. Additionally, usernames may not - be 32 hex digits, since that may be confused for an internal id. - """ - length_and_characters = re.match(r'^[A-Za-z0-9-_]{3,}$', username) - is_a_guid = re.match(r'^[A-Za-z0-9]{32}$', username) - return bool(length_and_characters and not is_a_guid) - - -def valid_email(email: str) -> bool: - """Vaguely RFC2822 email verifier""" - atom = r"[0-9A-Za-z!#$%&'*+-/=?^_`{|}~]{1,}" - dotatom = atom + r"(\." + atom + r")*" - addrspec = '^' + dotatom + '@' + dotatom + '$' - return bool(re.match(addrspec, email)) - - -def create_user( - root: RootConfigDirectoryContext, - model_factory: ModelFactory, - username: str, - displayname: str, - email: str) -> Tuple[UserModel, str]: - """ - Creates a new user - """ - # Validate arguments - if not valid_username(username): - raise ArgumentError('Invalid username: "{}"'.format(username)) - if email and not valid_email(email): - raise ArgumentError('Invalid email: "{}"'.format(email)) - - # Create the user directory and config file - uid: str = uuid.uuid4().hex - user_dir: str = os.path.join(root.user.path, uid) - os.mkdir(user_dir) - with get_stream('user.json') as s: - path: str = os.path.join(user_dir, 'config.json') - with open(path, 'wb') as f: - f.write(s.read()) - - # Create the user index entry - with root.user.edit_index() as index: - index[username] = uid - - # Fill out the new user - with root.user[uid].edit_config() as cfg: - cfg.uid = uid - cfg.username = username - cfg.displayname = displayname - cfg.email = email - cfg.created = int(time.time()) - - # Load the user model and set a temporary password - temporary_password = os.urandom(32).hex() - user = model_factory.user(uid) - user.set_password(temporary_password) - - return user, temporary_password