Example #1
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 #2
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 #3
0
 /**
  * Generate the token for the feed.
  *
  * @param IDF_Project
  * @param Pluf_User
  * @return string Token
  */
 public static function genFeedToken($project, $user)
 {
     $cr = new Pluf_Crypt(md5(Pluf::f('secret_key')));
     $encrypted = trim($cr->encrypt($user->id . ':' . $project->id), '~');
     return substr(md5(Pluf::f('secret_key') . $encrypted), 0, 2) . $encrypted;
 }
Example #4
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 #5
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;
 }