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)); } }
public function saveUser($passedUsername = "", $passedPassword = "") { /* *Empty email model to create and commit *New comments wont have an id or a timestamp, database handles that */ $userModel = new User_model(); /* *TODO: move all the set methods into the constructor of the model *TODO: find more elegant solution than hard coding sets *TODO: add error checking to the commit method */ $userModel->setUsername($passedUsername); /* * Save password as hash so increase security */ $userModel->setPassword(hash("sha256", $passedPassword)); /* * Commit the model to the database and send result back */ return $userModel->commit(); }
public function send($userID = NULL, $email = NULL) { $session_user = new User_model(); if (!$session_user->loadPropertiesFromPrimaryKey($_SESSION['UserID'])) { redirect('Login/logout'); } if (!$session_user->isAdvisor()) { redirect('Login/logout'); } $this->load->library('email'); $user = new User_model(); $user->loadPropertiesFromPrimaryKey($userID); if ($user->getAdvisor()->getUserID() != $session_user->getUserID()) { redirect('Login/logout'); } //Loads user's email if optional email wasn't set if ($email == NULL) { $email = $user->getEmailAddress(); } //Array of characters to generate password $charset = array('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '~', '=', '+', '_', '-', '?', '/', '>', '<', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'w', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'W', 'Z'); //Generate random password $passlen = mt_rand(8, 12); $pass = NULL; for ($i = 0; $i < $passlen; $i++) { $pass = $pass . $charset[mt_rand(0, count($charset) - 1)]; } //Set user password //Email user their login information $this->email->from('*****@*****.**', 'Admin Name'); $this->email->to('*****@*****.**'); $this->email->subject('Subject'); $this->email->message('Password: '******'Username: '******'headers', 'subject', 'body')); $user->setPassword($pass); //Email user their login information $this->load->library('email'); $config['protocol'] = 'smtp'; $config['smpt_crypt'] = 'ssl'; $config['smtp_host'] = 'ssl://smtp.gmail.com'; $config['smtp_port'] = '465'; $config['smtp_user'] = '******'; $config['smtp_pass'] = '******'; $config['mailtype'] = 'html'; $config['charset'] = 'utf-8'; $config['newline'] = "\r\n"; $config['validate'] = FALSE; $config['bcc_batch_mode'] = FALSE; $config['bcc_batch_size'] = 200; $this->email->initialize($config); $this->email->from('*****@*****.**', 'Senior'); $list = array('*****@*****.**'); $this->email->to($list); $this->email->reply_to('*****@*****.**', 'Senior'); $this->email->subject('Subject'); $this->email->message('Email works great!'); if ($user->update() && $this->email->send()) { $_SESSION['activation.message'] = "Success!"; } else { $_SESSION['activation.error'] = "Sending email failed!<br />" . $this->email->print_debugger(); } redirect('Activation/index'); }
/** * * @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(); }