59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
# This will essentially run one a successful registration happens
|
|
# This could become a class or function in the user_info file
|
|
## Since this file is essentially just going to be using that one
|
|
## However it will also create some of its own database entries
|
|
|
|
import sqlite3
|
|
from modules.data.config import read as config_read
|
|
from modules.data.database import connect as db_connect
|
|
|
|
from modules.algorithms.uuid import generate as uuid_generate
|
|
from modules.algorithms.uuid import long_hash as hash_string
|
|
|
|
from modules.user import info
|
|
|
|
db = db_connect()
|
|
db.create(None)
|
|
cur = db.cur
|
|
|
|
|
|
def auth_credentials(user_id, username, password, level):
|
|
cur.execute("INSERT INTO auth_credentials (user_id, username, password, level) VALUES (?, ?, ?, ?)", (user_id, username, password, level))
|
|
|
|
return user_id
|
|
|
|
def profile(user_id):
|
|
cur.execute("INSERT INTO profile (user_id) VALUES (?)", (user_id,))
|
|
|
|
occupation_id = config_read("user", "DeafultOccupation")
|
|
|
|
# finds wether or not the occupation_id exists
|
|
cur.execute("SELECT name FROM occupations WHERE occupation_id = ?", (occupation_id,))
|
|
rez = cur.fetchone()
|
|
if rez:
|
|
info.occupation(user_id).set({"occupation_id":occupation_id})
|
|
|
|
def team(user_id, name="friends"):
|
|
team_id = uuid_generate()
|
|
|
|
cur.execute("INSERT INTO teams (team_id, name, user_id) VALUES (?, ?, ?)", (team_id, name, user_id))
|
|
cur.execute("INSERT INTO team_leaders (team_id, user_id) VALUES (?, ?)", (team_id, user_id))
|
|
|
|
|
|
def main(username, password, level):
|
|
user_id = uuid_generate()
|
|
password_hash = hash_string(password + user_id)
|
|
|
|
auth_credentials(user_id, username, password_hash, level)
|
|
profile(user_id)
|
|
team(user_id)
|
|
|
|
db.commit()
|
|
return user_id
|
|
|
|
if __name__ == "__main__":
|
|
main("test_user", "test_password")
|
|
|
|
|
|
|