Beispiel #1
0
def edit_user(request, user_id):
    the_user = get_object_or_404(User, pk=int(user_id))
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        if the_user.has_usable_password:
            form = forms.EditUserForm(request.POST)
        else:
            form = forms.EditLDAPUserForm(request.POST)
        if form.is_valid():
            user = form.save()
            user_profile = UserProfile.objects.get(user=the_user)
            user_profile.level = request.POST['user_level']
            user_profile.save()
            if user_profile.level != 'GA':
                user.is_staff = False
                user.save()
            return redirect('manage_users')
    else:
        if the_user.has_usable_password:
            form = forms.EditUserForm({
                'user_level': the_user.userprofile.level,
                'user_id': the_user.id
            })
        else:
            form = forms.EditLDAPUserForm({
                'user_level': the_user.userprofile.level,
                'user_id': the_user.id
            })

    c = {'form': form, 'the_user': the_user}

    return render(request, 'forms/edit_user.html', c)
Beispiel #2
0
def update_user(username):
    user = running_context.user_datastore.get_user(username)
    if user:
        form = forms.EditUserForm(request.form)
        if form.validate():
            if form.password:
                user.password = encrypt_password(form.password.data)
                running_context.db.session.commit()
            if form.role.data:
                user.set_roles(form.role.data)

        return json.dumps(user.display())
    else:
        return json.dumps({"status": "could not edit user"})
Beispiel #3
0
 def __func():
     user = running_context.user_datastore.get_user(user_name)
     if user:
         form = forms.EditUserForm(request.form)
         if form.password:
             user.password = encrypt_password(form.password.data)
             running_context.db.session.commit()
         if form.role.data:
             user.set_roles(form.role.data)
         current_app.logger.info('Updated user {0}. Roles: {1}'.format(user_name, form.role.data))
         return user.display(), SUCCESS
     else:
         current_app.logger.error('Could not edit user {0}. User does not exist.'.format(user_name))
         return {"error": 'User does not exist.'.format(user_name)}, OBJECT_DNE_ERROR