Created
March 11, 2021 17:34
-
-
Save meepoSenpai/4515b634120812d9b959223b2b27ef41 to your computer and use it in GitHub Desktop.
User Stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User(DB.Entity): | |
id = PrimaryKey(int, auto=True) | |
name = Required(str) | |
mail = Required(str) | |
passhash = Required(str) | |
@db_session | |
def create(username: str, email: str, passhash: str): | |
if username == None or passhash == None or email == None: | |
raise ValueError("Username, E-Mail or Password can't be None") | |
user = User(name=username, mail=email, passhash=passhash) | |
commit() | |
return user | |
@db_session | |
def find_by_id(id: int): | |
return User[id] | |
@db_session | |
def find_by_name(name: str): | |
return select(user for user in User if user.name == name)[:] | |
@db_session | |
def remove_from_db(id: int, password: str): | |
if password != User[id].passhash: | |
raise ValueError("Incorrect Password") | |
User[id].delete() | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment