/**
  * Validate the email field for contact forms.
  * @param I2CE_FormField $formfield
  */
 public function validate_form_contact_field_email($formfield)
 {
     $value = $formfield->getValue();
     if (I2CE_Validate::checkString($value) && !I2CE_Validate::checkEmail($value)) {
         $formfield->setInvalidMessage('invalid_email');
     }
 }
 /**
  * Validate the email field for contact forms.
  * @param I2CE_FormField $formfield
  */
 public function validate_form_user_request_field_email($formfield)
 {
     $value = $formfield->getValue();
     if (I2CE_Validate::checkString($value) && !I2CE_Validate::checkEmail($value)) {
         $formfield->setInvalidMessage("invalid_email");
     }
 }
Ejemplo n.º 3
0
 /**
  * Perform the main actions of the page.
  * @global array Get the home page from the global configuration
  */
 protected function action()
 {
     parent::action();
     if ($this->user->logged_in()) {
         $this->setRedirect('home');
         return;
     }
     $access = I2CE::getUserAccess();
     $has_email = $access instanceof I2CE_UserAccess_Mechanism && $access->canChangePassword() && I2CE_User::hasDetail('email');
     $this->template->setBodyId("loginPage");
     $this->template->setDisplayDataImmediate('has_email', $has_email);
     if (!$this->isPost() || !$has_email) {
         return;
     }
     if ($this->post('submit') == "Reset") {
         if (I2CE_Validate::checkString($this->post('username')) && I2CE_User::userExists($this->post('username'), true)) {
             $user = new I2CE_User($this->post('username'), true, false, true);
             $email = $user->email;
             $valid_email = I2CE_Validate::checkEmail($email);
             $pass = trim(I2CE_User::generatePassword());
             if ($user->getRole() != 'guest' && $valid_email && $pass && $user->setPassword($pass)) {
                 if ($this->mailPassword($email, $this->post('username'), $pass)) {
                     $this->template->addTextNode("error_message", "Your password has been reset and mailed to you.");
                 } else {
                     $this->template->addTextNode("error_message", "Your password has been reset, but could not mailed to you. Please contact your system administrator");
                 }
             } else {
                 $this->template->addTextNode("error_message", "Your password could not be reset.  Please contact your system administrator to change your password.");
             }
         } else {
             $this->template->addTextNode("error_message", "Your username could not be found in the database.  Please contact your System Administrator.");
         }
     } elseif ($this->post('submit') == "View") {
         $usernames = I2CE_User::findUsersByInfo(false, array('email' => $this->post('email')));
         if (is_array($usernames) && count($usernames) == 1) {
             reset($usernames);
             $this->template->addText('<p id="error_message">Your username is: <b>' . current($usernames) . '</b><br />Enter it below to reset your password or return to the login page to login.</p>', 'p');
         } else {
             $this->template->addTextNode("error_message", "That email address was not found in the system.  Please contact your System Administrator.");
         }
     } else {
         $this->template->addTextNode("error_message", "Please click one of the submit buttons or only enter one text field.");
     }
 }
 /**
  * Perform extra validation for the trainingprovider form.
  * A new trainingprovider record needs to verify there aren't any existing 
  * records with the same name.
  * @param I2CE_Form $form
  */
 public function validate_form_trainingprovider($form)
 {
     $search = array();
     $name_ignore = false;
     if (isset($form->name_ignore)) {
         $name_ignore = $form->name_ignore;
     }
     if (I2CE_ModuleFactory::instance()->isEnabled('forms-storage') && $form->getId() == 0 && !$name_ignore && I2CE_Validate::checkString($form->name)) {
         $where = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'name', 'style' => 'lowerequals', 'data' => array('value' => strtolower($form->name)))));
         $results = I2CE_FormStorage::listFields('trainingprovider', array('name'), false, $where, array('name'));
         if (count($results) > 0) {
             foreach ($results as $id => &$data) {
                 $data = implode(', ', $data);
             }
             $form->getField('name')->setInvalid("Duplicate records match this record's name:", array("viewprovider?id=" => $results));
         }
     }
     $value = $form->getField('email')->getValue();
     if (I2CE_Validate::checkString($value) && !I2CE_Validate::checkEmail($value)) {
         $form->getField('email')->setInvalid('invalid_email');
     }
 }
Ejemplo n.º 5
0
 /**
  * Try to generate a new password and assign it to the password and confirm variables.
  */
 public function tryGeneratePassword()
 {
     if (!I2CE_User::hasDetail('email')) {
         return false;
     }
     if (!I2CE_Validate::checkEmail($this->email)) {
         return false;
     }
     if ($this->generate_password) {
         $pass = I2CE_User::generatePassword();
         $this->__set('password', $pass);
         $this->__set('confirm', $pass);
     }
     return true;
 }
 /**
  * Handler for mail triggers
  * @param string $username The username to be notified
  * @param string $trigger The trigger being called
  * @param string $message The message to send
  * @param string $link The optional link to include
  * @param string $link_text The link text for the link
  * @param array $args Any option arguments for this trigger handler
  * @return boolean
  */
 public function triggerEmail($username, $trigger, $message, $link = false, $link_text = '', $args = array())
 {
     $user = I2CE_FormFactory::instance()->createContainer("user|" . $username);
     $user->populate();
     $email = $user->email;
     if (!I2CE_Validate::checkEmail($email)) {
         I2CE::raiseError("Invalid email to {$email} for {$username} while sending trigger: {$trigger}");
         return false;
     }
     $display = $trigger;
     $this->config->setIfIsSet($display, "triggers/{$trigger}/display");
     $subject = '';
     if (array_key_exists('subject', $args)) {
         $subject = $args['subject'];
     } else {
         $this->config->setIfIsSet($subject, "messages/default_email_subject");
         if ($subject = '') {
             $subject = 'Automated email for ' . $display;
         } else {
             $subject .= " {$display}";
         }
     }
     $full_message = $message;
     if ($link) {
         $full_message .= "\n\n";
         if ($link_text) {
             $full_message .= "{$link_text}: ";
         }
         $full_message .= "{$link}\n";
     }
     $full_message = wordwrap($full_message);
     if (!I2CE_Mailer::mail($email, array('Subject' => $subject), $full_message)) {
         I2CE::raiseError("Unable to send message to {$email} for trigger.");
         return false;
     }
     return true;
 }