def view(request, login=None): userapi = UserAPI() user = user_utils.get_user(login) if request.method == 'POST': form = UserForm(request.POST, user=user) if form.is_valid(): success = True delta = dict(name=form.cleaned_data['name']) if form.cleaned_data['password']: delta['password'] = form.cleaned_data['password'] try: userapi.update(login, delta) messages.success(request, "Updated user information for %s" % user['name']) except ServerRequestError, err: success = False messages.error(request, "Failed to update user information for %s: %s" % (user['name'], err[1])) roleapi = RoleAPI() orig = [r for r in form.cleaned_data['orig_roles'].splitlines() if r] new = [r for r in form.cleaned_data['roles'] if r] to_remove = [r for r in orig if r not in new] for role in to_remove: try: roleapi.remove_user(role, login) messages.success(request, "Removed role %s from user %s" % (role, user['name'])) except ServerRequestError, err: success = False messages.error(request, "Failed to remove role %s from user %s: %s" % (role, user['name'], err[1])) to_add = [r for r in new if r not in orig] for role in to_add: try: roleapi.add_user(role, login) messages.success(request, "Added role %s to user %s" % (role, user['name'])) except ServerRequestError, err: success = False messages.error(request, "Failed to add role %s to user %s: %s" % (role, user['name'], err[1]))
bundle.write(cert) self.server = get_pulp_server(new=True) self.server.set_ssl_credentials(bundle.crtpath()) udata = self.userapi.user(username) logger.info("%s logged in successfully" % username) except server.ServerRequestError, err: logger.warning("Login failure for %s: %s" % (username, err[1])) return None except Exception, err: logger.warning(traceback.format_exc()) return None # we got the user data above with a direct UserAPI call so # that we could catch errors and tell if the login was # successful. now let's get better data using user_utils udata = user_utils.get_user(username) user, created = User.objects.get_or_create(username=username) if created: logger.info("Created new user object for %s", username) user.set_unusable_password() user.is_superuser = user_utils.is_superuser(username) user.first_name = udata['name'].split()[0] user.last_name = " ".join(udata['name'].split()[1:]) user.save() return user def get_user(self, user_id): """ get a user object representing a user """ try: