Example #1
0
 public static function factory($user)
 {
     $conf = new IDF_UserData();
     $conf->setModel((object) array('_model' => 'IDF_UserData', 'id' => $user->id));
     $conf->initCache();
     return $conf;
 }
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;
     }
     $this->user->setFromFormData($this->cleaned_data);
     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 UserAccount!
         $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_Admin_UserUpdate', $params);
         }
     }
     return $this->user;
 }
Example #3
0
 /**
  * Public profile of a user.
  */
 public function view($request, $match)
 {
     $sql = new Pluf_SQL('login=%s', array($match[1]));
     $users = Pluf::factory('Pluf_User')->getList(array('filter' => $sql->gen()));
     if (count($users) != 1 or !$users[0]->active) {
         throw new Pluf_HTTP_Error404();
     }
     $user = $users[0];
     $user_data = IDF_UserData::factory($user);
     return Pluf_Shortcuts_RenderToResponse('idf/user/public.html', array('page_title' => (string) $user, 'member' => $user, 'user_data' => $user_data), $request);
 }
Example #4
0
 public function get_submitter_data()
 {
     return IDF_UserData::factory($this->get_submitter());
 }
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;
 }