Пример #1
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     try {
         $email = $this->argument('email');
         $pass = $this->argument('password');
         $username = $this->argument('username');
         $groupName = $this->argument('group');
         $validator = new UserValidator(array('email' => $email, 'pass' => $pass, 'username' => $username), 'create');
         if (!$validator->passes()) {
             foreach ($validator->getErrors() as $key => $messages) {
                 $this->info(ucfirst($key) . ' :');
                 foreach ($messages as $message) {
                     $this->error($message);
                 }
             }
         } else {
             // Create the user
             $user = \Sentry::getUserProvider()->create(array('email' => $email, 'password' => $pass, 'username' => $username));
             $activationCode = $user->getActivationCode();
             $user->attemptActivation($activationCode);
             if ($groupName !== NULL) {
                 $group = \Sentry::getGroupProvider()->findByName($groupName);
                 $user->addGroup($group);
             }
             $this->info('User created with success');
         }
     } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
         $this->error('User already exists !');
     } catch (\Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
         $this->error('Group ' . $groupName . ' does not exists !');
     }
 }
Пример #2
0
 /**
  * Login post authentication
  */
 public function postLogin()
 {
     $credentials = array('username' => Input::get('username'), 'password' => Input::get('password'));
     try {
         $validator = new UserValidator(Input::all(), 'login');
         if (!$validator->passes()) {
             return View::make(Config::get('core::views.login'), array('errorMessages' => $validator->getErrors()));
             //return Response::json(array('logged' => false, 'errorMessages' => $validator->getErrors()));
         }
         // authenticate user
         Sentry::authenticate($credentials, Input::get('remember'));
     } catch (\Cartalyst\Sentry\Throttling\UserBannedException $e) {
         return View::make(Config::get('core::views.login'), array('errorMessages' => trans('core::all.messages.banned'), 'credentials' => $credentials));
         //return Response::json(array('logged' => false, 'errorMessage' => trans('core::all.messages.banned'), 'errorType' => 'danger'));
     } catch (\Cartalyst\Sentry\Users\UserNotActivatedException $e) {
         return View::make(Config::get('core::views.login'), array('errorMessages' => 'Sorry, this user is not active.', 'credentials' => $credentials));
     } catch (\RuntimeException $e) {
         return View::make(Config::get('core::views.login'), array('errorMessages' => $e->getMessage(), 'credentials' => $credentials));
         //return Response::json(array('logged' => false, 'errorMessage' => trans('core::all.messages.login-failed'), 'errorType' => 'danger'));
     }
     return Redirect::route("indexDashboard");
     //return Response::json(array('logged' => true));
 }
Пример #3
0
 /**
  * Update user account
  * @param int $userId
  * @return Response
  */
 public function putShow($userId)
 {
     \Core\Services\FilterData::removeHtmlExclude();
     try {
         $validator = new UserValidator(Input::all(), 'update');
         if (!$validator->passes()) {
             return Response::json(array('userUpdated' => false, 'errorMessages' => $validator->getErrors()));
         }
         $permissionsValues = Input::get('permission');
         $permissions = $this->_formatPermissions($permissionsValues);
         // Find the user using the user id
         $user = Sentry::getUserProvider()->findById($userId);
         $user->username = Input::get('username');
         $user->email = Input::get('email');
         $user->last_name = Input::get('last_name');
         $user->first_name = Input::get('first_name');
         $user->middle_name = Input::get('middle_name');
         $user->permissions = $permissions;
         $user->branch_id = Input::get('branch_id');
         $user->arranger_number = Input::get('arranger_number');
         $permissions = empty($permissions) ? '' : json_encode($permissions);
         // delete permissions in db
         DB::table('users')->where('id', $userId)->update(array('permissions' => $permissions));
         $pass = Input::get('pass');
         if (!empty($pass)) {
             $user->password = $pass;
         }
         // Update the user
         if ($user->save()) {
             // if the user has permission to update
             $banned = Input::get('banned');
             if (isset($banned) && Sentry::getUser()->getId() !== $user->getId()) {
                 $this->_banUser($userId, $banned);
             }
             if (Sentry::getUser()->hasAccess('user-group-management')) {
                 $groups = Input::get('groups') === null ? array() : Input::get('groups');
                 $userGroups = $user->getGroups()->toArray();
                 foreach ($userGroups as $group) {
                     if (!in_array($group['id'], $groups)) {
                         $group = Sentry::getGroupProvider()->findById($group['id']);
                         $user->removeGroup($group);
                     }
                 }
                 if (isset($groups) && is_array($groups)) {
                     foreach ($groups as $groupId) {
                         $group = Sentry::getGroupProvider()->findById($groupId);
                         $user->addGroup($group);
                     }
                 }
             }
             $message = array('userUpdated' => true, 'message' => trans('core::users.messages.update-success'), 'messageType' => 'success', 'redirectUrl' => URL::route('listUsers'));
             \Session::put('message', $message);
             return Response::json($message);
         } else {
             return Response::json(array('userUpdated' => false, 'message' => trans('core::users.messages.update-fail'), 'messageType' => 'danger'));
         }
     } catch (\Cartalyst\Sentry\Users\UserExistsException $e) {
         return Response::json(array('userUpdated' => false, 'message' => trans('core::users.messages.user-email-exists'), 'messageType' => 'danger'));
     } catch (\Exception $e) {
         return Response::json(array('userUpdated' => false, 'message' => trans('core::users.messages.user-name-exists'), 'messageType' => 'danger'));
     }
 }