Ejemplo n.º 1
0
def create_student_user(index=0):
    return User.create(  # NOQA: S106
        username=f'student-{index}',
        fullname='Astudent',
        mail_address=f'so-student-{index}@mail.com',
        password='******',
        role=Role.get_student_role(),
    )
Ejemplo n.º 2
0
def confirm_email(user_id: int, token: str):
    user = User.get_or_none(User.id == user_id)
    if user is None:
        return fail(404, 'The authentication code is invalid.')

    if not user.role.is_unverified:
        return fail(403, 'User has been already confirmed.')

    try:
        SERIALIZER.loads(
            token, salt=retrieve_salt(user), max_age=CONFIRMATION_TIME,
        )

    except SignatureExpired:
        send_confirmation_mail(user)
        return redirect(url_for(
            'login', login_message=(
                _(
                    'The confirmation link is expired, new link has been '
                    'sent to your email',
                ),
            ),
        ))
    except BadSignature:
        return fail(404, 'The authentication code is invalid.')

    else:
        update = User.update(
            role=Role.get_student_role(),
        ).where(User.username == user.username)
        update.execute()
        return redirect(url_for(
            'login', login_message=(
                _(
                    'Your user has been successfully confirmed, '
                    'you can now login',
                ),
            ),
        ))