Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("MODE_GUEST",0);
- define("MODE_USER",1);
- define("MODE_ADMIN",2);
- class User{
- private $id;
- private $email;
- private $haslo;
- private $construct;
- private $nazwa;
- private $opis;
- private $avatar;
- private $mode;
- public function __construct($anonim = true){
- if($anonim == true)
- {
- $this -> id = 0;
- $this -> login = '';
- $this -> password = '';
- $this -> nazwa = 'Anonim';
- $this -> opis = '';
- $this -> avatar = '';
- $this -> mode = MODE_GUEST;
- }
- $this -> construct = true;
- }
- public function isAnonymous()
- {
- return ($this -> id == MODE_GUEST ? true : false);
- }
- public function isAdmin()
- {
- return ($this -> mode == MODE_ADMIN ? true : false);
- }
- public function getId()
- {
- return $this -> id;
- }
- public function getEmail()
- {
- return $this -> email;
- }
- public function getHaslo()
- {
- return $this -> haslo;
- }
- public function getOpis()
- {
- return $this -> opis;
- }
- public function getAvatar()
- {
- return $this -> avatar;
- }
- public function getNazwa()
- {
- return $this -> nazwa;
- }
- public function getMode()
- {
- return $this -> mode;
- }
- public function __set($name, $value)
- {
- global $pdo;
- if($this -> construct)
- {
- $this -> $name = $value;
- $stmt = $pdo -> prepare('UPDATE '.MySql_TPrefix.'users SET
- '.$name.' = :value WHERE id = :id');
- $stmt -> bindValue(':value', $value, PDO::PARAM_STR);
- $stmt -> bindValue(':id', $this->getId(), PDO::PARAM_INT);
- $stmt -> execute();
- }
- }
- static public function Sprawdz($email, $password)
- {
- global $pdo;
- $stmt = $pdo -> prepare('SELECT id, email, nazwa, haslo, opis, avatar, mode FROM '.MySql_TPrefix.'users WHERE email=:email AND haslo=:haslo');
- $stmt -> bindValue(':email', $email, PDO::PARAM_STR);
- $stmt -> bindValue(':haslo', sha1(md5('@TuJestBardzo_').md5($password).md5('_TrudnaSol@')), PDO::PARAM_STR);
- $stmt -> execute();
- $stmt -> setFetchMode(PDO::FETCH_CLASS, 'User', array(0 => false));
- if($user = $stmt -> fetch())
- {
- // Jezeli uzytkownik o takim loginie i hasle
- // istnieje, zwroc jego rekord w postaci obiektu
- $stmt -> closeCursor();
- return $user;
- }
- else
- {
- $stmt -> closeCursor();
- // Bledy w loginie/hasle zglaszamy zerem
- return 0;
- }
- }
- static public function Rejestruj ($email, $password, $nazwa)
- {
- global $pdo;
- $result = User::Sprawdz($email, $password);
- if($result instanceof user){ return false; }
- $stmt = $pdo -> prepare('INSERT INTO '.MySql_TPrefix.'users (email, haslo, mode, nazwa) VALUES (:email, :haslo, :mode, :nazwa)');
- $stmt -> bindValue(':email', $email, PDO::PARAM_STR);
- $stmt -> bindValue(':haslo', sha1(md5('@TuJestBardzo_').md5($password).md5('_TrudnaSol@')), PDO::PARAM_STR);
- $stmt -> bindValue(':mode', MODE_USER, PDO::PARAM_INT);
- $stmt -> bindValue(':nazwa', $nazwa, PDO::PARAM_STR);
- $ile = $stmt -> execute();
- if($ile > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement