[NO TESTS] WIP
This commit is contained in:
parent
ae6044c76e
commit
4413df7132
5 changed files with 28 additions and 10 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
from pathlib import Path
|
||||
import click
|
||||
from flask import Flask, request, session, current_app
|
||||
from flask import Flask, request, session, current_app, Authorization
|
||||
import tomllib
|
||||
|
||||
from tentacles.blueprints import ui, api
|
||||
|
|
|
@ -20,8 +20,8 @@ from flask import (
|
|||
BLUEPRINT = Blueprint("ui", __name__)
|
||||
|
||||
|
||||
def is_logged_in(authorization):
|
||||
return False
|
||||
def is_logged_in(request: Request) -> bool:
|
||||
return request.uid is not None
|
||||
|
||||
|
||||
@BLUEPRINT.route("/")
|
||||
|
@ -37,7 +37,7 @@ def root():
|
|||
|
||||
@BLUEPRINT.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if is_logged_in(request.authorization):
|
||||
if is_logged_in(request):
|
||||
return redirect("/")
|
||||
|
||||
elif request.method == "POST":
|
||||
|
@ -61,12 +61,15 @@ def login():
|
|||
|
||||
@BLUEPRINT.route("/register", methods=["GET", "POST"])
|
||||
def register():
|
||||
if is_logged_in(request.authorization):
|
||||
if is_logged_in(request):
|
||||
return redirect("/")
|
||||
|
||||
elif request.method == "POST":
|
||||
try:
|
||||
if uid := current_app.db.try_create_user(
|
||||
request.form["username"], request.form["password"]
|
||||
request.form["username"],
|
||||
request.form["email"],
|
||||
request.form["password"],
|
||||
):
|
||||
flash(
|
||||
"Please check your email for a verification request",
|
||||
|
|
|
@ -8,12 +8,26 @@ INSERT OR IGNORE INTO groups (id, name, priority) VALUES (0, 'root', 20);
|
|||
INSERT OR IGNORE INTO groups (id, name, priority) VALUES (0, 'users', 10);
|
||||
INSERT OR IGNORE INTO groups (id, name, priority) VALUES (0, 'guests', 0);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS user_statuses (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||
, name TEXT
|
||||
, UNIQUE(name)
|
||||
);
|
||||
|
||||
INSERT OR IGNORE INTO user_statuses (id, name) values (-1, 'disabled');
|
||||
INSERT OR IGNORE INTO user_statuses (id, name) values (-2, 'unverified');
|
||||
INSERT OR IGNORE INTO user_statuses (id, name) values (1, 'enabled');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||
, group_id INTEGER
|
||||
, name TEXT
|
||||
, email TEXT
|
||||
, hash TEXT
|
||||
, status_id INTEGER
|
||||
, verification_id INTEGER
|
||||
, FOREIGN KEY(group_id) REFERENCES groups(id)
|
||||
, FOREIGN KEY(status_id) REFERENCES user_statuses(id)
|
||||
, UNIQUE(name)
|
||||
);
|
||||
|
||||
|
|
|
@ -73,14 +73,14 @@ class Store(object):
|
|||
|
||||
@fmap(one)
|
||||
@requires_conn
|
||||
def try_create_user(self, username, password):
|
||||
def try_create_user(self, username, email, password):
|
||||
"""Attempt to create a new user."""
|
||||
|
||||
digest = sha3_256()
|
||||
digest.update(password.encode("utf-8"))
|
||||
return self._conn.execute(
|
||||
"INSERT INTO users (name, hash) VALUES (?, ?) RETURNING (id)",
|
||||
[username, digest.hexdigest()],
|
||||
"INSERT INTO users (name, email, hash) VALUES (?, ?, ?) RETURNING (id)",
|
||||
[username, email, digest.hexdigest()],
|
||||
).fetchone()
|
||||
|
||||
@requires_conn
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
<h1>Register</h1>
|
||||
<form method="post">
|
||||
<p>Username: <input type="text" name="username">
|
||||
<p>Email address: <input type="text" name="email">
|
||||
<p>Password: <input type="password" name="password">
|
||||
<p><input type="submit" value=Login>
|
||||
<p><input type="submit" value=Register>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue