Esempio n. 1
0
 public function change()
 {
     if (!isset($_SESSION['UserID'])) {
         redirect('Login/logout');
     }
     //Create new user and load its data
     $user = new User_model();
     if (!$user->loadPropertiesFromPrimaryKey($_SESSION['UserID'])) {
         redirect('Login/logout');
     }
     //If user did not load, logout the session
     if ($user->isGuest()) {
         redirect('Mainpage');
     }
     //If not a student, redirect to mainpage
     $oldpw = $this->input->post('oldpw');
     $newpw = $this->input->post('newpw');
     $newpw2 = $this->input->post('newpw2');
     if (!$user->authenticate($oldpw)) {
         $this->load->view('changePassword', array('user' => $user, 'error' => TRUE));
     } elseif ($newpw != $newpw2) {
         $this->load->view('changePassword', array('user' => $user, 'error2' => TRUE));
     } elseif (strpbrk($newpw, '!@#$%&*-+=1234567890') === FALSE || strlen($newpw) < 8) {
         $this->load->view('changePassword', array('user' => $user, 'error3' => TRUE));
     } elseif (strpbrk($newpw, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') === FALSE || strlen($newpw) < 8) {
         $this->load->view('changePassword', array('user' => $user, 'error3' => TRUE));
     } else {
         $user->setPassword($newpw);
         $user->update();
         $this->load->view('changePassword', array('user' => $user, 'success' => TRUE));
     }
 }
Esempio n. 2
0
 public function auth()
 {
     //Get the username and password from the field
     $username = $this->input->post('username');
     $password = $this->input->post('password');
     //Create a new user object
     $user = new User_model();
     //If username exists load userdata
     if ($user->loadPropertiesFromPrimaryKey($username) || $user->loadPropertiesFromEmailAddress($username)) {
         //If password is correct
         if ($user->authenticate($password)) {
             if (null !== $user->getLastLogin() && 0 < $user->getLastLogin() && $user->getLastLogin() + 10368000 < time()) {
                 $advisor = $user->getAdvisor();
                 $this->load->view('login', array("error2" => TRUE, 'advisorname' => $advisor->getName(), 'advisoremail' => $advisor->getEmailAddress()));
             } else {
                 //Set the logged in timestamp
                 $user->setLastLogin(time());
                 $user->update();
                 //Activate the session
                 $_SESSION['UserID'] = $user->getUserID();
                 //Redirect to the mainpage controller
                 redirect('Mainpage');
             }
         } else {
             //Incorrect username or password, reload login and display an error
             $this->load->view('login', array("error" => TRUE));
         }
     } else {
         //Incorrect username or password, reload login and display an error
         $this->load->view('login', array("error" => TRUE));
     }
 }