Beispiel #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
Beispiel #2
0
def add_remove_check(email, user_group_name):
    """
    Check if the user is existed in a given server group
    """
    user = maybe_get_user_by_email(email)
    user_group = get_user_group_by_name(user_group_name)

    users = user_group.get_users()

    if user in users:
        return True
    else:
        return False
Beispiel #3
0
def remove_user_from_user_group(email, user_group_name):
    user = maybe_get_user_by_email(email)
    if not user:
        raise ValueError("No user found for email: %s" % email)

    user_group = get_user_group_by_name(user_group_name)
    if not user_group:
        raise ValueError("No user group found for name: %s" % user_group_name)

    if add_remove_check(email, user_group_name):
        #not sure if this is correct?
        user_group.user_list.remove(user)
    else:
        print("The user: %s is not found in the user group: %s" % (email, user_group_name))
Beispiel #4
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
Beispiel #5
0
def login():
    if request.method == "POST":
        email = request.form.get('email')
        password = request.form.get('password')
        # Get the user
        user = auth_utils.maybe_get_user_by_email(email)
        if user:
            # If the user exists, check their password
            authenticated = user.check_password(password)
            if authenticated:
                # User is legit, give them a session.
                login_user(user)
                return redirect(url_for('index'))

        # In case any of the conditionals fail, show the error on the login page.
        g.incorrect = True
        g.email = email
    return render_template('login.html')
Beispiel #6
0
def login():
    if request.method == "POST":
        email = request.form.get('email')
        password = request.form.get('password')
        # Get the user
        user = auth_utils.maybe_get_user_by_email(email)
        if user:
            # If the user exists, check their password
            authenticated = user.check_password(password)
            if authenticated:
                # User is legit, give them a session.
                login_user(user)

                redirect_location = request.args.get('redirect')
                if redirect_location:
                    return redirect(urllib.unquote(redirect_location))
                return redirect(url_for('index'))

        # In case any of the conditionals fail, show the error on the login page.
        g.incorrect = True
        g.email = email
    return render_template('login.html')