Beispiel #1
0
def register(user: User):
    """
    Tries to insert a new user to the database, send verification mail to him
    """

    try:
        user.ts_registration = time()
        user.ts_last_login = time()
        user.enabled = True
        user.email_verified = False
        user.roles = [Roles.ROLE_USER]
        user.password = encrypt(user.password)

        insert(user)
    except IntegrityError as e:
        raise CustomError(
            message="Bu e-mail veya kullanici adi ile zaten bir kullanici var",
            status_code=400,
        )

    current_app.logger.debug('User with email {} registered'.format(
        user.email))

    send_verification_email(
        user.email,
        encode(user.jwt_payload(), current_app.config["JWT_SECRET"],
               current_app.config["JWT_TTL"]))
Beispiel #2
0
def register(user: User):
    """
    Tries to insert a new user to the database, send verification mail to him
    """

    try:
        user.ts_registration = time()
        user.ts_last_login = time()
        user.enabled = True
        user.email_verified = False
        user.roles = [Roles.ROLE_USER]
        user.password = encrypt(user.password)

        insert(user)
    except IntegrityError as e:
        raise CustomError(
            message="User already registered",
            status_code=400,
        )

    current_app.logger.debug('User with email {} registered'.format(
        user.email))