Exemple #1
0
def create_user(operator,
                first_name,
                last_name,
                email,
                username,
                password,
                is_admin=False,
                **kwargs):
    """
    Create a new user in the database with the given values.
    """
    # TODO Auditable stuff
    existing_user = maybe_get_user_by_email(email)
    if existing_user:
        raise UserAlreadyExistsError("A user with that email address exists.")
    name = "%s %s" % (first_name, last_name)
    lower_name = name.lower()
    user = User(first_name=first_name,
                last_name=last_name,
                email=email,
                username=username,
                lowercase_display_name=lower_name,
                is_admin=is_admin)
    user.password = User.encode_password(password)
    user.save()
    activity_log.log_user_created(user, operator)
    return user
    def post(cls):
        try:
            data = USER_SIGNUP_SCHEMA.load(request.get_json())
            user = User(**data)
            user.hash_password()
            user.save()
            sendOtp(user.username, user.phone_number, user.id)

            return {'Message': 'User Created'}, 200
        except ValidationError as e:
            print(e)
            return check_error(str(e))
        except NotUniqueError:
            return {'Message': 'User already exist'}, 500
Exemple #3
0
def create_user(operator, first_name, last_name, email, username, password, **kwargs):
    """
    Create a new user in the database with the given values.
    """
    # TODO Auditable stuff
    existing_user = maybe_get_user_by_email(email)
    if existing_user:
        raise UserAlreadyExistsError("A user with that email address exists.")
    name = "%s %s" % (first_name, last_name)
    lower_name = name.lower()
    user = User(first_name=first_name, last_name=last_name, email=email, username=username,
                lowercase_display_name=lower_name)
    user.password = User.encode_password(password)
    user.save()
    activity_log.log_user_created(user, operator)
    return user