Пример #1
0
def insert_account(account_args):
    try:
        inserted_account = Account(**account_args)
        db.session.add(inserted_account)
        db.session.commit()
        return inserted_account.full_view()
    except IntegrityError:
        db.session.rollback()
        return None
    except Exception:
        db.session.rollback()
        raise
Пример #2
0
def signup(account_info):
    account = AccountChecker.__on_creation__(account_info)
    accountExists = Account.get_account_by_email(account["email"]) is not None
    if accountExists:
        return {
            "message": f"This email already exists: {account['email']}"
        }, 409
    account["id"] = str(uuid.uuid4())
    account["date_created"] = datetime.today().strftime("%Y-%m-%d")
    account["password"] = _encrypt(account["password"])
    return {"account": dal.insert_account(account)}, 201
Пример #3
0
def login(account_info):
    checkedAccount = AccountChecker.__on_login__(account_info)
    account = Account.get_account_by_email(checkedAccount["email"])
    if not account:
        return {"message": "Email not found in the database"}, 404

    if not _verify(checkedAccount["password"], account.password):
        return {
            "message": "Incorrect password provided, please try again"
        }, 401

    token = account.encode_auth_token(account.id)
    return {"message": account.full_view(), "token": token}, 201
Пример #4
0
def delete_account(account_id):
    # NEED TO DELETE REFERENCES TO ACCOUNT FIRST !
    account = Account.get_account_by_id(account_id)
    db.session.delete(account)
    db.session.commit()
    return True
Пример #5
0
def update_account(account_id, account_patch):
    account = Account.get_account_by_id(account_id)
    for key, value in account_patch.items():
        setattr(account, key, value)
    db.session.commit()
    return account.full_view()
Пример #6
0
def get_account_by_id(account_id):
    account = Account.get_account_by_id(account_id)
    return account.full_view()
Пример #7
0
def get_account(account_id):
    account = Account.get_account_by_id(account_id)
    return None if account is None else account.full_view()
Пример #8
0
def get_current_account(token):
    accountIdFromToken = verify_token(token)
    account = Account.get_account_by_id(accountIdFromToken).full_view()
    return {"account": account}, 200