예제 #1
0
 private function __construct($session)
 {
     $this->userRepo = UserRepository::create();
     $this->sessionRepo = SessionsRepository::create();
     $this->rolesRepo = UserRolesRepository::create();
     $this->isLogged = self::checkSessionsForLogging($session);
 }
예제 #2
0
 public function login()
 {
     if (isset($_POST['register'])) {
         $this->redirect('users', 'register');
         exit;
     }
     if (isset($_POST['login'])) {
         $username = $_POST['username'];
         $passwordHash = md5($_POST['password']);
         $info = UserRepository::create()->loginCheck($username, $passwordHash);
         if ($info) {
             $_SESSION['userId'] = $info['id'];
             $_SESSION['username'] = $info['username'];
             $_SESSION['email'] = $info['email'];
             $_SESSION['roleId'] = $info['roleId'];
             $_SESSION['cash'] = $info['cash'];
             $_SESSION['userCart'] = CartRepository::create()->getUserCard($info['id']);
             if ($info['roleId'] == 1) {
                 $this->redirect('home', 'userHome');
             }
             if ($info['roleId'] == 2) {
                 $this->redirect('home', 'editorHome');
             }
             $this->redirect('home', 'editorHome');
         }
         echo 'Invalid details';
     }
 }
예제 #3
0
 protected function onLoad()
 {
     $token = time();
     $_SESSION['token'] = $token;
     echo '<form method="post"><input id="token" type="hidden" name="token" value="' . $token . '"></form>';
     $uriParts = explode('/', $_SERVER['REQUEST_URI']);
     $action = $uriParts[count($uriParts) - 1];
     if (!isset($_SESSION['userId']) && $action != 'guestHome') {
         $this->redirect('home', 'guestHome');
         exit;
     }
     if (isset($_SESSION['userId'])) {
         if ($this->loggedUser == null) {
             $this->loggedUser = UserRepository::create()->getOne($_SESSION['userId']);
         }
     }
 }
예제 #4
0
 public function getUserCard($userId)
 {
     $query = "SELECT * FROM carts WHERE carts.ownerId = ?";
     $this->db->query($query, [$userId]);
     $result = $this->db->row();
     $query = "SELECT * FROM  cartsproducts where cartId = ?";
     $this->db->query($query, [$result['id']]);
     $cartProducts = $this->db->fetchAll();
     $productRepo = ProductRepository::create();
     foreach ($cartProducts as $key => $value) {
         $cartProducts[$key]['product'] = $productRepo->getProduct(intval($value['productId']));
     }
     $user = UserRepository::create()->getOne($userId);
     $_SESSION['cash'] = $user['cash'];
     $result['cartProducts'] = $cartProducts;
     return $result;
 }
예제 #5
0
파일: User.php 프로젝트: BarishYumerov/PHP
 public function save()
 {
     return UserRepository::create()->save($this);
 }