Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: SUNNY
- * Date: 30. 9. 2016
- * Time: 23:05
- */
- class User
- {
- public function __construct()
- {
- // TBA
- }
- public function register($email, $fname, $lname, $pass)
- {
- $hpass = password_hash($pass, PASSWORD_DEFAULT);
- $this->checkIdentifiers($email);
- $this->checkIdentifiers($fname);
- $this->checkIdentifiers($lname);
- // Tu sa este skontroluje, ci sa email nenachadza v DB, ak nie tak .
- // INSERT INTO users (email, first_name, last_name, password) VALUES (?, ?, ?, ?));
- }
- public function login($email, $pass)
- {
- // Tu vyberiem z DB heslo zo zadaneho emailu a skontrolujem, ci sedi nizsie
- $password = $pass;
- $hpassword = ''; // toto sa vyberie z DB
- password_verify($password, $hpassword);
- setcookie('username', $email, time() + (86400 * 30), '/');
- }
- public function logout()
- {
- if(isset($_COOKIE['username']))
- setcookie('username', '', time()-7000000, '/');
- }
- // Metóda zisťujúca, či je uživateľ príhlasený, ak áno vráti true
- public function isLogged()
- {
- if(isset($_COOKIE['username']))
- return true;
- return false;
- }
- // V prípade ak uživateľ bude prihlásený, tak ho presmerujeme na danú URL
- public function redirect($url)
- {
- header('Location:' . $url);
- }
- private function checkIdentifiers($identifiers)
- {
- foreach ($identifiers as $identifier)
- {
- if (!preg_match('/^[a-zA-Z0-9\_\-]+$/u', $identifier))
- throw new Exception('Dangerous identifier in SQL query');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement