Tak wykonuje rejestracje:
$token = $u->setInactive(); 'zarejestrowanie się.</strong></p><p>Należy pamiętać o zweryfikowaniu konta i kliknąć w łącze załączone w mailu który sotał wysłany';
Dodaje pomyślnie dane do bazy.
Gorzej jest z pobraniem id zarejestrowanego użytkownika. (jak wysyłam maila to potrzebuje te dane)
pobieram tak:
$user->userId;
nic nie zwraca
Klasa:
<? class User extends functions { public $uid; protected $sql; public $userId; public function __construct($sql) { $this->sql = $sql; $this->uid = null; 'password' => '', 'emailAddr' => '', 'gg' => '', 'imie' => '', 'nazwisko' => '', 'isActive' => false); } public function __get($field) { if($field == 'userId') { return $this->uid; } else { return $this->fields[$field]; } } public function __set($field, $value) { { $this->fields[$field] = $value; } } public function validateUserName($username) { { } else { return true; } { } else { return true; } } public function validateEmailAddr($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); if(false) { } } public function getById($uid) { $db = $this->sql; $u = new User($db); $sql = $db->query('select * from users where user_id = "'.$uid.'"'); if($sql->num_rows) { $row = $sql->fetch_array(); $u->username = $row['username']; $u->password = $row['password']; $u->emailAddr = $row['email_addr']; $u->isActive = $row['is_active']; $u->imie = $row['imie']; $u->nazwisko = $row['nazwisko']; $u->uid = $uid; } return $u; } public function getByUsername($username) { $db = $this->sql; $u = new User($db); $sql = $db->query('select * from users where username = "'.$username.'" and is_active = 1'); if($sql->num_rows) { $row = $sql->fetch_array(); $u->password = $row['password']; $u->username = $row['username']; $u->emailAddr = $row['email_addr']; $u->isActive = $row['is_active']; $u->imie = $row['imie']; $u->nazwisko = $row['nazwisko']; $u->uid = $row['user_id']; } return $u; } public function save() { $db = $this->sql; if($this->uid) { $sql = $db->query('update USERS set username = "'.$this->username.'", password = "'.$this->password.'", email_addr = "'.$this->emailAddr.'", is_active = "'.$this->isActive.'" where user_id = "'.$this->userId.'"'); } else { $sql = $db->query('insert into users (username, password, email_addr, is_active, gg,imie,nazwisko,data) values ("'.$this->username.'", "'.sha1($this->password).'", "'.$this->emailAddr.'", "0", if(!$sql) { } } } public function setInactive() { $db = $this->sql; $this->isActive = false; $this->save(); $token = $this->random_text(5); $sql = $db->query('insert into users_pending (user_id, token) values ("'.$this->uid.'", "'.$token.'")'); return $token; } public function setActive($token) { $db = $this->sql; $sql = $db->query('select token from users_pending where user_id = "'.$this->uid.'" and token = "'.$token.'"'); if(!$sql->num_rows) { return false; } else { $sql = $db->query('delete from users_pending where user_id = "'.$this->uid.'" and token = "'.$this->token.'"'); $this->isAdcive = true; $this->save(); return true; } } }