Example #1
0
 public function postUsers(Request $request)
 {
     $outputMessage = array();
     if ($request->has('action')) {
         switch ($request->get('action')) {
             case 'new':
                 $email = $request->get('email');
                 $password = $request->get('password');
                 $firstname = $request->get('firstname');
                 $lastname = $request->get('lastname');
                 //$groupName = $request->get('group');
                 $groupID = $request->get('group');
                 try {
                     $user = Sentry::register(array('email' => $email, 'first_name' => $firstname, 'last_name' => $lastname, 'password' => $password, 'activated' => true));
                     if ($user) {
                         $outputMessage[] = array("type" => "success", "msg" => "User created successfuly.");
                         if ($groupID == 1) {
                             $group = Sentry::findGroupByName('user');
                             $user->addGroup($group);
                             $outputMessage[] = array("type" => "alert", "msg" => "The God is unique.User is added to User group ;)");
                         } else {
                             $group = Sentry::findGroupById($groupID);
                             if ($group) {
                                 $user->addGroup($group);
                                 $outputMessage[] = array("type" => "success", "msg" => "User added to " . $group->name . " successfuly");
                             } else {
                                 $group = Sentry::findGroupByName('user');
                                 $user->addGroup($group);
                                 $outputMessage[] = array("type" => "alert", "msg" => "Group " . $group->name . " not found.User is added to User group ;)");
                             }
                         }
                     }
                 } catch (\Cartalyst\Sentry\Users\LoginRequiredException $e) {
                     $outputMessage[] = array("type" => "alert", "msg" => "Login field is required.");
                 } catch (\Cartalyst\Sentry\Users\PasswordRequiredException $e) {
                     $outputMessage[] = array("type" => "alert", "msg" => "Login field is required.");
                 } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
                     $outputMessage[] = array("type" => "alert", "msg" => "User with this login already exists.");
                 } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
                     $outputMessage[] = array("type" => "alert", "msg" => "Group was not found.");
                 }
                 break;
         }
     }
     $groups = Sentry::findAllGroups();
     $users = User::select(array('id', 'first_name', 'last_name', 'email'))->paginate(20);
     return view('admin.users')->with('users', $users)->with('groups', $groups)->with('messages', $outputMessage);
 }
 /**
  * @return \Illuminate\Http\JsonResponse
  */
 public function getIndex()
 {
     return Response::json(Sentry::findAllGroups());
 }
 /**
  * Return array of groups
  *
  * @return array
  */
 public function findAll()
 {
     return Sentry::findAllGroups();
 }