/** * 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')); } }
public function postSave() { $user = ClientUser::getInstance(); // Update the user name. $user->update(array('first' => Request::get('first'), 'last' => Request::get('last'))); // Update the password. $password = Request::post('password'); $new_password = Request::post('new_password'); $new_password_confirm = Request::post('new_password_confirm'); if (!empty($password) && $user->checkPass($password)) { if (false) { Messenger::error('Your password did not meet the required criteria.'); } elseif ($new_password != $new_password_confirm) { Messenger::error('You did not enter the same password twice.'); } else { $user->setPass($new_password); } } elseif (!empty($new_password) || !empty($new_password)) { Messenger::error('You did not enter your correct current password.'); } // Update mailing list preferences. $new_lists = Request::get('subscribed', 'array', 'int', array()); $new_lists = array_combine($new_lists, $new_lists); $all_lists = Subscription::getLists(); $user_id = ClientUser::getInstance()->id; $user_lists = Subscription::getUserLists($user_id); $remove_lists = array(); foreach ($user_lists as $list) { if (empty($new_lists[$list['message_list_id']]) && !empty($list['visible'])) { $remove_lists[$list['message_list_id']] = $list['message_list_id']; } } $add_lists = $new_lists; unset($add_lists[0]); if (!isset($new_lists[0])) { foreach ($all_lists as $list) { if (empty($list['visible'])) { $remove_lists[$list['message_list_id']] = $list['message_list_id']; } } } $db = Database::getInstance(); if (!empty($remove_lists)) { $db->delete('message_list_user', array('message_list_id' => array('IN', $remove_lists), 'user_id' => $user_id)); } if (!empty($add_lists)) { $db->insertMultiple('message_list_user', array('message_list_id' => $add_lists, 'user_id' => $user_id), true); } if (count(Messenger::getErrors()) == 0) { Navigation::redirect(null, array('msg' => 'saved')); } }
protected function initSettings() { if (Request::get('return') == 'view') { $this->post_actions['after_post'] = function ($row) { Navigation::redirect('/' . $row['url'] . '.htm'); }; } $this->preset['user_id']['default'] = ClientUser::getInstance()->id; $this->preset['url']['submit_function'] = function (&$output) { $output['url'] = Request::post('url', 'url') ?: Request::post('title', 'url'); }; $this->preset['header_image'] = array('type' => 'image', 'location' => BlogModel::IMAGE_PATH, 'weblocation' => '/' . BlogModel::IMAGE_PATH); $this->action_fields = array('view' => array('display_name' => 'View', 'type' => 'html', 'html' => function ($row) { return '<a href="/' . $row['url'] . '.htm"><img src="/images/lightning/resume.png" /></a>'; })); }
/** * Require the user to log in and return to this page afterwards. * * @param string $action * The action on the login page. */ public static function requireLogin($action = '') { if (self::getInstance()->id == 0) { $query = array(); if (!empty($action)) { $query['action'] = $action; } // Set the redirect parameter. $query['redirect'] = Request::getLocation(); // Add the current query string. $redirect_query = $_GET; unset($redirect_query['request']); if (!empty($redirect_query)) { $query['redirect'] .= '?' . http_build_query($redirect_query); } Navigation::redirect('/user' . $action, $query); } }
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'); }
protected function redirect() { if (!empty($this->results['redirect'])) { if (!empty($this->results['set_redirect'])) { // bring them back to this page after $qsa = strstr($this->results['redirect'], '?') ? '&' : '?'; $redirect = $this->results['redirect'] . $qsa . 'redirect=' . urlencode($_SERVER['REQUEST_URI']); } else { $redirect = $this->results['redirect']; } Navigation::redirect($redirect); } }
/** * Redirects the user if they are not logged in. * * @param int $auth * A required authority level if they are logged in. */ public function login_required($auth = 0) { if ($this->id == 0) { Navigation::redirect($this->login_url . urlencode($_SERVER['REQUEST_URI'])); } if ($this->authority < $auth) { Navigation::redirect($this->unauthorized_url . urlencode($_SERVER['REQUEST_URI'])); } }
/** * Redirect the page to the same current page with the current query string. * * @param array * Additional query string parameters to add to the current url. */ public function redirect($params = array()) { $output_params = array(); foreach ($this->params as $param) { if (isset($params[$param])) { $output_params[$param] = $params[$param]; } elseif (isset($this->$param)) { $output_params[$param] = $this->$param; } } Navigation::redirect('/' . Request::getLocation(), $output_params); }
public function getStopImpersonating() { $session = Session::getInstance(); if (ClientUser::getInstance()->isImpersonating()) { $session->unsetSetting('impersonate'); $session->saveData(); Navigation::redirect('/'); } }
public function getImpersonate() { $session = Session::getInstance(); $session->setSettings('impersonate', Request::get('id', 'int')); $session->saveData(); // TODO: This should call the User::loginRedirect() function. Navigation::redirect('/'); }
public function afterPostRedirect() { // Run any scripts after execution. if (isset($this->function_after[$this->action])) { $this->function_after[$this->action](); } // If this is a custom submit action. $submit = Request::get('submit'); foreach ($this->custom_buttons as $button) { if ($button['text'] == $submit && !empty($button['redirect'])) { Navigation::redirect($this->replaceURLVariables($button['redirect'])); } } // Redirect to the next page. if ($return = Request::get('table_return', 'url_encoded')) { Navigation::redirect($return); } if ($this->submit_redirect && ($redirect = Request::get('redirect'))) { Navigation::redirect($redirect); } elseif (!empty($this->redirectAfter[$this->action])) { Navigation::redirect($this->redirectAfter[$this->action]); } elseif ($this->submit_redirect && isset($this->action_after[$this->action])) { Navigation::redirect($this->createUrl($this->action_after[$this->action], $this->action_after[$this->action] == 'list' ? 1 : $this->id)); } else { // Generic redirect. Navigation::redirect($this->createUrl()); } }