示例#1
0
 /**
  * Send a posted contact request to the site admin.
  */
 public function postSendMessage()
 {
     // Make sure the sender's email address is valid.
     if (!($sender_email = Request::post('email', 'email'))) {
         Messenger::error('Please enter a valid email address.');
         return $this->get();
     }
     if (!ReCaptcha::verify()) {
         Messenger::error('You did not correctly enter the captcha code.');
         return $this->get();
     }
     $subject = Configuration::get('contact.subject');
     $body = "\nName: {$_POST['name']}\nEmail: {$sender_email}\nMessage:\n{$_POST['message']}";
     $to_addresses = Configuration::get('contact.to');
     $mailer = new Mailer();
     foreach ($to_addresses as $to) {
         $mailer->to($to);
     }
     $sent = $mailer->from($sender_email)->subject($subject)->message($body)->send();
     if (!$sent) {
         Messenger::error('Your message could not be sent. Please try again later');
         return $this->get();
     } else {
         // Send an email to to have them test for spam.
         if ($auto_responder = Configuration::get('contact.auto_responder')) {
             $auto_responder_mailer = new Mailer();
             $result = $auto_responder_mailer->sendOne($auto_responder, UserModel::loadByEmail($sender_email) ?: new UserModel(array('email' => $sender_email)));
             if ($result && Configuration::get('contact.spam_test')) {
                 // Set the notice.
                 Navigation::redirect('/message', array('msg' => 'spam_test'));
             }
         }
         Navigation::redirect('/message', array('msg' => 'contact_sent'));
     }
 }
示例#2
0
 public function postReset()
 {
     if (!($email = Request::get('email', 'email'))) {
         Output::error('Invalid email');
     } elseif (!($user = UserModel::loadByEmail($email))) {
         Output::error('User does not exist.');
     }
     $user->sendResetLink();
 }
示例#3
0
 public function execute($job)
 {
     // Remove expired sessions.
     Logger::message('Cleaning sessions...');
     $count = Session::clearExpiredSessions();
     Logger::message($count . ' sessions removed.');
     // Remove user reset keys.
     Logger::message('Cleaning expired user keys...');
     $count = User::removeExpiredTempKeys();
     Logger::message($count . ' user keys removed.');
 }
示例#4
0
 public function initSettings()
 {
     $this->preset['password']['submit_function'] = function (&$output) {
         if ($pass = Request::post('password')) {
             $salt = User::getSalt();
             $output['salt'] = bin2hex($salt);
             $output['password'] = User::passHash($pass, $salt);
         }
     };
     $this->preset['password']['edit_value'] = function (&$row) {
         return '';
     };
     $this->preset['password']['display_value'] = function (&$row) {
         return !empty($row['password']) ? 'Set' : '';
     };
 }
示例#5
0
 /**
  * Create an admin account. Will prompt for email address and password.
  */
 public function executeCreateAdmin()
 {
     do {
         if (!empty($email_input)) {
             $this->out('That is not a valid email.');
         }
         $email_input = $this->readline('Email: ');
     } while (!($email = Scrub::email($email_input)));
     do {
         $password = $this->readline('Password: '******'success']) {
         $user = UserModel::loadById($res['data']);
         $user->setType(UserModel::TYPE_ADMIN);
     } else {
         $this->out('Failed to create user.');
     }
 }
示例#6
0
 /**
  * Create the default logged in user.
  *
  * @return User
  *   The currently logged in user.
  */
 public static function createInstance()
 {
     // If a session is found.
     $session = SessionTool::getInstance(true, false);
     if ($session && $session->user_id > 0) {
         // If we are logged into someone elses account.
         if ($impersonate = $session->getSetting('impersonate')) {
             $user = User::loadById($impersonate);
         } else {
             // Try to load the user on this session.
             $user = User::loadById($session->user_id);
         }
     }
     if (!empty($user)) {
         return $user;
     } else {
         // No user was found.
         return User::anonymous();
     }
 }
示例#7
0
 public function post()
 {
     if ($name = Request::post('name', '', '', '')) {
         $name_parts = explode(' ', $name, 2);
         $name = array('first' => $name_parts[0]);
         if (!empty($name_parts[1])) {
             $name['last'] = $name_parts[1];
         }
     } else {
         // Add the user to the system.
         $name = array('first' => Request::post('first', '', '', ''), 'last' => Request::post('last', '', '', ''));
     }
     $email = Request::post('email', 'email');
     $user = User::addUser($email, $name);
     // Add the user to the mailing list.
     $default_list = Configuration::get('mailer.default_list');
     $mailing_list = Request::post('list_id', 'int', null, $default_list);
     if (!empty($mailing_list)) {
         $user->subscribe($mailing_list);
     }
     Navigation::redirect(Request::post('redirect') ?: '/message?msg=optin');
 }
示例#8
0
 public function execute()
 {
     // Load the bounce handler.
     require_once HOME_PATH . '/Lightning/Vendor/BounceHandler/src/BounceHandler.php';
     $bounce_handler = new \cfortune\PHPBounceHandler\BounceHandler();
     // Parse the message.
     $bounce_info = $bounce_handler->get_the_facts(file_get_contents('php://stdin'));
     // If this was a message failure.
     if (!empty($bounce_info[0]['recipient']) && preg_match('/5\\.\\d\\.\\d/', $bounce_info[0]['status'])) {
         $email = $bounce_info[0]['recipient'];
         $user = User::loadByEmail($email);
         if (!$user) {
             // Bounced from an unknown recipient, ignore this.
             Tracker::trackEvent('Email Bounced', 0, 0);
             return;
         }
         // Track the bounced event.
         // TODO: we can scan the email for a link to see if we know the message id.
         Tracker::trackEvent('Email Bounced', 0, $user->user_id);
         // Get the last 6 send/bounce events.
         // TODO: Also check for a reactivation email.
         $mail_history = Database::getInstance()->select('tracker_event', array('user_id' => $user->user_id, 'tracker_id' => array('IN', array(Tracker::getTrackerId('Email Sent'), Tracker::getTrackerId('Email Bounced')))), array(), 'ORDER BY date DESC LIMIT 6');
         $bounce_count = 0;
         $bounce_id = Tracker::getTrackerId('Email Bounced');
         foreach ($mail_history as $history) {
             if ($history['tracker_id'] == $bounce_id) {
                 $bounce_count++;
             }
         }
         // If there are two bounced messages, deactivate the user.
         if ($bounce_count >= 2) {
             // TODO: Instead of '1' here, we should have a table like `tracker`
             // that tracks tracker sub_ids by name.
             Tracker::trackEvent('Deactivate User', 1, $user->user_id);
             $user->unsubscribeAll();
         }
     }
 }
示例#9
0
 public function postSetPassword()
 {
     if ($user = UserModel::loadByTempKey(Request::get('key', 'base64'))) {
         if (($pass = Request::post('password')) && $pass == Request::post('password2')) {
             $user->setPass($pass);
             $user->registerToSession();
             $user->removeTempKey();
             $this->loginRedirect();
         } else {
             Messenger::error('Please enter a valid password and verify it by entering it again..');
         }
     } else {
         $this->page = '';
         Messenger::error('Invalid Access Key');
     }
 }