Esempio n. 1
0
def insert(user):
    """Create a new request

    Args:

        user: Django User

    Returns:

        New account request
    """
    try:
        # check if a user with the same username exists
        _get_user_by_username(user.username)
        raise ApiError("A user with the same username already exists.")
    except ObjectDoesNotExist:
        user.save()

        # Create the account request and save it
        account_request = AccountRequest(
            username=user.username,
            first_name=user.first_name,
            last_name=user.last_name,
            email=user.email,
        )

        context = {"URI": SERVER_URI}
        template_path = "core_website_app/admin/email/request_account_for_admin.html"
        send_mail_api.send_mail_to_administrators(
            subject="New Account Request",
            path_to_template=template_path,
            context=context,
        )
        return account_request.save()
Esempio n. 2
0
def insert(user):
    """
        Create a new request

        Parameters:
            user:

        Returns: new account request
    """
    try:
        # check if a user with the same username exists
        _get_user_by_username(user.username)
        raise ApiError('A user with the same username already exists.')
    except ObjectDoesNotExist:
        user.save()

        # Create the account request and save it
        account_request = AccountRequest(username=user.username)
        return account_request.save()