/** * User update form processing page. * * @param int * @return Redirect */ public function postEdit($userId = null) { try { // Get the user information $user = Sentry::getUserProvider()->findById($userId); } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { // Redirect to the user management page return Rediret::to('admin/users')->with('error', Lang::get('admin/users/messages.does_not_exist')); } // Declare the rules for the form validation $rules = array('first_name' => 'required|min:3', 'last_name' => 'required|min:3', 'email' => 'required|email|unique:users,email,' . $user->email . ',email'); // Do we want to update the user password? if (Input::get('password')) { $rules['password'] = '******'; $rules['password_confirmation'] = 'required|between:3,32'; } // Validate the inputs $validator = Validator::make(Input::all(), $rules); // Check if the form validates with success if ($validator->passes()) { try { // Update the user $user->first_name = Input::get('first_name'); $user->last_name = Input::get('last_name'); $user->email = Input::get('email'); $user->activated = Input::get('activated', $user->activated); $user->permissions = Input::get('permissions'); // Do we want to update the user password? if ($password = Input::get('password')) { $user->password = $password; } // Get the current user groups $userGroups = $user->groups()->lists('group_id'); // Get the selected groups $selectedGroups = Input::get('groups', array()); // Groups comparison between the groups the user currently // have and the groups the user wish to have. $groupsToAdd = array_diff($selectedGroups, $userGroups); $groupsToRemove = array_diff($userGroups, $selectedGroups); // Assign the user to groups foreach ($groupsToAdd as $groupId) { $group = Sentry::getGroupProvider()->findById($groupId); $user->addGroup($group); } // Remove the user from groups foreach ($groupsToRemove as $groupId) { $group = Sentry::getGroupProvider()->findById($groupId); $user->removeGroup($group); } // Was the user updated? if ($user->save()) { // Redirect to the user page return Redirect::to('admin/users/' . $userId . '/edit')->with('success', Lang::get('admin/users/messages.update.success')); } else { // Redirect to the user page return Redirect::to('admin/users/' . $userId . '/edit')->with('error', Lang::get('admin/users/messages.update.error')); } } catch (Cartalyst\Sentry\Users\LoginRequiredException $e) { $error = Lang::get('admin/users/messages.login_required'); } // Redirect to the user page return Redirect::to('admin/users/' . $userId . '/edit')->withInput()->with('error', $error); } // Form validation failed return Redirect::to('admin/users/' . $userId . '/edit')->withInput()->withErrors($validator); }
/** * Group update form processing page. * * @param int $groupId * @return Redirect */ public function postEdit($groupId = null) { try { // Get the group information $group = Sentry::getGroupProvider()->findById($groupId); } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) { // Redirect to the groups management page return Rediret::to('admin/groups')->with('error', Lang::get('admin/groups/messages.does_not_exist')); } // Declare the rules for the form validation $rules = array('name' => 'required'); // Validate the inputs $validator = Validator::make(Input::all(), $rules); // Check if the form validates with success if ($validator->passes()) { try { // Update the group data $group->name = Input::get('name'); $group->permissions = Input::get('permissions'); // Was the group updated? if ($group->save()) { // Redirect to the group page return Redirect::to('admin/groups/' . $groupId . '/edit')->with('success', Lang::get('admin/groups/messages.update.success')); } else { // Redirect to the group page return Redirect::to('admin/groups/' . $groupId . '/edit')->with('error', Lang::get('admin/groups/messages.update.error')); } } catch (Cartalyst\Sentry\Groups\NameRequiredException $e) { $error = Lang::get('admin/group/messages.name_required'); } // Redirect to the group page return Redirect::to('admin/groups/' . $groupId . '/edit')->withInput()->with('error', $error); } // Form validation failed return Redirect::to('admin/groups/' . $groupId . '/edit')->withInput()->withErrors($validator); }