Esempio n. 1
0
def edit_user(user_id):
    user = users_service.get_by_id(user_id)

    # Make sure a user with this id actually exists
    if user is not None:
        form = UserForm(obj=user)

        # Check if we're submitting a form or not
        if form.validate_on_submit():
            # Only need to update the password if a new password was entered into the form
            if form.password.data:
                user.set_password(form.password.data)

            user.username = form.username.data
            user.first_name = form.first_name.data
            user.last_name = form.last_name.data
            user.email = form.email.data
            user.permissions = form.permissions.data
            user.save()

            flash(u'Successfully updated user.', 'success')
            return redirect('admin/users/' + str(user.user_id))
        else:
            templates = items_service.get_templates_by_user_id(user.user_id)
            services = items_service.get_services_by_user_id(user.user_id)
            return render_template('admin/edit_user.html',
                                   user=user,
                                   form=form,
                                   templates=templates,
                                   services=services)
    else:
        return redirect('/')
Esempio n. 2
0
def edit_user(user_id):
    user = users_service.get_by_id(user_id)

    # Make sure a user with this id actually exists
    if user is not None:
        form = UserForm(obj=user)

        # Check if we're submitting a form or not
        if form.validate_on_submit():
            # Only need to update the password if a new password was entered into the form
            if form.password.data:
                user.set_password(form.password.data)

            user.username = form.username.data
            user.first_name = form.first_name.data
            user.last_name = form.last_name.data
            user.email = form.email.data
            user.permissions = form.permissions.data
            user.save()

            flash(u'Successfully updated user.', 'success')
            return redirect('admin/users/' + str(user.user_id))
        else:
            templates = items_service.get_templates_by_user_id(user.user_id)
            services = items_service.get_services_by_user_id(user.user_id)
            return render_template('admin/edit_user.html',
                                   user=user,
                                   form=form,
                                   templates=templates,
                                   services=services)
    else:
        return redirect('/')
Esempio n. 3
0
def add_user():
    add_user_form = UserForm()
    if add_user_form.validate_on_submit():
        if users_service.exists(add_user_form.username.data):
            flash(u'Username already exists.', 'error')
        else:
            password = add_user_form.password.data.encode('utf-8')
            hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
            new_user = User(username=add_user_form.username.data,
                            password=hashed_password,
                            first_name=add_user_form.first_name.data,
                            last_name=add_user_form.last_name.data,
                            email=add_user_form.email.data,
                            permissions=add_user_form.permissions.data)

            new_user.create()
            flash(u'Successfully added user.', 'success')

        return redirect('admin/users/add')
    else:
        return render_template('admin/add_user.html', form=add_user_form)
Esempio n. 4
0
def add_user():
    add_user_form = UserForm()
    if add_user_form.validate_on_submit():
        if users_service.exists(add_user_form.username.data):
            flash(u'Username already exists.', 'error')
        else:
            password = add_user_form.password.data.encode('utf-8')
            hashed_password = bcrypt.hashpw(password, bcrypt.gensalt())
            new_user = User(username=add_user_form.username.data,
                            password=hashed_password,
                            first_name=add_user_form.first_name.data,
                            last_name=add_user_form.last_name.data,
                            email=add_user_form.email.data,
                            permissions=add_user_form.permissions.data)

            new_user.create()
            flash(u'Successfully added user.', 'success')

        return redirect('admin/users/add')
    else:
        return render_template('admin/add_user.html', form=add_user_form)