public function newUserRegistration() { if ($this->config->item('allow_signup') == true) { // Check validation for user input in SignUp form $this->form_validation->set_rules('username', 'Username', 'trim|required'); $this->form_validation->set_rules('email', 'Email', 'trim|required'); $this->form_validation->set_rules('phone', 'Phone', 'trim|required'); $this->form_validation->set_rules('firstName', 'First Name', 'trim|required'); $this->form_validation->set_rules('lastName', 'Last Name', 'trim|required'); $this->form_validation->set_rules('password', 'Password', 'trim|required'); if ($this->form_validation->run() == false) { $this->load->view('login/registration_form'); } else { if ($this->config->item('require_password_reset') == true) { $password = User_Model::randomPassword(); } elseif ($this->config->item('require_password_reset') == false) { $password = password_hash($this->input->post('password'), PASSWORD_DEFAULT); } $data = array('username' => $this->input->post('username'), 'email' => $this->input->post('email'), 'phone' => $this->input->post('phone'), 'first_name' => $this->input->post('firstName'), 'last_name' => $this->input->post('lastName'), 'password' => $password); $result = $this->login->registrationInsert($data); if ($result == true) { $data['message_display'] = 'Registration Successful!'; $this->load->view('login/login_form', $data); } else { $data['message_display'] = 'Username already exist!'; $this->load->view('login/registration_form', $data); } } } else { $this->session->set_flashdata('error', 'The site admin does not allow user signup.'); redirect('home'); } }
public function createNewUser($formData) { if (!$this->userObj->isAdmin()) { echo json_encode(array('status' => 'error', 'msg' => 'You do not have permission to create a new user.')); exit; } // Check to make sure user does not already exist $userExists = User_model::exists($formData['username']); // If the above statement returns more than 0 rows, the user exists, so display error if ($userExists > 0) { echo json_encode(array('status' => 'error', 'msg' => 'A user with that name already exists.')); exit; } else { $phonenumber = @$formData['phone']; if (!isset($formData['canAdd'])) { $formData['canAdd'] = 0; } if (!isset($formData['canCheckin'])) { $formData['canCheckin'] = 0; } $userArray = array('username' => $formData['username'], 'password' => User_Model::randomPassword(), 'department' => $formData['department'], 'phone' => $phonenumber, 'email' => $formData['email'], 'last_name' => $formData['last_name'], 'first_name' => $formData['first_name'], 'can_add' => $formData['canAdd'], 'can_checkin' => $formData['canCheckin'], 'pw_reset_code' => 1); $userId = User_Model::createUser($userArray); if (!isset($formData['admin'])) { $formData['admin'] = '0'; } $adminArray = array('id' => $userId, 'admin' => $formData['admin']); //Sets the correct admin settings for the new user User_Model::newUserAdmin($adminArray); if (isset($formData['departmentReview'])) { for ($i = 0; $i < sizeof($formData['departmentReview']); $i++) { $deptId = $formData['departmentReview'][$i]; $deptArray = array('dept_id' => $deptId, 'user_id' => $userId); //sets the reviewer status for the new user User_model::newUserReviewer($deptArray); } } /* // mail user telling him/her that his/her account has been created. $newUserObj = new User($userId, $pdo); $date = date('M-d-Y H:i'); $getFullName = $this->userObj->getFullName(); $fullName = $getFullName[0].' '.$getFullName[1]; $getNewFullName = $newUserObj->getFullName(); $newUserFullName = $getNewFullName[0].' '.$getNewFullName[1]; $body= (file_get_contents('templates/emails/user-email-template.html')); $body = str_replace('$fullName', $newUserFullName, $body); $body = str_replace('$userName', $newUserObj->getName(), $body); $body = str_replace('$base_url', $base_url, $body); $body = str_replace('$msg','Your Document Management account was created by '. $fullName . ' on ' . $date , $body); $body = str_replace('$date', $date, $body); $body = str_replace('$email', $this->userObj->getEmailAddress(), $body); $body = str_replace('$siteName', msg('email_automated_document_messenger'), $body); $body = str_replace('$phoneNumber', $this->userObj->getPhoneNumber(), $body); $body = str_replace('$creator', $fullName, $body); if($GLOBALS['CONFIG']['authen'] == 'mysql') { $body = str_replace('$password', $_POST['password'], $body); } $mail = new PHPMailer; $mail->isSendmail(); $mail->setFrom($this->userObj->getEmailAddress(), $fullName); $mail->Subject = msg('message_account_created_add_user'); $mail->msgHTML($body); $mail->addAddress($newUserObj->getEmailAddress() , $newUserFullName); if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; break; } else { echo "Message sent!"; } */ } }