Ejemplo n.º 1
0
Archivo: view.php Proyecto: nob/joi
 /**
  * render
  * Finds and chooses the correct template, then renders the page
  *
  * @param string  $template  Template (or array of templates, in order of preference) to render the page with
  * @return string
  */
 public function render($template)
 {
     $html = '<p style="text-align:center; font-size:28px; font-style:italic; padding-top:50px;">No template found.</p>';
     $list = $template ? $list = array($template) : self::$_templates;
     $allow_php = Config::get('_allow_php', false);
     foreach ($list as $template) {
         $template_path = $this->getTemplatesDirectory() . '/templates/' . ltrim($template, '/');
         $template_type = 'html';
         if (file_exists($template_path . '.html') || file_exists($template_path . '.php')) {
             # standard lex-parsed template
             if (file_exists($template_path . '.html')) {
                 Statamic_View::$_dataStore = array_merge(Statamic_View::$_dataStore, $this->data);
                 $html = $this->parser->parse(Theme::getTemplate($template), Statamic_View::$_dataStore, array($this, 'callback'), $allow_php);
                 break;
                 # lets forge into raw data
             } elseif (file_exists($template_path . '.php')) {
                 $template_type = 'php';
                 extract($this->data);
                 ob_start();
                 require $template_path . ".php";
                 $html = ob_get_clean();
                 break;
             } else {
                 Log::error("Template does not exist: '{$template_path}'", 'core');
             }
         }
     }
     return $this->_render_layout($html, $template_type);
 }
 public function member__forgot_password()
 {
     $globals = Statamic::loadAllConfigs();
     $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
     $token = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_STRING);
     $return = filter_input(INPUT_POST, 'return', FILTER_SANITIZE_STRING);
     $reset_return = filter_input(INPUT_POST, 'reset_return', FILTER_SANITIZE_STRING);
     $referrer = Request::getReferrer();
     // validate form token
     if (!$this->tokens->validate($token)) {
         $this->flash->set('forgot_password_error', 'Invalid token.');
         URL::redirect($referrer);
     }
     // bail if member doesn't exist
     if (!($member = Member::load($username))) {
         $this->flash->set('forgot_password_error', Localization::fetch('member_doesnt_exist'));
         URL::redirect($referrer);
     }
     // cache reset data
     $token = $this->tokens->create();
     $reset_data = array('username' => $username);
     if (isset($reset_return)) {
         $reset_data['return'] = $reset_return;
     }
     $this->cache->putYAML($token, $reset_data);
     // generate reset url
     $reset_url = URL::makeFull($this->fetchConfig('reset_password_url', str_replace(Config::getSiteURL(), '', $referrer)));
     $reset_url .= '?H=' . $token;
     // send email
     $attributes = array('from' => $this->fetchConfig('email_sender', Config::get('email_sender'), null, false, false), 'to' => $member->get('email'), 'subject' => $this->fetchConfig('reset_password_subject', 'Password Reset', null, false, false));
     if ($html_template = $this->fetchConfig('reset_password_html_email', false, null, false, false)) {
         $attributes['html'] = Theme::getTemplate($html_template);
     }
     if ($text_template = $this->fetchConfig('reset_password_text_email', false, null, false, false)) {
         $attributes['text'] = Theme::getTemplate($text_template);
     }
     foreach ($attributes as $key => $value) {
         $attributes[$key] = Parse::template($value, array('reset_url' => $reset_url), array('statamic_view', 'callback'), $globals);
     }
     Email::send($attributes);
     $this->flash->set('forgot_password_sent', true);
     // redirect
     URL::redirect($return);
 }
 public function forgot_password_form()
 {
     // parse parameters and vars
     $attr_string = '';
     $site_root = Config::getSiteRoot();
     $return = $this->fetchParam('return', URL::getCurrent(), null, false, false);
     $reset_return = $this->fetchParam('reset_return', null, null, false, false);
     $allow_request_return = $this->fetchParam('allow_request_return', false, null, true, false);
     $logged_in_redirect = $this->fetchParam('logged_in_redirect', $return, null, false, false);
     $attr = $this->fetchParam('attr', false);
     // check that email template(s) exist
     if (!Theme::getTemplate($this->fetchConfig('reset_password_html_email', false, null, false, false)) && !Theme::getTemplate($this->fetchConfig('reset_password_text_email', false, null, false, false))) {
         throw new Exception('Your reset password email template(s) must exist and contain a {{ reset_url }}.');
     }
     // grab request return
     $get_return = filter_input(INPUT_GET, 'return', FILTER_SANITIZE_URL);
     $post_return = filter_input(INPUT_POST, 'return', FILTER_SANITIZE_URL);
     $request_return = Helper::pick($post_return, $get_return);
     // is user already logged in? forward as needed
     if (Auth::isLoggedIn()) {
         URL::redirect($logged_in_redirect, 302);
     }
     // if we're letting return values to be set in URL and one exists, grab it
     if ($allow_request_return && $request_return) {
         $return = $request_return;
     }
     // set up any data to be parsed into content
     $data = array('error' => $this->flash->get('forgot_password_error', ''), 'email_sent' => $this->flash->get('forgot_password_sent'));
     // set up attributes
     if ($attr) {
         $attributes_array = Helper::explodeOptions($attr, true);
         foreach ($attributes_array as $key => $value) {
             $attr_string .= ' ' . $key . '="' . $value . '"';
         }
     }
     // set up form HTML
     $html = '<form method="post" action="' . Path::tidy($site_root . "/TRIGGER/member/forgot_password") . '" ' . $attr_string . '>';
     $html .= '<input type="hidden" name="return" value="' . $return . '">';
     if ($reset_return) {
         $html .= '<input type="hidden" name="reset_return" value="' . $reset_return . '">';
     }
     $html .= '<input type="hidden" name="token" value="' . $this->tokens->create() . '">';
     $html .= Parse::template($this->content, $data);
     $html .= '</form>';
     // return that HTML
     return $html;
 }
