Example #1
0
 public function signup($username, $password1, $password2, $alias, $email)
 {
     if (!is_null($this->auth_token)) {
         throw new DBException('already logged in');
     }
     $username = $this->db->safe($username);
     $password1 = $this->db->safe($password1);
     $password2 = $this->db->safe($password2);
     $alias = $this->db->safe($alias);
     $email = $this->db->safe($email);
     $sql = sprintf("SELECT username FROM users WHERE username='******'", $username);
     if ($this->db->exists($sql)) {
         throw new DBException('username already exists');
     }
     if (!$this->valid_alias($alias)) {
         throw new DBException('invalid characters in alias');
     }
     if ($password1 != $password2) {
         throw new DBException('passwords do not match');
     }
     if (!validate::email($email)) {
         throw new DBException('invalid email');
     }
     $salt = sha1($username);
     $password_hash = sha1($password1 . $salt);
     $email_hash = md5($email);
     $sql = sprintf("INSERT INTO users (username,alias,email,email_hash,\n\t\t\t\t\t\tpassword,salt,joindate) VALUES ('%s','%s','%s','%s',\n\t\t\t\t\t\t'%s','%s',UNIX_TIMESTAMP())", $username, $alias, $email, $email_hash, $password_hash, $salt);
     $this->db->autocommit(FALSE);
     if (!($uid = $this->db->insert($sql))) {
         throw new DBException('failed query when adding user' . $sql);
     }
     if (!($nsid = $this->ns->add($alias, True))) {
         debug_hook('failed to add user namespace');
         throw new DBException('failed to add user namespace');
     }
     if (!$this->ns->acl_add($nsid, $uid, ACL_READ | ACL_WRITE | ACL_ADMIN)) {
         debug_hook('failed to add namespace privileges');
         debug_hook('error: ' . $this->db->error . $this->db->errno);
         throw new DBException('failed to set user namespace permissions');
     }
     if (!$this->ns->acl_add(DB_PUBNS, $uid, ACL_READ | ACL_WRITE)) {
         debug_hook('failed to add user to public namespace');
         throw new DBException('failed to set global namespace permissions');
     }
     $this->db->commit();
     $this->login($username, $password1);
 }
Example #2
0
File: user.php Project: ascseb/auth
 /**
  * Allows a model to be loaded by username or email address.
  */
 public function unique_key($id)
 {
     if (!empty($id) and is_string($id) and !ctype_digit($id)) {
         return validate::email($id) ? 'email' : 'username';
     }
     return parent::unique_key($id);
 }
Example #3
0
 /**
  * Allows a model to be loaded by username or email address.
  */
 public function unique_key($id)
 {
     if (!empty($id) and is_string($id) and !ctype_digit($id)) {
         return validate::email($id) ? 'email' : 'username';
     }
     return $this->_primary_key;
 }