/** * Forgot password. */ function forgotAction() { // Wrap the whole thing in a try/catch. try { // Get the login name. $login = $this->getStr('login'); // Make sure the login is valid. if (isset($login)) { // Get the DAO used to retrieve employee info. $employeeDao = new EmployeeDao(); // Get the employee attempting to log in. $employee = $employeeDao->getEmployeeByLogin($login); // Make sure the employee was found. if (isset($employee)) { // Make sure the employee has an email address. if (isset($employee->email)) { // The new password. $password = $this->generatePassword(); // Log the password. Logger::getLogger()->debug("Resetting password for {$login}: {$password}"); // Get the mail configuration. $config = Bootstrap::$registry->config->mail; // Create the login info. $mailconfig = array('auth' => 'login', 'port' => $config->port, 'username' => $config->user, 'password' => $config->pass); // Create the transport. $transport = new Zend_Mail_Transport_Smtp($config->host, $mailconfig); $mail = new Zend_Mail(); $mail->setBodyText("\nForgot Password Request:\n\n" . "Your company timesheet system web site received a request \n" . "indicating your account password was forgotten and should \n" . "be reset. If you did not make this request, please notify the\n" . "web site administrator.\n\n" . "Here is your new login information:\n" . " Login: {$login}\n" . " Password: {$password}\n\n" . "Once you login, you can change your password by viewing\n" . "your profile information.\n")->setFrom($config->from, $config->name)->addTo($employee->email, $employee->full_name)->setSubject('Timesheet System - Password Reset')->send($transport); // Create the JSON object to return. $json = new stdClass(); $json->success = true; $json->msg = 'An email with a new random password was sent ' . 'to the email address associated with your account. ' . 'Please check your email for your updated login info. ' . 'If you have any problems, please contact the web site ' . 'administrator.'; // Set a random password on the user account. $employee->hashed_pass = hash('SHA512', $password); // Turn the employee info into an array. $data = array('id' => $employee->id, 'login' => $employee->login, 'hashed_pass' => $employee->hashed_pass, 'email' => $employee->email, 'first_name' => $employee->first_name, 'last_name' => $employee->last_name, 'suffix' => $employee->suffix, 'division' => $employee->division, 'personnel_type' => $employee->personnel_type, 'active' => $employee->active); // Save the updated employee data. $employeeDao->save($employee->id, $data); } else { // No email address on file. $json = new stdClass(); $json->success = false; $json->msg = 'No email address is specified within your ' . 'profile information, so your password was not reset. ' . 'Please contact the web site administrator for your new password.'; } } else { // No user account found. $json = new stdClass(); $json->success = false; $json->msg = 'No user account was found with the specified ' . 'login or email address. Please specify the correct ' . 'user information before requesting a password reset.'; } } else { // Create the JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = 'A login or email address must be provided ' . 'when requesting a password reset.'; } } catch (Zend_Exception $ex) { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = $ex->getMessage(); } // Return the JSON response. $this->_helper->json($json); }
/** * Add a employee. */ public function addAction() { // Get the user's session. $session = new Zend_Session_Namespace('Web'); // Get the current user. $me = $session->employee; // Wrap the whole thing in a try/catch. try { // Create an array of the fields that represent the employee. $data = array('first_name' => $this->getStr('first_name'), 'last_name' => $this->getStr('last_name'), 'suffix' => $this->getStr('suffix'), 'login' => $this->getStr('login'), 'email' => $this->getStr('email'), 'division' => $this->getStr('division'), 'personnel_type' => $this->getStr('personnel_type'), 'active' => $this->getBool('active')); // Set the hashed password value if necessary. $password = $this->getStr('password'); $data['hashed_pass'] = hash('SHA512', $password); // Collect the privileges for this user. $privileges = array(); if ($this->getBool('admin') && $me->admin) { $privileges[] = 'admin'; } if ($this->getBool('payroll') && ($me->payroll || $me->admin)) { $privileges[] = 'payroll'; } if ($this->getBool('manager') && ($me->manager || $me->admin)) { $privileges[] = 'manager'; } if ($this->getBool('security') && ($me->security || $me->admin)) { $privileges[] = 'security'; } // Get the DAO. $employeeDao = new EmployeeDao(); // Check to see if the login already exists. $exists = $employeeDao->getEmployeeByLogin($data['login']); // Check to see if the requested login already exists. if (isset($exists)) { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = 'Failed to create the employee - an account ' . 'with the specified login already exists.'; } else { // Add the employee. $id = $employeeDao->add($data); // Retrieve the new employee. $employee = $employeeDao->get($id); // Make sure the employee was returned. if (isset($employee)) { // Check to see if privileges need to be added. if (count($privileges) > 0) { // Get the RoleDao. $roleDao = new RoleDao(); // Create the roles for this user. foreach ($privileges as $priv) { // Add this role. $roleDao->add(array('name' => $priv, 'employee_id' => $employee->id)); } } // Get the primary supervisor id. $supervisor = $this->getInt('supervisor'); // Make sure the supervisor is valid. if (isset($supervisor) && is_numeric($supervisor)) { // Get the DAO. $supervisorDao = new SupervisorDao(); // Add the primary supervisor. $supervisorDao->add(array('employee_id' => $employee->id, 'supervisor_id' => $supervisor, 'primary' => true)); } // Create the JSON object to return. $json = new stdClass(); $json->success = true; $json->msg = 'The employee was created successfully.'; $json->employee = $employee; } else { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = 'Failed to create the employee.'; } } } catch (Zend_Exception $ex) { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = $ex->getMessage(); } // Return the JSON. $this->_helper->json($json); }