Exemplo n.º 1
0
 public function validateUserId()
 {
     $userId = empty($_POST['userId']) ? '' : $_POST['userId'];
     $password = empty($_POST['password']) ? '' : $_POST['password'];
     //below we will call the controller class with userId and password
     $loginNHVBSRdb = new loginNHVBSRmodel();
     $personResult = $loginNHVBSRdb->getPersonDetails($userId, $password);
     //validates the userId and password entered by the user
     if (isset($personResult[0]) && $personResult != NULL) {
         $row = $personResult[0];
         $id = isset($row['ID']) ? $row['ID'] : '';
         $firstName = isset($row['firstName']) ? $row['firstName'] : '';
         $lastName = isset($row['lastName']) ? $row['lastName'] : '';
         $roleId = isset($row['roleID']) ? $row['roleID'] : '';
         $coordinatorID = isset($row['coordinatorID']) ? $row['coordinatorID'] : '';
         $activeUser = isset($row['activeUser']) ? $row['activeUser'] : '';
         //Checks to make sure that the user is active and able to log on
         if ($activeUser == 0) {
             $_SESSION['Login.Error'] = "Inactive User ";
             session_destroy();
             $this->registry->template->showLogon('session', 'LoginNHVBSR');
         } else {
             if (session_id() == PHP_SESSION_NONE) {
                 session_start();
             }
             $myCurrentDate = new DateTime("now", new DateTimeZone("America/New_York"));
             $timeStampKey = $myCurrentDate->format("Y-m-d-H-i-s");
             $sessionKey = $userId . $timeStampKey;
             $loginNHVBSRdb->setSessionDetail(session_id(), $sessionKey, "A");
             $_SESSION['IDKey'] = $sessionKey;
             $_SESSION['ID'] = (int) $id;
             $_SESSION['firstName'] = $firstName;
             $_SESSION['lastName'] = $lastName;
             $_SESSION['userName'] = $userId;
             $_SESSION['roleID'] = $roleId;
             $_SESSION['coordinatorID'] = $coordinatorID;
             //Before showing the user the main page, log the successful login event
             //appendLogEntry($timeStampKey . " > " . "User: "******" Logged in Successfully.");
             /*** set a template variable ***/
             $this->registry->template->welcome = 'Home';
             $this->registry->template->show('home', 'index');
         }
     } else {
         //Timestamp for logging purposes
         $myCurrentDate = new DateTime("now", new DateTimeZone("America/New_York"));
         $timeStampKey = $myCurrentDate->format("Y-m-d-H-i-s");
         //the logic to redirect to the login page with appropriate error message
         $_SESSION['Login.Error'] = "Invalid credentials ";
         session_destroy();
         //Before showing the user the login page again, log the unsuccessful login event
         ////appendLogEntry($timeStampKey . " > " . "User: "******" Login failed, Invalid Credentails");
         $this->registry->template->showLogon('session', 'LoginNHVBSR');
     }
 }