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)); } }
/** * * @param type $data * @return type This function will return the id of the newly created use on success * and returns false otherwise. */ private function createUserData($data) { $this->checkSec(); $user = new User_model(); if ($data['uID'] != 0) { $user->setUserID($data['uID']); } $user->setEmailAddress($data['email']); $user->setName($data['lName'] . ',' . $data['fName']); //todo Ensure there is a password and a name here. if ($data['pass'] == $data['confPass']) { $user->setPassword($data['pass']); } $user->setState(1); $user->setLastLogin(0); $isCreated = $user->create(); if (!$isCreated && $data['uID'] != 0) { redirect('User/index/modify/' . $user->getUserID()); } $this->addUserRoles($data, $user); return $user->getUserID(); }