function delete()
 {
     UserSession::signOut();
     $this->respondTo('html', function () {
         $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'index');
     });
 }
Example #2
0
 protected function getCommonData()
 {
     $userSession = UserSession::getInstance();
     $signedIn = $userSession->isSignedIn();
     $replacements = ['user' => $signedIn ? $userSession->getUser() : new User(), 'is_signed_in' => $signedIn, 'basket' => Basket::getInstance($userSession)];
     return $replacements;
 }
Example #3
0
 function create()
 {
     try {
         $user = User::create($this->getRequest()->request);
         UserSession::getInstance()->signInWithUser($user);
         $this->respondTo('html', function () use($user) {
             $data['user'] = $user;
             $this->render(new View\TwigView('user/registered.html', $data));
         });
     } catch (ValidationException $e) {
         $this->respondTo('html', function () use($e) {
             $this->getResponse()->redirect('App\\Auth\\Controllers\\SessionController', 'signIn');
         });
     }
 }
 public function rate($id)
 {
     $this->respondTo('html', function () use($id) {
         try {
             $userSession = UserSession::getInstance();
             if (!$userSession->isSignedIn()) {
                 throw new ActionNotAuthorizedException();
             }
             Rating::create($userSession->getUser(), Product::find($id), $this->getRequest()->getParams());
             $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]);
         } catch (ResourceNotFoundException $e) {
             $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]);
         } catch (ValidationException $e) {
             $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]);
         } catch (DuplicateResourceException $e) {
             $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]);
         } catch (ActionNotAuthorizedException $e) {
             $this->getResponse()->redirect('App\\Store\\Controllers\\ProductController', 'show', [$id]);
         }
     });
 }
 public function buy()
 {
     $this->respondTo('html', function () {
         try {
             $userSession = UserSession::getInstance();
             if (!$userSession->isSignedIn()) {
                 throw new ActionNotAuthorizedException();
             }
             $basket = Basket::getInstance($userSession);
             if ($basket->isEmpty()) {
                 $this->getResponse()->redirect('App\\Store\\Controllers\\BasketController', 'index');
                 return;
             }
             $order = Order::create($basket, $userSession->getUser());
             $basket->clear();
             $data = array_merge($this->getCommonData(), ['order' => $order]);
             $this->render(new TwigView('basket/success.html', $data));
         } catch (ActionNotAuthorizedException $e) {
             $this->getResponse()->redirect('App\\Auth\\Controllers\\SessionController', 'signIn');
         }
     });
 }