/**
  * @param UserBindingModel $user
  * @throws \Exception
  * @Route("register")
  */
 public function registerUser(UserBindingModel $user)
 {
     if ($_POST['csrf'] !== $_SESSION["token"]) {
         http_response_code(400);
         ob_end_clean();
         echo "CSRF not matching error";
         die;
     }
     if (!$user->modelState()->isValid()) {
         http_response_code(400);
         ob_end_clean();
         var_dump($user->modelState()->get());
         die;
         //throw new \Exception('Model state not valid');
     }
     $userExists = $this->_usersRepo->findByUsername($user->getUsername());
     if (!is_null($userExists)) {
         http_response_code(400);
         ob_end_clean();
         $username = $userExists->getUsername();
         echo "Username {$username} already taken";
         die;
     }
     $this->_usersRepo->create($user);
     $newUser = $this->_usersRepo->findByUsername($user->getUsername());
     $_SESSION['is_logged'] = true;
     $_SESSION['user_id'] = $newUser->getId();
     $_SESSION['username'] = $newUser->getUsername();
     $_SESSION['role_id'] = $newUser->getRoleId();
 }
 public function create(UserBindingModel $user)
 {
     // Insert or update the $user
     // in the 'users' table
     $this->db->insertEntity('users', array('username' => $user->getUsername(), 'password' => $user->getPassword(), 'email' => $user->getEmail(), 'cash' => $user->getCash(), 'role_id' => $user->getRoleId()));
 }