Ejemplo n.º 4
0
 /**
  * Send a notification/response email
  *
  * @param array  $submission  Array of submitted values
  * @param array  $config  Array of config values
  * @return void
  */
 private function send($submission, $config)
 {
     if (array_get($this->config, 'master_killswitch')) {
         return;
     }
     $email = array_get($config, 'email', false);
     if ($email) {
         $attributes = array_intersect_key($email, array_flip(Email::$allowed));
         if (array_get($email, 'automagic') || array_get($email, 'automatic')) {
             $automagic_email = $this->buildAutomagicEmail($submission);
             $attributes['html'] = $automagic_email['html'];
             $attributes['text'] = $automagic_email['text'];
         }
         if ($html_template = array_get($email, 'html_template', false)) {
             $attributes['html'] = Theme::getTemplate($html_template);
         }
         if ($text_template = array_get($email, 'text_template', false)) {
             $attributes['text'] = Theme::getTemplate($text_template);
         }
         /*
         |--------------------------------------------------------------------------
         | Parse all fields
         |--------------------------------------------------------------------------
         |
         | All email settings are parsed with the form data, allowing you, for
         | example, to send an email to a submitted email address.
         |
         |
         */
         foreach ($attributes as $key => $value) {
             $attributes[$key] = Parse::template($value, $submission);
         }
         $attributes['email_handler'] = array_get($config, 'email_handler', false);
         $attributes['email_handler_key'] = array_get($config, 'email_handler_key', false);
         Email::send($attributes);
     }
 }
Ejemplo n.º 5
0
 /**
  * Send a notification/response email
  *
  * @param array $submission Array of submitted values
  * @param array $email Array of email config values
  * @param array $config Array of config values
  */
 private function send($submission, $email, $config)
 {
     $attributes = array_intersect_key($email, array_flip(Email::$allowed));
     if (array_get($email, 'automagic') || array_get($email, 'automatic')) {
         $automagic_email = $this->buildAutomagicEmail($submission);
         $attributes['html'] = $automagic_email['html'];
         $attributes['text'] = $automagic_email['text'];
     }
     if ($html_template = array_get($email, 'html_template', false)) {
         $attributes['html'] = Theme::getTemplate($html_template);
     }
     if ($text_template = array_get($email, 'text_template', false)) {
         $attributes['text'] = Theme::getTemplate($text_template);
     }
     /*
     |--------------------------------------------------------------------------
     | Parse all fields
     |--------------------------------------------------------------------------
     |
     | All email settings are parsed with the form data, allowing you, for
     | example, to send an email to a submitted email address.
     |
     |
     */
     $globals = Config::getAll();
     array_walk_recursive($attributes, function (&$value, $key) use($submission, $globals) {
         $value = Parse::contextualTemplate($value, $submission, $globals);
     });
     $attributes['email_handler'] = array_get($config, 'email_handler', null);
     $attributes['email_handler_key'] = array_get($config, 'email_handler_key', null);
     $attributes['smtp'] = array_get($config, 'smtp', null);
     Email::send($attributes);
 }