Add in beginings of auth system
This commit is contained in:
33
src/auth.py
Normal file
33
src/auth.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
from flask import Blueprint
|
||||||
|
from user_model import User
|
||||||
|
from main import db
|
||||||
|
|
||||||
|
auth = Blueprint("auth_api", __name__)
|
||||||
|
|
||||||
|
@auth.route("/login")
|
||||||
|
def login(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
@auth.route("/logout")
|
||||||
|
def logout(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
@auth.route("/user")
|
||||||
|
def get_current_user(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
@auth.route("/user", methods=["POST"])
|
||||||
|
def create_user(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
@auth.route("/user/<user_id>", methods=["POST"])
|
||||||
|
def update_user(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
@auth.route("/user/<user_id>", methods=["DELETE"])
|
||||||
|
def delete_user(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
@auth.route("/user/<user_id>")
|
||||||
|
def get_user(self):
|
||||||
|
return
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
|
from sqlalchemy import Column, ForeignKey, Integer, Table
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
from main import db
|
from main import db
|
||||||
|
|
||||||
|
def create_new_session(user: User) -> Session:
|
||||||
|
return
|
||||||
|
|
||||||
class User(db.Model):
|
class User(db.Model):
|
||||||
|
|
||||||
@@ -8,5 +12,25 @@ class User(db.Model):
|
|||||||
user_id = db.Column(db.Integer, primary_key=True)
|
user_id = db.Column(db.Integer, primary_key=True)
|
||||||
password_hash = db.Column(db.Text)
|
password_hash = db.Column(db.Text)
|
||||||
user_name = db.Column(db.Text, unique=True)
|
user_name = db.Column(db.Text, unique=True)
|
||||||
|
sessions = relationship("Session", back_populates="user")
|
||||||
|
|
||||||
|
def set_password(self, newPassword: str):
|
||||||
|
self.password_hash = "testing"
|
||||||
|
|
||||||
|
def test_password(self, password: str) -> bool:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {"username": self.user_name}
|
||||||
|
|
||||||
|
class Session(db.Model):
|
||||||
|
|
||||||
|
__tableanme__ = "sessions"
|
||||||
|
|
||||||
|
session_id = db.Column(db.Text, primary_key=True)
|
||||||
|
parent_id = db.Column(db.Integer, ForeignKey("users.user_id"))
|
||||||
|
issue_timestamp = db.Column(db.Integer)
|
||||||
|
user = relationship("User", back_populates="sessions")
|
||||||
|
|
||||||
|
def session_active(self):
|
||||||
|
return True
|
||||||
|
|||||||
75
src/users.py
75
src/users.py
@@ -1,75 +0,0 @@
|
|||||||
from typeing import List
|
|
||||||
from flask import Blueprint, current_app
|
|
||||||
from werkzeug.security import generate_password_hash, check_password_hash
|
|
||||||
|
|
||||||
|
|
||||||
class User:
|
|
||||||
_id: int
|
|
||||||
_username: str
|
|
||||||
_hash: str
|
|
||||||
_updated: bool
|
|
||||||
_created: bool
|
|
||||||
_delete: bool
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
id,
|
|
||||||
username,
|
|
||||||
hash,
|
|
||||||
created: bool = False,
|
|
||||||
updated: bool = False,
|
|
||||||
delete: bool = False,
|
|
||||||
):
|
|
||||||
return
|
|
||||||
|
|
||||||
def check_password(self, password: str):
|
|
||||||
return
|
|
||||||
|
|
||||||
def commit(self):
|
|
||||||
return
|
|
||||||
|
|
||||||
@property
|
|
||||||
def hash(self):
|
|
||||||
return self._hash
|
|
||||||
|
|
||||||
@hash.setter
|
|
||||||
def set_hash(self, password: str):
|
|
||||||
self._updated = False
|
|
||||||
self._hash = generate_password_hash(password)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def username(self):
|
|
||||||
return self.username
|
|
||||||
|
|
||||||
@username.setter
|
|
||||||
def set_username(self, username):
|
|
||||||
self._updated = False
|
|
||||||
self._username = username
|
|
||||||
|
|
||||||
|
|
||||||
class UserService:
|
|
||||||
|
|
||||||
def __init__():
|
|
||||||
return
|
|
||||||
|
|
||||||
def read_by_username(username: str) -> User:
|
|
||||||
return
|
|
||||||
|
|
||||||
def read_all() -> List[User]:
|
|
||||||
return []
|
|
||||||
|
|
||||||
def check_login(username: str, password: str):
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
users = Blueprint("users_api", __name__)
|
|
||||||
|
|
||||||
|
|
||||||
@users.route("/login", method=["POST"])
|
|
||||||
def login():
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
@users.route("/logout", method=["POST"])
|
|
||||||
def logout():
|
|
||||||
return
|
|
||||||
Reference in New Issue
Block a user