Example #1
0
 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;
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * 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);
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * 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);
 }
Example #6
0
 /**
  * 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);
 }
Example #7
0
 /**
  * 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);
 }
Example #8
0
 /**
  * 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;
 }
Example #9
0
 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);
 }
Example #10
0
 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();
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * 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);
 }