Exemple #1
0
 /**
  * creates a new user and stores basic data in the database.
  *
  * @param  string  $login   Login name
  * @param  string  $pass    Password
  * @param  integer $user_id User ID
  * @return mixed
  */
 public function createUser($login, $pass = '', $user_id = 0)
 {
     foreach ($this->auth_container as $auth) {
         if (!$this->checkAuth($auth)) {
             return false;
         }
     }
     // is $login valid?
     $login = (string) $login;
     if (!$this->isValidLogin($login)) {
         return false;
     }
     // does $login already exist?
     if ($this->getUserByLogin($login, false)) {
         $this->errors[] = self::ERROR_USER_LOGIN_NOT_UNIQUE;
         return false;
     }
     // set user-ID
     if (0 == $user_id) {
         $this->user_id = (int) $this->db->nextID(SQLPREFIX . 'faquser', 'user_id');
     } else {
         $this->user_id = $user_id;
     }
     // create user entry
     $insert = sprintf("\n            INSERT INTO\n                %sfaquser\n            (user_id, login, session_timestamp, member_since)\n                VALUES\n            (%d, '%s', %d, '%s')", SQLPREFIX, $this->getUserId(), $this->db->escape_string($login), $_SERVER['REQUEST_TIME'], date('YmdHis', $_SERVER['REQUEST_TIME']));
     $this->db->query($insert);
     if (!$this->userdata instanceof PMF_User_UserData) {
         $this->userdata = new PMF_User_UserData($this->db);
     }
     $data = $this->userdata->add($this->getUserId());
     if (!$data) {
         $this->errors[] = self::ERROR_USER_CANNOT_CREATE_USERDATA;
         return false;
     }
     // create authentication entry
     if ($pass == '') {
         $pass = $this->createPassword();
     }
     $success = false;
     foreach ($this->auth_container as $name => $auth) {
         if ($auth->setReadOnly()) {
             continue;
         }
         if (!$auth->add($login, $pass)) {
             $this->errors[] = self::ERROR_USER_CANNOT_CREATE_USER . 'in PMF_Auth ' . $name;
         } else {
             $success = true;
         }
     }
     if (!$success) {
         return false;
     }
     $this->perm->autoJoin($this->user_id);
     return $this->getUserByLogin($login, false);
 }