/**
  * Restricts deleting employees when there is only one admin
  * and the admin is assigned to an employee to be deleted
  */
 protected function _checkLastAdminDeletion($empNumbers)
 {
     $searchClues['userType'] = SystemUser::ADMIN_USER_ROLE_ID;
     $searchClues['status'] = SystemUser::ENABLED;
     $systemUserService = new SystemUserService();
     $adminUsers = $systemUserService->searchSystemUsers($searchClues);
     $adminEmpNumbers = array();
     $defaultAdminExists = false;
     foreach ($adminUsers as $adminUser) {
         $adminEmpNumber = $adminUser->getEmployee()->getEmpNumber();
         if (!empty($adminEmpNumber)) {
             $adminEmpNumbers[] = $adminEmpNumber;
         } else {
             $defaultAdminExists = true;
         }
     }
     if ($defaultAdminExists) {
         return;
     }
     $adminUserDiff = array_diff($adminEmpNumbers, $empNumbers);
     if (empty($adminUserDiff)) {
         $this->getUser()->setFlash('templateMessage', array('failure', __('Failed to Delete: At Least One Admin Should Exist')));
         $this->redirect('pim/viewEmployeeList');
     }
 }
 public function save()
 {
     $userId = sfContext::getInstance()->getUser()->getAttribute('user')->getUserId();
     $systemUserService = new SystemUserService();
     $posts = $this->getValues();
     $systemUserService->updatePassword($userId, $posts['newPassword']);
     //save secondary password
     $formExtension = PluginFormMergeManager::instance();
     $formExtension->saveMergeForms($this, 'changeUserPassword', 'ChangeUserPasswordForm');
 }
 /**
  *
  * @param <type> $request
  * @return <type>
  */
 public function execute($request)
 {
     $this->setLayout(false);
     sfConfig::set('sf_web_debug', false);
     sfConfig::set('sf_debug', false);
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     }
     $systemUser = $request->getParameter('systemUser');
     $userId = $request->getParameter('user_id');
     $systemUserService = new SystemUserService();
     $user = $systemUserService->isExistingSystemUser($systemUser['userName'], $userId);
     $isExisting = $user instanceof SystemUser ? false : true;
     return $this->renderText(json_encode($isExisting));
 }
Example #4
0
 public function validateRequest(sfWebRequest $request)
 {
     $server = $this->getOAuthServer();
     $oauthRequest = $this->getOAuthRequest();
     $oauthResponse = $this->getOAuthResponse();
     if (!$server->verifyResourceRequest($oauthRequest, $oauthResponse)) {
         $server->getResponse()->send();
         throw new sfStopException();
     }
     $tokenData = $server->getAccessTokenData($oauthRequest, $oauthResponse);
     $userId = $tokenData['user_id'];
     $userService = new SystemUserService();
     $user = $userService->getSystemUser($userId);
     $authService = new AuthService();
     $authService->setLoggedInUser($user);
     $this->getAuthenticationService()->setCredentialsForUser($user, array());
 }
 public function execute($request)
 {
     $this->form = new ChangeUserPasswordForm();
     $this->userId = $this->getUser()->getAttribute('user')->getUserId();
     $systemUserService = new SystemUserService();
     $systemUser = $systemUserService->getSystemUser($this->userId);
     $this->username = $systemUser->getName();
     if ($this->getUser()->hasFlash('templateMessage')) {
         $this->templateMessage = $this->getUser()->getFlash('templateMessage');
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()));
         if ($this->form->isValid()) {
             if (!$systemUserService->isCurrentPassword($this->userId, $this->form->getValue('currentPassword'))) {
                 $this->getUser()->setFlash('templateMessage', array('WARNING', __('Current Password Is Wrong')));
                 $this->redirect('admin/changeUserPassword');
             } else {
                 $this->form->save();
                 $this->getUser()->setFlash('templateMessage', array('SUCCESS', __('Successfully Changed')));
                 $this->redirect('admin/changeUserPassword');
             }
         }
     }
 }