예제 #1
0
 public static function RecoverPassword($id, $request_type = null)
 {
     //Generate Random Password of 6 characters
     $password = self::GenerateRandomPassword(Constant::PASSWORD_MIMIMUM_LENGTH);
     //Encrypt password
     $password_encrypted = self::EncryptPassword($password);
     //check if this employee exists
     $employee = EmployeePeer::retrieveByPK($id);
     if ($employee) {
         $employee->setPassword($password_encrypted);
         //Set newly created password to databaes
         if ($employee->save()) {
             //send the new password and other details to use via email
             //prepare the constants that will be replaced in email body
             $email_vars = array('USER' => $employee->getName(), 'EMAIL' => $employee->getEmail(), 'PASSWORD' => $password);
             Emails::SendEmail($employee->getEmail(), $request_type, $email_vars);
             return Constant::LOGIN_PASSWORD_SENT_SUCCESS;
         } else {
             return Constant::DB_ERROR;
         }
     } else {
         return Constant::LOGIN_INVALIDATION_EMAIL_FIELD;
     }
 }