Ejemplo n.º 1
0
 public function save($commit = true)
 {
     if (!$this->isValid()) {
         throw new Exception(__('Cannot save the model from an invalid form.'));
     }
     // remove all the permissions
     $perm = Pluf_Permission::getFromString('IDF.project-authorized-user');
     $cm = $this->project->getMembershipData();
     $guser = new Pluf_User();
     foreach ($cm['authorized'] as $user) {
         Pluf_RowPermission::remove($user, $this->project, $perm);
     }
     if ($this->cleaned_data['private_project']) {
         foreach (preg_split("/\r\n|\r|\n|\\,/", $this->cleaned_data['authorized_users'], -1, PREG_SPLIT_NO_EMPTY) as $login) {
             $sql = new Pluf_SQL('login=%s', array(trim($login)));
             $users = $guser->getList(array('filter' => $sql->gen()));
             if ($users->count() == 1) {
                 Pluf_RowPermission::add($users[0], $this->project, $perm);
             }
         }
         $this->project->private = 1;
     } else {
         $this->project->private = 0;
     }
     $this->project->update();
     $this->project->membershipsUpdated();
 }
Ejemplo n.º 2
0
 /**
  * Just a simple control.
  */
 public function clean_key()
 {
     $this->cleaned_data['key'] = trim($this->cleaned_data['key']);
     $error = __('We are sorry but this confirmation key is not valid. Maybe you should directly copy/paste it from your confirmation email.');
     if (false === ($email_id = IDF_Form_RegisterInputKey::checkKeyHash($this->cleaned_data['key']))) {
         throw new Pluf_Form_Invalid($error);
     }
     $guser = new Pluf_User();
     $sql = new Pluf_SQL('email=%s AND id=%s', $email_id);
     $users = $guser->getList(array('filter' => $sql->gen()));
     if ($users->count() != 1) {
         throw new Pluf_Form_Invalid($error);
     }
     if ($users[0]->active) {
         throw new Pluf_Form_Invalid(__('This account has already been confirmed. Maybe should you try to recover your password using the help link.'));
     }
     $this->_user_id = $email_id[1];
     return $this->cleaned_data['key'];
 }
Ejemplo n.º 3
0
 /**
  * The update of the memberships is done in different places. This
  * avoids duplicating code.
  *
  * @param IDF_Project The project
  * @param array The new memberships data in 'owners' and 'members' keys
  */
 public static function updateMemberships($project, $cleaned_data)
 {
     // remove all the permissions
     $cm = $project->getMembershipData();
     $def = array('owners' => Pluf_Permission::getFromString('IDF.project-owner'), 'members' => Pluf_Permission::getFromString('IDF.project-member'));
     $guser = new Pluf_User();
     foreach ($def as $key => $perm) {
         foreach ($cm[$key] as $user) {
             Pluf_RowPermission::remove($user, $project, $perm);
         }
         foreach (preg_split("/\r\n|\r|\n|\\,/", $cleaned_data[$key], -1, PREG_SPLIT_NO_EMPTY) as $login) {
             $sql = new Pluf_SQL('login=%s', array(trim($login)));
             $users = $guser->getList(array('filter' => $sql->gen()));
             if ($users->count() == 1) {
                 Pluf_RowPermission::add($users[0], $project, $perm);
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Based on the given string, try to find the matching user.
  *
  * Search order is: email, login, last_name.
  *
  * If no user found, simply returns null.
  *
  * @param string User
  * @return Pluf_User or null
  */
 public static function findUser($string)
 {
     $string = trim($string);
     if (strlen($string) == 0) {
         return null;
     }
     $guser = new Pluf_User();
     foreach (array('email', 'login', 'last_name') as $what) {
         $sql = new Pluf_SQL($what . '=%s', $string);
         $users = $guser->getList(array('filter' => $sql->gen()));
         if ($users->count() > 0) {
             return $users[0];
         }
     }
     return null;
 }