예제 #1
0
 /**
  * Group update form processing page.
  *
  * @param  int $id
  * @return Redirect
  */
 public function update($id = null, GroupRequest $request)
 {
     try {
         // Get the group information
         $group = Sentinel::findRoleById($id);
     } catch (GroupNotFoundException $e) {
         // Redirect to the groups management page
         return Rediret::route('groups')->with('error', Lang::get('groups/message.group_not_found', compact('id')));
     }
     // Update the group data
     $group->name = Input::get('name');
     // Was the group updated?
     if ($group->save()) {
         // Redirect to the group page
         return Redirect::route('groups')->with('success', Lang::get('groups/message.success.update'));
     } else {
         // Redirect to the group page
         return Redirect::route('update/group', $id)->with('error', Lang::get('groups/message.error.update'));
     }
 }
예제 #2
0
 /**
  * Role update form processing page.
  *
  * @param  int $id
  * @return Redirect
  */
 public function update($id = null, RoleRequest $request)
 {
     try {
         // Get the role information
         $role = Sentinel::findRoleById($id);
     } catch (RoleNotFoundException $e) {
         // Redirect to the roles management page
         return Rediret::route('roles')->with('error', Lang::get('roles/message.role_not_found', compact('id')));
     }
     // Update the role data
     $role->name = Input::get('name');
     // Was the role updated?
     if ($role->save()) {
         // Redirect to the role page
         return Redirect::route('roles')->with('success', Lang::get('roles/message.success.update'));
     } else {
         // Redirect to the role page
         return Redirect::route('update/role', $id)->with('error', Lang::get('roles/message.error.update'));
     }
 }
예제 #3
0
 /**
  * Group update form processing page.
  *
  * @param  int  $id
  * @return Redirect
  */
 public function postEdit($id = null)
 {
     // We need to reverse the UI specific logic for our
     // permissions here before we update the group.
     $permissions = Input::get('permissions', array());
     $this->decodePermissions($permissions);
     app('request')->request->set('permissions', $permissions);
     try {
         // Get the group information
         $group = Sentry::getGroupProvider()->findById($id);
     } catch (GroupNotFoundException $e) {
         // Redirect to the groups management page
         return Rediret::route('groups')->with('error', Lang::get('admin/groups/message.group_not_found', compact('id')));
     }
     // Declare the rules for the form validation
     $rules = array('name' => 'required|alpha_space|min:2');
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $rules);
     // If validation fails, we'll exit the operation now.
     if ($validator->fails()) {
         // Ooops.. something went wrong
         return Redirect::back()->withInput()->withErrors($validator);
     }
     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::route('update/group', $id)->with('success', Lang::get('admin/groups/message.success.update'));
         } else {
             // Redirect to the group page
             return Redirect::route('update/group', $id)->with('error', Lang::get('admin/groups/message.error.update'));
         }
     } catch (NameRequiredException $e) {
         $error = Lang::get('admin/group/message.group_name_required');
     }
     // Redirect to the group page
     return Redirect::route('update/group', $id)->withInput()->with('error', $error);
 }
예제 #4
0
 /**
  * Group update form processing page.
  *
  * @param  int      $id
  * @return Redirect
  */
 public function postEdit($id = null)
 {
     try {
         // Get the group information
         $group = Sentinel::findRoleById($id);
     } catch (GroupNotFoundException $e) {
         // Redirect to the groups management page
         return Rediret::route('groups')->with('error', Lang::get('groups/message.group_not_found', compact('id')));
     }
     // Declare the rules for the form validation
     $rules = array('name' => 'required');
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $rules);
     // If validation fails, we'll exit the operation now.
     if ($validator->fails()) {
         // Ooops.. something went wrong
         return Redirect::back()->withInput()->withErrors($validator);
     }
     // Update the group data
     $group->name = Input::get('name');
     // Was the group updated?
     if ($group->save()) {
         // Redirect to the group page
         return Redirect::route('groups')->with('success', Lang::get('groups/message.success.update'));
     } else {
         // Redirect to the group page
         return Redirect::route('update/group', $id)->with('error', Lang::get('groups/message.error.update'));
     }
 }
 /**
  * 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);
 }