Ejemplo n.º 1
0
 public function findAllUsersInGroup($group)
 {
     // Get the user_ids that have membership to the group
     $pivot_info = \GroupUserPivot::where('group_id', '=', $group->id)->get();
     // Populate a array with the User objects that are in
     // the group
     $users = array();
     foreach ($pivot_info as $pivot) {
         // Find a user in the pivot with the id
         $user = \User::find($pivot->user_id);
         // If we found a user, add it to the array
         if ($user) {
             array_push($users, \User::find($pivot->user_id));
         }
     }
     return $users;
 }
Ejemplo n.º 2
0
 public function postUpdateUser()
 {
     // Find the user
     $user = Auth::findUserById(Input::get('userID'));
     // Find the administrators group
     $admin_group = Auth::findGroupByName('Administrators');
     // ... and check that it exists
     if (!$admin_group) {
         return Redirect::back()->withInput()->withErrors('Administrators group could not be found');
     }
     $user->email = Input::get('email');
     $user->tsid = Input::get('tsid');
     if (Input::get('username') != '') {
         $user->username = Input::get('username');
     }
     if (Input::get('password') != '') {
         $user->password = Hash::make(Input::get('password'));
     }
     $groups = Input::except('_token', 'username', 'password', 'first_name', 'last_name', 'userID', 'email', 'tsid');
     // Delete all the permissions the user has now
     \GroupUserPivot::where('user_id', '=', $user->id)->delete();
     // Restore the permissions.
     //
     // NB Todo. Check that we not revoking 'Administrors' access from
     // the site admin
     foreach ($groups as $group => $value) {
         $thisGroup = Auth::findGroupByName(str_replace("_", " ", $group));
         Auth::addUserToGroup($user, $thisGroup);
     }
     if ($user->save()) {
         return Redirect::action('UserController@getDetail', array($user->getKey()))->with('success', 'User has been updated');
     } else {
         return Redirect::back()->withInput()->withErrors('Error updating user');
     }
 }