Esempio n. 1
0
 public function __initialize(Request $request)
 {
     $this->request = $request;
     if (!$request->hasSession('manager')) {
         if ($request->isXmlHttpRequest()) {
             return new JsonResponse(['code' => 10086, 'msg' => 'Access denied.'], Response::HTTP_FORBIDDEN);
         }
         return $this->redirect($this->generateUrl($this->getParameters('admin-bundle.fail_url')));
     }
     $this->user = $request->getSession('manager');
     return true;
 }
Esempio n. 2
0
 public function signOutAction(Request $request)
 {
     try {
         $redirectUrl = $this->generateUrl($this->getParameters('admin-bundle.logout_url'));
     } catch (\Exception $e) {
         if (!$request->request->has('redirect_url')) {
             throw new ServerInternalErrorException('redirect_url unconfiguration.');
         }
         $redirectUrl = $request->request->get('logout_url');
     }
     $request->clearSession('manager');
     if ($request->hasSession('manager')) {
         if ($request->isXmlHttpRequest()) {
             return new JsonResponse(['code' => 10088, 'msg' => 'Operation fail.'], Response::HTTP_BAD_REQUEST);
         }
         return $this->redirect($redirectUrl);
     }
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['msg' => 'ok']);
     }
     return $this->redirect($redirectUrl);
 }
Esempio n. 3
0
 /**
  * @param Request $request
  * @return array|JsonResponse|\FastD\Http\RedirectResponse
  */
 protected function verifyAccountAndPassword(Request $request)
 {
     $account = $request->request->hasGet('_username', null);
     $password = $request->request->hasGet('_password', null);
     if (empty($account) || empty($password)) {
         if ($request->isXmlHttpRequest()) {
             return new JsonResponse(['code' => 10086, 'msg' => 'Access denied.'], Response::HTTP_FORBIDDEN);
         }
         $url = $request->header->hasGet('REFERER', null);
         if (null === $url) {
             throw new \RuntimeException('Access denied.');
         }
         return $this->redirect($url);
     }
     return ['username' => $account, 'password' => $password];
 }