Example #1
0
 /**
  * login action
  *
  * @return void
  */
 public function Login()
 {
     //echo __METHOD__ .'-'. __LINE__ .' : BEGIN ===============<br />';
     $this->readInputRecord();
     try {
         $this->validateForm();
     } catch (Openbiz\Validation\Exception $e) {
         $this->processFormObjError($e->errors);
         return;
     }
     // get the username and password
     $this->username = Openbiz::$app->getClientProxy()->getFormInputs("username");
     $this->password = Openbiz::$app->getClientProxy()->getFormInputs("password");
     $this->smartcard = Openbiz::$app->getClientProxy()->getFormInputs("smartcard");
     if ($this->username == $this->getElement("username")->hint) {
         $this->username = null;
     }
     if ($this->password == $this->getElement("password")->hint) {
         $this->password = null;
     }
     $eventlog = Openbiz::getService(OPENBIZ_EVENTLOG_SERVICE);
     try {
         //echo __METHOD__ .'-'. __LINE__ .' : before authUser <br />';
         $authUser = $this->authUser();
         if ($authUser) {
             // after authenticate user: 1. init profile
             $profile = Openbiz::$app->initUserProfile($this->username);
             // after authenticate user: 2. insert login event
             $logComment = array($this->username, $_SERVER['REMOTE_ADDR']);
             $eventlog->log("LOGIN", "MSG_LOGIN_SUCCESSFUL", $logComment);
             // after authenticate user: 3. update login time in user record
             $updateLoginTimeStatus = $this->updateLoginTime();
             if (!$updateLoginTimeStatus) {
                 return false;
             }
             // after authenticate user: 3. update current theme and language
             $this->updateLanguage();
             $this->updateTheme();
             $redirectPage = OPENBIZ_APP_INDEX_URL . $profile['roleStartpage'][0];
             if (!$profile['roleStartpage'][0]) {
                 $errorMessage['password'] = $this->getMessage("PERM_INCORRECT");
                 $errorMessage['login_status'] = $this->getMessage("LOGIN_FAILED");
                 $this->processFormObjError($errorMessage);
                 return;
             }
             $cookies = Openbiz::$app->getClientProxy()->getFormInputs("session_timeout");
             if ($cookies) {
                 $password = $this->password;
                 $password = md5(md5($password . $this->username) . md5($profile['create_time']));
                 setcookie("SYSTEM_SESSION_USERNAME", $this->username, time() + (int) $cookies, "/");
                 setcookie("SYSTEM_SESSION_PASSWORD", $password, time() + (int) $cookies, "/");
             }
             //if its admin first time login, then show init system wizard
             $initLock = OPENBIZ_APP_PATH . '/files/initialize.lock';
             if ($profile['Id'] == 1 && !is_file($initLock)) {
                 $redirectPage = OPENBIZ_APP_INDEX_URL . "/system/initialize";
                 Openbiz::$app->getClientProxy()->ReDirectPage($redirectPage);
                 return true;
             }
             //if admin is not init profile yet
             $initLock = OPENBIZ_APP_PATH . '/files/initialize_profile.lock';
             if ($profile['Id'] == 1 && !is_file($initLock)) {
                 $redirectPage = OPENBIZ_APP_INDEX_URL . "/system/initialize_profile";
                 Openbiz::$app->getClientProxy()->ReDirectPage($redirectPage);
                 return true;
             }
             $profile = Openbiz::$app->getSessionContext()->getVar("_USER_PROFILE");
             if ($this->lastViewedPage != "") {
                 Openbiz::$app->getClientProxy()->redirectPage($this->lastViewedPage);
             } elseif ($profile['roleStartpage'][0]) {
                 Openbiz::$app->getClientProxy()->redirectPage($redirectPage);
             } else {
                 parent::processPostAction();
             }
             return true;
         } else {
             switch ($this->auth_method) {
                 case "smartcard":
                     $logComment = array($this->smartcard);
                     $eventlog->log("LOGIN", "MSG_SMARTCARD_LOGIN_FAILED", $logComment);
                     $errorMessage['smartcard'] = $this->getMessage("SMARTCARD_INCORRECT");
                     break;
                 default:
                     $logComment = array($this->username, $_SERVER['REMOTE_ADDR'], $this->password);
                     $eventlog->log("LOGIN", "MSG_LOGIN_FAILED", $logComment);
                     $errorMessage['password'] = $this->getMessage("PASSWORD_INCORRECT");
                     break;
             }
             $errorMessage['login_status'] = $this->getMessage("LOGIN_FAILED");
             $this->processFormObjError($errorMessage);
         }
     } catch (Exception $e) {
         $errorMessage['login_status'] = $this->getMessage("LOGIN_FAILED");
         $this->processFormObjError($errorMessage);
         //Openbiz::$app->getClientProxy()->showErrorMessage($e->getMessage());
     }
 }