function __construct($exception, $mimetype = null) { $content = ''; $admins = Pluf::f('admins', array()); if (count($admins) > 0) { // Get a nice stack trace and send it by emails. $stack = Pluf_HTTP_Response_ServerError_Pretty($exception); $subject = $exception->getMessage(); $subject = substr(strip_tags(nl2br($subject)), 0, 50) . '...'; foreach ($admins as $admin) { $email = new Pluf_Mail($admin[1], $admin[1], $subject); $email->addTextMessage($stack); $email->sendMail(); } } try { $context = new Pluf_Template_Context(array('message' => $exception->getMessage())); $tmpl = new Pluf_Template('500.html'); $content = $tmpl->render($context); $mimetype = null; } catch (Exception $e) { $mimetype = 'text/plain'; $content = 'The server encountered an unexpected condition which prevented it from fulfilling your request.' . "\n\n" . 'An email has been sent to the administrators, we will correct this error as soon as possible. Thank you for your comprehension.' . "\n\n" . '500 - Internal Server Error'; } parent::__construct($content, $mimetype); $this->status_code = 500; }
/** * Display the main page of the application. * * The main page is only displaying data. So we load the categories * and for each category we display the corresponding items. * * @param Pluf_HTTP_Request Request object * @param array Matches against the regex of the dispatcher * @return Pluf_HTTP_Response or can throw Exception */ public function main($request, $match) { // In the main page we want a list of all the Todo lists with // a link to edit each of them, a link to see the content and // a link to create a new list. // Get the complete list of Todo_List object $lists = Pluf::factory('Todo_List')->getList(); // Create a context for the template $context = new Pluf_Template_Context(array('page_title' => 'Home', 'lists' => $lists)); // Load a template $tmpl = new Pluf_Template('todo/index.html'); // Render the template and send the response to the user return new Pluf_HTTP_Response($tmpl->render($context)); }
function __construct($request) { $content = ''; try { $context = new Pluf_Template_Context(array('query' => $request->query)); $tmpl = new Pluf_Template('404.html'); $content = $tmpl->render($context); $mimetype = null; } catch (Exception $e) { $mimetype = 'text/plain'; $content = sprintf('The requested URL %s was not found on this server.' . "\n" . 'Please check the URL and try again.' . "\n\n" . '404 - Not Found', Pluf_esc($request->query)); } parent::__construct($content, $mimetype); $this->status_code = 404; }
function __construct($request) { $content = ''; try { $context = new Pluf_Template_Context(array('query' => $request->query)); $tmpl = new Pluf_Template('403.html'); $content = $tmpl->render($context); $mimetype = null; } catch (Exception $e) { $mimetype = 'text/plain'; $content = 'You are not authorized to view this page. You do not have permission' . "\n" . 'to view the requested directory or page using the credentials supplied.' . "\n\n" . '403 - Forbidden'; } parent::__construct($content, $mimetype); $this->status_code = 403; }
function __construct($request) { $content = ''; try { $context = new Pluf_Template_Context(array('query' => $request->query)); $tmpl = new Pluf_Template('503.html'); $content = $tmpl->render($context); $mimetype = null; } catch (Exception $e) { $mimetype = 'text/plain'; $content = sprintf('The requested URL %s is not available at the moment.' . "\n" . 'Please try again later.' . "\n\n" . '503 - Service Unavailable', Pluf_esc($request->query)); } parent::__construct($content, $mimetype); $this->status_code = 503; $this->headers['Retry-After'] = 300; // retry after 5 minutes }
/** * Notification of change of the object. * * @param IDF_Conf Current configuration * @param bool Creation (true) */ public function notify($conf, $create = true) { // Now we add to the queue, soon we will push everything in // the queue, including email notifications and indexing. // Even if the url is empty, we add to the queue as some // plugins may want to do something with this information in // an asynchronous way. $project = $this->get_project(); $scm = $project->getConf()->getVal('scm', 'git'); $url = str_replace(array('%p', '%r'), array($project->shortname, $this->scm_id), $conf->getVal('webhook_url', '')); $payload = array('to_send' => array('project' => $project->shortname, 'rev' => $this->scm_id, 'scm' => $scm, 'summary' => $this->summary, 'fullmessage' => $this->fullmessage, 'author' => $this->origauthor, 'creation_date' => $this->creation_dtime), 'project_id' => $project->id, 'authkey' => $project->getPostCommitHookKey(), 'url' => $url); $item = new IDF_Queue(); $item->type = 'new_commit'; $item->payload = $payload; $item->create(); if ('' == $conf->getVal('source_notification_email', '')) { return; } $current_locale = Pluf_Translation::getLocale(); $langs = Pluf::f('languages', array('en')); Pluf_Translation::loadSetLocale($langs[0]); $context = new Pluf_Template_Context(array('c' => $this, 'project' => $this->get_project(), 'url_base' => Pluf::f('url_base'))); $tmpl = new Pluf_Template('idf/source/commit-created-email.txt'); $text_email = $tmpl->render($context); $email = new Pluf_Mail(Pluf::f('from_email'), $conf->getVal('source_notification_email'), sprintf(__('New Commit %s - %s (%s)'), $this->scm_id, $this->summary, $this->get_project()->shortname)); $email->addTextMessage($text_email); $email->sendMail(); Pluf_Translation::loadSetLocale($current_locale); }
public function timelineFeed($request, $match) { $prj = $request->project; // Need to check the rights $rights = array(); if (true === IDF_Precondition::accessSource($request)) { $rights[] = '\'IDF_Commit\''; IDF_Scm::syncTimeline($request->project); } if (true === IDF_Precondition::accessIssues($request)) { $rights[] = '\'IDF_Issue\''; $rights[] = '\'IDF_IssueComment\''; } if (true === IDF_Precondition::accessDownloads($request)) { $rights[] = '\'IDF_Upload\''; } if (true === IDF_Precondition::accessWiki($request)) { $rights[] = '\'IDF_WikiPage\''; $rights[] = '\'IDF_WikiRevision\''; } if (true === IDF_Precondition::accessReview($request)) { $rights[] = '\'IDF_Review_Comment\''; $rights[] = '\'IDF_Review_Patch\''; } if (count($rights) == 0) { $rights[] = '\'IDF_Dummy\''; } $sqls = sprintf('model_class IN (%s)', implode(', ', $rights)); $sql = new Pluf_SQL('project=%s AND ' . $sqls, array($prj->id)); $params = array('filter' => $sql->gen(), 'order' => 'creation_dtime DESC', 'nb' => 20); $items = Pluf::factory('IDF_Timeline')->getList($params); $set = new Pluf_Model_Set($items, array('public_dtime' => 'public_dtime')); $out = array(); foreach ($set as $item) { if ($item->id) { $out[] = $item->feedFragment($request); } } if ($items->count() > 0) { $date = Pluf_Date::gmDateToGmString($items[0]->creation_dtime); } else { $date = gmdate('c'); } $out = Pluf_Template::markSafe(implode("\n", $out)); $tmpl = new Pluf_Template('idf/index.atom'); $title = __('Updates'); $feedurl = Pluf::f('url_base') . Pluf::f('idf_base') . $request->query; $viewurl = Pluf_HTTP_URL_urlForView('IDF_Views_Project::timeline', array($prj->shortname)); $context = new Pluf_Template_Context_Request($request, array('body' => $out, 'date' => $date, 'title' => $title, 'feedurl' => $feedurl, 'viewurl' => $viewurl)); return new Pluf_HTTP_Response('<?xml version="1.0" encoding="utf-8"?>' . "\n" . $tmpl->render($context), 'application/atom+xml; charset=utf-8'); }
/** * Notification of change of the object. * * For the moment, only email, but one can add webhooks later. * * Usage: * <pre> * $this->notify($conf); // Notify the creation * $this->notify($conf, false); // Notify the update of the object * </pre> * * @param IDF_Conf Current configuration * @param bool Creation (true) */ public function notify($conf, $create = true) { $prj = $this->get_project(); $to_email = array(); if ('' != $conf->getVal('issues_notification_email', '')) { $langs = Pluf::f('languages', array('en')); $to_email[] = array($conf->getVal('issues_notification_email'), $langs[0]); } $current_locale = Pluf_Translation::getLocale(); $id = '<' . md5($this->id . md5(Pluf::f('secret_key'))) . '@' . Pluf::f('mail_host', 'localhost') . '>'; if ($create) { if (null != $this->get_owner() and $this->owner != $this->submitter) { $email_lang = array($this->get_owner()->email, $this->get_owner()->language); if (!in_array($email_lang, $to_email)) { $to_email[] = $email_lang; } } $comments = $this->get_comments_list(array('order' => 'id ASC')); $context = new Pluf_Template_Context(array('issue' => $this, 'comment' => $comments[0], 'project' => $prj, 'url_base' => Pluf::f('url_base'))); foreach ($to_email as $email_lang) { Pluf_Translation::loadSetLocale($email_lang[1]); $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Issue %s - %s (%s)'), $this->id, $this->summary, $prj->shortname)); $tmpl = new Pluf_Template('idf/issues/issue-created-email.txt'); $email->addTextMessage($tmpl->render($context)); $email->addHeaders(array('Message-ID' => $id)); $email->sendMail(); } } else { $comments = $this->get_comments_list(array('order' => 'id DESC')); $email_sender = ''; if (isset($comments[0])) { $email_sender = $comments[0]->get_submitter()->email; } foreach ($this->get_interested_list() as $interested) { $email_lang = array($interested->email, $interested->language); if (!in_array($email_lang, $to_email)) { $to_email[] = $email_lang; } } $email_lang = array($this->get_submitter()->email, $this->get_submitter()->language); if (!in_array($email_lang, $to_email)) { $to_email[] = $email_lang; } if (null != $this->get_owner()) { $email_lang = array($this->get_owner()->email, $this->get_owner()->language); if (!in_array($email_lang, $to_email)) { $to_email[] = $email_lang; } } $context = new Pluf_Template_Context(array('issue' => $this, 'comments' => $comments, 'project' => $prj, 'url_base' => Pluf::f('url_base'))); foreach ($to_email as $email_lang) { if ($email_lang[0] == $email_sender) { continue; // Do not notify the one having created // the comment } Pluf_Translation::loadSetLocale($email_lang[1]); $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Updated Issue %s - %s (%s)'), $this->id, $this->summary, $prj->shortname)); $tmpl = new Pluf_Template('idf/issues/issue-updated-email.txt'); $email->addTextMessage($tmpl->render($context)); $email->addHeaders(array('References' => $id)); $email->sendMail(); } } Pluf_Translation::loadSetLocale($current_locale); }
/** * Notification of change of the object. * * @param IDF_Conf Current configuration * @param bool Creation (true) */ public function notify($conf, $create = true) { if ('' == $conf->getVal('downloads_notification_email', '')) { return; } $current_locale = Pluf_Translation::getLocale(); $langs = Pluf::f('languages', array('en')); Pluf_Translation::loadSetLocale($langs[0]); $context = new Pluf_Template_Context(array('file' => $this, 'urlfile' => $this->getAbsoluteUrl($this->get_project()), 'project' => $this->get_project(), 'tags' => $this->get_tags_list())); $tmpl = new Pluf_Template('idf/downloads/download-created-email.txt'); $text_email = $tmpl->render($context); $addresses = explode(',', $conf->getVal('downloads_notification_email')); foreach ($addresses as $address) { $email = new Pluf_Mail(Pluf::f('from_email'), $address, sprintf(__('New download - %s (%s)'), $this->summary, $this->get_project()->shortname)); $email->addTextMessage($text_email); $email->sendMail(); } Pluf_Translation::loadSetLocale($current_locale); }
/** * Send the reminder email. * */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } $account = $this->cleaned_data['account']; $sql = new Pluf_SQL('email=%s OR login=%s', array($account, $account)); $users = Pluf::factory('Pluf_User')->getList(array('filter' => $sql->gen())); $return_url = ''; foreach ($users as $user) { if ($user->active) { $return_url = Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryInputCode'); $tmpl = new Pluf_Template('idf/user/passrecovery-email.txt'); $cr = new Pluf_Crypt(md5(Pluf::f('secret_key'))); $code = trim($cr->encrypt($user->email . ':' . $user->id . ':' . time()), '~'); $code = substr(md5(Pluf::f('secret_key') . $code), 0, 2) . $code; $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecovery', array($code), array(), false); $urlic = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::passwordRecoveryInputCode', array(), array(), false); $context = new Pluf_Template_Context(array('url' => Pluf_Template::markSafe($url), 'urlik' => Pluf_Template::markSafe($urlic), 'user' => Pluf_Template::markSafe($user), 'key' => Pluf_Template::markSafe($code))); $email = new Pluf_Mail(Pluf::f('from_email'), $user->email, __('Password Recovery - InDefero')); $email->setReturnPath(Pluf::f('bounce_email', Pluf::f('from_email'))); $email->addTextMessage($tmpl->render($context)); $email->sendMail(); } if (!$user->active and $user->first_name == '---') { $return_url = Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey'); IDF_Form_Register::sendVerificationEmail($user); } } return $return_url; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } unset($this->cleaned_data['password2']); $update_pass = false; if (strlen($this->cleaned_data['password']) == 0) { unset($this->cleaned_data['password']); } else { $update_pass = true; } $old_email = $this->user->email; $new_email = $this->cleaned_data['email']; unset($this->cleaned_data['email']); if ($old_email != $new_email) { $cr = new Pluf_Crypt(md5(Pluf::f('secret_key'))); $encrypted = trim($cr->encrypt($new_email . ':' . $this->user->id . ':' . time()), '~'); $key = substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2) . $encrypted; $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($key), array(), false); $urlik = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey', array(), array(), false); $context = new Pluf_Template_Context(array('key' => Pluf_Template::markSafe($key), 'url' => Pluf_Template::markSafe($url), 'urlik' => Pluf_Template::markSafe($urlik), 'email' => $new_email, 'user' => $this->user)); $tmpl = new Pluf_Template('idf/user/changeemail-email.txt'); $text_email = $tmpl->render($context); $email = new Pluf_Mail(Pluf::f('from_email'), $new_email, __('Confirm your new email address.')); $email->addTextMessage($text_email); $email->sendMail(); $this->user->setMessage(sprintf(__('A validation email has been sent to "%s" to validate the email address change.'), Pluf_esc($new_email))); } $this->user->setFromFormData($this->cleaned_data); // Add key as needed. if ('' !== $this->cleaned_data['public_key']) { $key = new IDF_Key(); $key->user = $this->user; $key->content = $this->cleaned_data['public_key']; if ($commit) { $key->create(); } } if ($commit) { $this->user->update(); // FIXME: go the extra mile and check the input lengths for // all fields here! // FIXME: this is all doubled in admin/UserUpdate! $user_data = IDF_UserData::factory($this->user); // Add or remove avatar - we need to do this here because every // single setter directly leads to a save in the database if ($user_data->avatar != '' && ($this->cleaned_data['remove_custom_avatar'] == 1 || $this->cleaned_data['custom_avatar'] != '')) { $avatar_path = Pluf::f('upload_path') . '/avatars/' . basename($user_data->avatar); if (basename($avatar_path) != '' && is_file($avatar_path)) { unlink($avatar_path); } $user_data->avatar = ''; } if ($this->cleaned_data['custom_avatar'] != '') { $user_data->avatar = $this->cleaned_data['custom_avatar']; } $user_data->description = $this->cleaned_data['description']; $user_data->twitter = $this->cleaned_data['twitter']; $user_data->public_email = $this->cleaned_data['public_email']; $user_data->website = $this->cleaned_data['website']; if ($update_pass) { /** * [signal] * * Pluf_User::passwordUpdated * * [sender] * * IDF_Form_UserAccount * * [description] * * This signal is sent when the user updated his * password from his account page. * * [parameters] * * array('user' => $user) * */ $params = array('user' => $this->user); Pluf_Signal::send('Pluf_User::passwordUpdated', 'IDF_Form_UserAccount', $params); } } return $this->user; }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } $password = Pluf_Utils::getPassword(); $user = new Pluf_User(); $user->setFromFormData($this->cleaned_data); $user->active = true; $user->staff = false; $user->administrator = false; $user->setPassword($password); $user->create(); /** * [signal] * * Pluf_User::passwordUpdated * * [sender] * * IDF_Form_Admin_UserCreate * * [description] * * This signal is sent when a user is created * by the staff. * * [parameters] * * array('user' => $user) * */ $params = array('user' => $user); Pluf_Signal::send('Pluf_User::passwordUpdated', 'IDF_Form_Admin_UserCreate', $params); // Create the public key as needed if ('' !== $this->cleaned_data['public_key']) { $key = new IDF_Key(); $key->user = $user; $key->content = $this->cleaned_data['public_key']; $key->create(); } // Send an email to the user with the password Pluf::loadFunction('Pluf_HTTP_URL_urlForView'); $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::login', array(), array(), false); $context = new Pluf_Template_Context(array('password' => Pluf_Template::markSafe($password), 'user' => $user, 'url' => Pluf_Template::markSafe($url), 'admin' => $this->request->user)); $tmpl = new Pluf_Template('idf/gadmin/users/createuser-email.txt'); $text_email = $tmpl->render($context); $email = new Pluf_Mail(Pluf::f('from_email'), $user->email, __('Your details to access your forge.')); $email->addTextMessage($text_email); $email->sendMail(); return $user; }
public function timelineFeed($request, $match) { $prj = $request->project; $model_filter = @$match[2]; $model_filter = @$match[2]; $all_model_filters = self::getAvailableModelFilters(); if (!array_key_exists($model_filter, $all_model_filters)) { $model_filter = 'all'; } $title = $all_model_filters[$model_filter]; $classes = self::determineModelClasses($request, $model_filter); $sqls = sprintf('model_class IN (%s)', implode(', ', $classes)); $sql = new Pluf_SQL('project=%s AND ' . $sqls, array($prj->id)); $params = array('filter' => $sql->gen(), 'order' => 'creation_dtime DESC', 'nb' => 20); $items = Pluf::factory('IDF_Timeline')->getList($params); $set = new Pluf_Model_Set($items, array('public_dtime' => 'public_dtime')); $out = array(); foreach ($set as $item) { if ($item->id) { $out[] = $item->feedFragment($request); } } if ($items->count() > 0) { $date = Pluf_Date::gmDateToGmString($items[0]->creation_dtime); } else { $date = gmdate('c'); } $out = Pluf_Template::markSafe(implode("\n", $out)); $tmpl = new Pluf_Template('idf/index.atom'); $feedurl = Pluf::f('url_base') . Pluf::f('idf_base') . $request->query; $viewurl = Pluf_HTTP_URL_urlForView('IDF_Views_Project::timeline', array($prj->shortname)); $context = new Pluf_Template_Context_Request($request, array('body' => $out, 'date' => $date, 'title' => $title, 'feedurl' => $feedurl, 'viewurl' => $viewurl)); return new Pluf_HTTP_Response('<?xml version="1.0" encoding="utf-8"?>' . "\n" . $tmpl->render($context), 'application/atom+xml; charset=utf-8'); }
/** * Render a template file and an array as a reponse. * * If a none null request object is given, the context used will * automatically be a Pluf_Template_Context_Request context and thus * the context will be populated using the * 'template_context_processors' functions. * * @param string Template file name * @param array Associative array for the context * @param Pluf_HTTP_Request Request object (null) * @return Pluf_HTTP_Response The response with the rendered template */ function Pluf_Shortcuts_RenderToResponse($tplfile, $params, $request = null) { $tmpl = new Pluf_Template($tplfile); if (is_null($request)) { $context = new Pluf_Template_Context($params); } else { $context = new Pluf_Template_Context_Request($request, $params); } return new Pluf_HTTP_Response($tmpl->render($context)); }
public function feedFragment($request) { $issue = $this->get_issue(); $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_Issue::view', array($request->project->shortname, $issue->id)); $title = sprintf(__('%s: Comment on issue %d - %s'), Pluf_esc($request->project->name), $issue->id, Pluf_esc($issue->summary)); $url .= '#ic' . $this->id; $date = Pluf_Date::gmDateToGmString($this->creation_dtime); $context = new Pluf_Template_Context_Request($request, array('url' => $url, 'author' => $issue->get_submitter(), 'title' => $title, 'c' => $this, 'issue' => $issue, 'date' => $date)); $tmpl = new Pluf_Template('idf/issues/feedfragment.xml'); return $tmpl->render($context); }
public function feedFragment($request) { $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_Wiki::view', array($request->project->shortname, $this->title)); $title = sprintf(__('%s: Documentation page %s added - %s'), $request->project->name, $this->title, $this->summary); $date = Pluf_Date::gmDateToGmString($this->creation_dtime); $context = new Pluf_Template_Context_Request($request, array('url' => $url, 'title' => $title, 'page' => $this, 'rev' => $this->get_current_revision(), 'create' => true, 'date' => $date)); $tmpl = new Pluf_Template('idf/wiki/feedfragment.xml'); return $tmpl->render($context); }
/** * Registration. * * We just ask for login, email and to agree with the terms. Then, * we go ahead and send a confirmation email. The confirmation * email will allow to set the password, first name and last name * of the user. */ function register($request, $match) { $title = __('Create Your Account'); $params = array('request' => $request); if ($request->method == 'POST') { $form = new IDF_Form_Register($request->POST, $params); if ($form->isValid()) { $user = $form->save(); // It is sending the confirmation email $url = Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey'); return new Pluf_HTTP_Response_Redirect($url); } } else { if (isset($request->GET['login'])) { $params['initial'] = array('login' => $request->GET['login']); } $form = new IDF_Form_Register(null, $params); } $context = new Pluf_Template_Context(array()); $tmpl = new Pluf_Template('idf/terms.html'); $terms = Pluf_Template::markSafe($tmpl->render($context)); return Pluf_Shortcuts_RenderToResponse('idf/register/index.html', array('page_title' => $title, 'form' => $form, 'terms' => $terms), $request); }
public static function sendVerificationEmail($user) { Pluf::loadFunction('Pluf_HTTP_URL_urlForView'); $from_email = Pluf::f('from_email'); $cr = new Pluf_Crypt(md5(Pluf::f('secret_key'))); $encrypted = trim($cr->encrypt($user->email . ':' . $user->id), '~'); $key = substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2) . $encrypted; $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::registerConfirmation', array($key), array(), false); $urlik = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views::registerInputKey', array(), array(), false); $context = new Pluf_Template_Context(array('key' => $key, 'url' => $url, 'urlik' => $urlik, 'user' => $user)); $tmpl = new Pluf_Template('idf/register/confirmation-email.txt'); $text_email = $tmpl->render($context); $email = new Pluf_Mail($from_email, $user->email, __('Confirm the creation of your account.')); $email->addTextMessage($text_email); $email->sendMail(); }
/** * Log the user in. * * The login form is provided by the login_form.html template. * The '_redirect_after' hidden value is used to redirect the user * after successfull login. If the view is called with * _redirect_after set in the query as a GET variable it will be * available as $_redirect_after in the template. * * @param Request Request object * @param array Match * @param string Default redirect URL after login ('/') * @param array Extra context values (array()). * @param string Login form template ('login_form.html') * @return Response object */ function login($request, $match, $success_url = '/', $extra_context = array(), $template = 'login_form.html') { if (!empty($request->REQUEST['_redirect_after'])) { $success_url = $request->REQUEST['_redirect_after']; } $error = ''; if ($request->method == 'POST') { foreach (Pluf::f('auth_backends', array('Pluf_Auth_ModelBackend')) as $backend) { $user = call_user_func(array($backend, 'authenticate'), $request->POST); if ($user !== false) { break; } } if (false === $user) { $error = __('The login or the password is not valid. The login and the password are case sensitive.'); } else { if (!$request->session->getTestCookie()) { $error = __('You need to enable the cookies in your browser to access this website.'); } else { $request->user = $user; $request->session->clear(); $request->session->setData('login_time', gmdate('Y-m-d H:i:s')); $user->last_login = gmdate('Y-m-d H:i:s'); $user->update(); $request->session->deleteTestCookie(); return new Pluf_HTTP_Response_Redirect($success_url); } } } // Show the login form $request->session->createTestCookie(); $context = new Pluf_Template_Context_Request($request, array_merge(array('page_title' => __('Sign In'), '_redirect_after' => $success_url, 'error' => $error), $extra_context)); $tmpl = new Pluf_Template($template); return new Pluf_HTTP_Response($tmpl->render($context)); }
public function notify($conf, $create = true) { if ('' == $conf->getVal('review_notification_email', '')) { return; } $current_locale = Pluf_Translation::getLocale(); $langs = Pluf::f('languages', array('en')); Pluf_Translation::loadSetLocale($langs[0]); $context = new Pluf_Template_Context(array('review' => $this->get_review(), 'patch' => $this, 'comments' => array(), 'project' => $this->get_review()->get_project(), 'url_base' => Pluf::f('url_base'))); $tmpl = new Pluf_Template('idf/review/review-created-email.txt'); $text_email = $tmpl->render($context); $addresses = explode(';', $conf->getVal('review_notification_email')); foreach ($addresses as $address) { $email = new Pluf_Mail(Pluf::f('from_email'), $address, sprintf(__('New Code Review %s - %s (%s)'), $this->get_review()->id, $this->get_review()->summary, $this->get_review()->get_project()->shortname)); $email->addTextMessage($text_email); $email->sendMail(); } Pluf_Translation::loadSetLocale($current_locale); }
public function testRender() { $folders = array(dirname(__FILE__) . '/../Pluf_Template_Compiler/tpl1', dirname(__FILE__) . '/../Pluf_Template_Compiler/tpl2'); $tmpl = new Pluf_Template('tpl-extends.html', $folders); $this->assertEquals("This is the base template\n\nHello blockname\n\ntoto \n\nTemplate base \"Bye bye block2\" here:Bye bye block2", $tmpl->render()); }
/** * Save the model in the database. * * @param bool Commit in the database or not. If not, the object * is returned but not saved in the database. * @return Object Model with data set from the form. */ function save($commit = true) { if (!$this->isValid()) { throw new Exception(__('Cannot save the model from an invalid form.')); } unset($this->cleaned_data['password2']); $update_pass = false; if (strlen($this->cleaned_data['password']) == 0) { unset($this->cleaned_data['password']); } else { $update_pass = true; } $old_email = $this->user->email; $new_email = $this->cleaned_data['email']; unset($this->cleaned_data['email']); if ($old_email != $new_email) { $cr = new Pluf_Crypt(md5(Pluf::f('secret_key'))); $encrypted = trim($cr->encrypt($new_email . ':' . $this->user->id . ':' . time()), '~'); $key = substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2) . $encrypted; $url = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailDo', array($key), array(), false); $urlik = Pluf::f('url_base') . Pluf_HTTP_URL_urlForView('IDF_Views_User::changeEmailInputKey', array(), array(), false); $context = new Pluf_Template_Context(array('key' => Pluf_Template::markSafe($key), 'url' => Pluf_Template::markSafe($url), 'urlik' => Pluf_Template::markSafe($urlik), 'email' => $new_email, 'user' => $this->user)); $tmpl = new Pluf_Template('idf/user/changeemail-email.txt'); $text_email = $tmpl->render($context); $email = new Pluf_Mail(Pluf::f('from_email'), $new_email, __('Confirm your new email address.')); $email->addTextMessage($text_email); $email->sendMail(); $this->user->setMessage(sprintf(__('A validation email has been sent to "%s" to validate the email address change.'), Pluf_esc($new_email))); } $this->user->setFromFormData($this->cleaned_data); // Add key as needed. if ('' !== $this->cleaned_data['ssh_key']) { $key = new IDF_Key(); $key->user = $this->user; $key->content = $this->cleaned_data['ssh_key']; if ($commit) { $key->create(); } } if ($commit) { $this->user->update(); if ($update_pass) { /** * [signal] * * Pluf_User::passwordUpdated * * [sender] * * IDF_Form_UserAccount * * [description] * * This signal is sent when the user updated his * password from his account page. * * [parameters] * * array('user' => $user) * */ $params = array('user' => $this->user); Pluf_Signal::send('Pluf_User::passwordUpdated', 'IDF_Form_UserAccount', $params); } } return $this->user; }
/** * Notify of the update of the review. * * * @param IDF_Conf Current configuration * @param bool Creation (true) */ public function notify($conf, $create = true) { $patch = $this->get_patch(); $review = $patch->get_review(); $prj = $review->get_project(); $to_email = array(); if ('' != $conf->getVal('review_notification_email', '')) { $langs = Pluf::f('languages', array('en')); $to_email[] = array($conf->getVal('issues_notification_email'), $langs[0]); } $current_locale = Pluf_Translation::getLocale(); $reviewers = $review->getReviewers(); if (!Pluf_Model_InArray($review->get_submitter(), $reviewers)) { $reviewers[] = $review->get_submitter(); } $comments = $patch->getFileComments(array('order' => 'id DESC')); $gcomments = $patch->get_comments_list(array('order' => 'id DESC')); $context = new Pluf_Template_Context(array('review' => $review, 'patch' => $patch, 'comments' => $comments, 'gcomments' => $gcomments, 'project' => $prj, 'url_base' => Pluf::f('url_base'))); // build the list of emails and lang foreach ($reviewers as $user) { $email_lang = array($user->email, $user->language); if (!in_array($email_lang, $to_email)) { $to_email[] = $email_lang; } } $tmpl = new Pluf_Template('idf/review/review-updated-email.txt'); foreach ($to_email as $email_lang) { Pluf_Translation::loadSetLocale($email_lang[1]); $email = new Pluf_Mail(Pluf::f('from_email'), $email_lang[0], sprintf(__('Updated Code Review %s - %s (%s)'), $review->id, $review->summary, $prj->shortname)); $email->addTextMessage($tmpl->render($context)); $email->sendMail(); } Pluf_Translation::loadSetLocale($current_locale); }
/** * Notification of change of a WikiPage. * * The content of a WikiPage is in the IDF_WikiRevision object, * this is why we send the notificatin from there. This means that * when the create flag is set, this is for the creation of a * wikipage and not, for the addition of a new revision. * * Usage: * <pre> * $this->notify($conf); // Notify the creation of a wiki page * $this->notify($conf, false); // Notify the update of the page * </pre> * * @param IDF_Conf Current configuration * @param bool Creation (true) */ public function notify($conf, $create = true) { if ('' == $conf->getVal('wiki_notification_email', '')) { return; } $current_locale = Pluf_Translation::getLocale(); $langs = Pluf::f('languages', array('en')); Pluf_Translation::loadSetLocale($langs[0]); $context = new Pluf_Template_Context(array('page' => $this->get_wikipage(), 'rev' => $this, 'project' => $this->get_wikipage()->get_project(), 'url_base' => Pluf::f('url_base'))); if ($create) { $template = 'idf/wiki/wiki-created-email.txt'; $title = sprintf(__('New Documentation Page %s - %s (%s)'), $this->get_wikipage()->title, $this->get_wikipage()->summary, $this->get_wikipage()->get_project()->shortname); } else { $template = 'idf/wiki/wiki-updated-email.txt'; $title = sprintf(__('Documentation Page Changed %s - %s (%s)'), $this->get_wikipage()->title, $this->get_wikipage()->summary, $this->get_wikipage()->get_project()->shortname); } $tmpl = new Pluf_Template($template); $text_email = $tmpl->render($context); $email = new Pluf_Mail(Pluf::f('from_email'), $conf->getVal('wiki_notification_email'), $title); $email->addTextMessage($text_email); $email->sendMail(); Pluf_Translation::loadSetLocale($current_locale); }