/** * Mark role as default. * * @author Casper Rasmussen <*****@*****.**> * * @param int $id * @return \Illuminate\Http\RedirectResponse */ public function setDefault($id) { if (Gate::denies('backend-developer')) { abort(403); } // Retrieve role by ID $role = $this->roleRepository->getById($id); if (empty($role)) { return redirect()->route('nodes.backend.users.roles')->with('error', 'Role does not exist'); } // Make sure the role we're about to mark as default // isn't already the default role if ($role->isDefault()) { return redirect()->route('nodes.backend.users.roles')->with('warning', 'Role is already default'); } try { $this->roleRepository->setDefault($role); return redirect()->route('nodes.backend.users.roles')->with('success', 'Role was successfully set default'); } catch (Exception $e) { return redirect()->route('nodes.backend.users.roles')->with('error', 'Could not set the role default'); } }
/** * @author Casper Rasmussen <*****@*****.**> * @param \Nodes\Backend\Models\User\Validation\UserValidator $userValidator * @return \Illuminate\Http\RedirectResponse */ public function update(UserValidator $userValidator) { // Retrieve posted data $data = Request::all(); // Retrieve user to update $user = $this->userRepository->getById($data['id']); if (empty($user)) { return redirect()->route('nodes.backend.users')->with('error', 'User was not found'); } // Make sure user has access to edit this user if (Gate::denies('backend-edit-backend-user', $user)) { abort(403); } // Validate user if (!$userValidator->with($data)->validate()) { return redirect()->back()->withInput()->with(['error' => $userValidator->errorsBag()]); } // Retrieve available roles for users user-role, // and make sure that the selected role is within // the access level of the authed user. // // Otherwise remove "user_role" from the array of data // we're about to update on the user $roles = $this->roleRepository->getListUserLevel(); if (empty($roles[$data['user_role']])) { unset($data['user_role']); } // Update user and redirect try { $this->userRepository->updateUser($user, $data); // Only admins have access to list of users, users need to go to return Gate::allows('backend-admin') ? redirect()->route('nodes.backend.users')->with('success', 'User was successfully updated') : redirect()->route(config('nodes.backend.auth.routes.success'))->with('success', 'User was successfully updated'); } catch (Exception $e) { return redirect()->back()->withInput()->with('error', 'Could not update user'); } }