Ejemplo n.º 1
0
 public function create(RegisterBindingModel $user)
 {
     if ($user->getPassword() != $user->getConfirmPassword()) {
         throw new InvalidUserInputException('Passwords does not match');
     }
     $isCreated = $this->db->insertEntity(self::USERS_TABLENAME, array('username' => $user->getUsername(), 'password' => password_hash($user->getPassword(), AppConfig::PASSWORD_CRYPT_METHOD), 'email' => $user->getEmail(), 'cash' => $user->getCash(), 'role_id' => $user->getRole()));
     return $isCreated;
 }
 /**
  * @param BindModels\RegisterBindingModel $userModel
  * @Route("register")
  */
 public function registerUser(BindModels\RegisterBindingModel $userModel)
 {
     $userModel->setCash(self::DEFAULT_USER_CASH);
     $userModel->setRole(AppUserRolesConfig::DEFAULT_USER_ROLE);
     $isRegistered = $this->_eshopData->getUsersRepository()->create($userModel);
     if ($isRegistered) {
         $user = $this->_eshopData->getUsersRepository()->findByUsername($userModel->getUsername());
         $this->_eshopData->getCartsRepository()->create($user->getId());
         $data = ["username" => $userModel->getUsername(), "password" => $userModel->getPassword()];
         $loginDetails = new BindModels\LoginBindingModel($data);
         $this->loginUser($loginDetails);
     }
     //TODO throw more meaningful error message
     echo 'Register failed';
 }