diff --git a/backend/actions/actions.py b/backend/actions/actions.py index b614e346..062d2001 100644 --- a/backend/actions/actions.py +++ b/backend/actions/actions.py @@ -4,6 +4,10 @@ from apiserver.data import Source, ops from apiserver import data +from apiserver.data.api.ud.userdata import new_userdata +from apiserver.lib.model.entities import SignedUp +from auth.data.relational.opaque import get_setup +from faker import Faker import opaquepy as opq @@ -95,6 +99,59 @@ async def print_admin_token(): print(admin_token) +async def generate_dummies(): + local_dsrc = await get_local_dsrc() + faker = Faker() + admin_password = "admin" + async with data.get_conn(local_dsrc) as conn: + setup = await get_setup(conn) + + # setup = "" + faker_u = faker.unique + + for i in range(99): + fname = faker_u.first_name() + lname = faker_u.last_name() + email = f"{fname}.{lname}@gmail.com" + su = SignedUp( + firstname=fname, + lastname=lname, + email=email, + phone=faker_u.phone_number(), + confirmed=True, + ) + av40id = int.from_bytes(faker_u.binary(2), byteorder="big") + register_id = auth.core.util.random_time_hash_hex() + joined = faker.date() + async with data.get_conn(local_dsrc) as conn: + uid = await data.user.new_user( + conn, + su, + register_id=register_id, + av40id=av40id, + joined=joined, + ) + userdata = new_userdata(su, uid, register_id, av40id, joined) + + cl_req, cl_state = opq.register_client(admin_password) + serv_resp = opq.register(setup, cl_req, uid) + cl_fin = opq.register_client_finish(cl_state, admin_password, serv_resp) + pw_file = opq.register_finish(cl_fin) + birthdate = faker.date() + new_ud = data.ud.finished_userdata( + userdata, + callname=fname, + eduinstitution="TU Delft", + birthdate=birthdate, + show_age=True, + ) + + await data.user.UserOps.update_password_file(conn, uid, pw_file) + did_ups = await data.ud.upsert_userdata(conn, new_ud) + print(did_ups) + await data.signedup.delete_signedup(conn, email) + + async def run_function(func_name): module = sys.modules['__main__'] func = getattr(module, func_name)