当前位置: 首页>>代码示例>>PHP>>正文


PHP Application::csrf方法代码示例

本文整理汇总了PHP中Pagekit\Application::csrf方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::csrf方法的具体用法?PHP Application::csrf怎么用?PHP Application::csrf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pagekit\Application的用法示例。


在下文中一共展示了Application::csrf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: authenticateAction

 /**
  * @Route(methods="POST", defaults={"_maintenance" = true})
  * @Request({"credentials": "array", "remember_me": "boolean", "redirect": "string"})
  */
 public function authenticateAction($credentials, $remember = false, $redirect = '')
 {
     try {
         if (!App::csrf()->validate()) {
             throw new CsrfException(__('Invalid token. Please try again.'));
         }
         App::auth()->authorize($user = App::auth()->authenticate($credentials, false));
         if (($event = App::auth()->login($user, $remember)) && $event->hasResponse()) {
             return $event->getResponse();
         }
         if (App::request()->isXmlHttpRequest()) {
             return App::response()->json(['csrf' => App::csrf()->generate()]);
         } else {
             return App::redirect(preg_replace('#(https?:)?//[^/]+#', '', $redirect));
         }
     } catch (CsrfException $e) {
         if (App::request()->isXmlHttpRequest()) {
             return App::response()->json(['csrf' => App::csrf()->generate()], 401);
         }
         $error = $e->getMessage();
     } catch (BadCredentialsException $e) {
         $error = __('Invalid username or password.');
     } catch (AuthException $e) {
         $error = $e->getMessage();
     }
     if (App::request()->isXmlHttpRequest()) {
         App::abort(401, $error);
     } else {
         App::message()->error($error);
         return App::redirect(preg_replace('#(https?:)?//[^/]+#', '', App::url()->previous()));
     }
 }
开发者ID:nstaeger,项目名称:pagekit,代码行数:36,代码来源:AuthController.php

示例2: confirmAction

 /**
  * @Request({"user", "key"})
  */
 public function confirmAction($username = "", $activation = "")
 {
     if (empty($username) || empty($activation) || !($user = User::where(compact('username', 'activation'))->first())) {
         return $this->messageView(__('Invalid key.'), $success = false);
     }
     if ($user->isBlocked()) {
         return $this->messageView(__('Your account has not been activated or is blocked.'), $success = false);
     }
     $error = '';
     if ('POST' === App::request()->getMethod()) {
         try {
             if (!App::csrf()->validate()) {
                 throw new Exception(__('Invalid token. Please try again.'));
             }
             $password = App::request()->request->get('password');
             if (empty($password)) {
                 throw new Exception(__('Enter password.'));
             }
             if ($password != trim($password)) {
                 throw new Exception(__('Invalid password.'));
             }
             $user->password = App::get('auth.password')->hash($password);
             $user->activation = null;
             $user->save();
             App::message()->success(__('Your password has been reset.'));
             return App::redirect('@user/login');
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     return ['$view' => ['title' => __('Reset Confirm'), 'name' => 'system/user/reset-confirm.php'], 'username' => $username, 'activation' => $activation, 'error' => $error];
 }
开发者ID:nstaeger,项目名称:pagekit,代码行数:35,代码来源:ResetPasswordController.php

示例3: authenticateAction

 /**
  * @Route(methods="POST", defaults={"_maintenance" = true})
  * @Request({"credentials": "array", "_remember_me": "boolean"})
  */
 public function authenticateAction($credentials, $remember = false)
 {
     $isXml = App::request()->isXmlHttpRequest();
     try {
         if (!App::csrf()->validate()) {
             throw new AuthException(__('Invalid token. Please try again.'));
         }
         App::auth()->authorize($user = App::auth()->authenticate($credentials, false));
         if (!$isXml) {
             return App::auth()->login($user, $remember);
         } else {
             App::auth()->setUser($user, $remember);
             return ['success' => true];
         }
     } catch (BadCredentialsException $e) {
         $error = __('Invalid username or password.');
     } catch (AuthException $e) {
         $error = $e->getMessage();
     }
     if (!$isXml) {
         App::message()->error($error);
         return App::redirect(App::url()->previous());
     } else {
         App::abort(400, $error);
     }
 }
开发者ID:aqnouch,项目名称:rimbo,代码行数:30,代码来源:AuthController.php

示例4: authenticateAction

 /**
  * @Route(methods="POST", defaults={"_maintenance" = true})
  * @Request({"credentials": "array"})
  */
 public function authenticateAction($credentials)
 {
     try {
         if (!App::csrf()->validate()) {
             throw new AuthException(__('Invalid token. Please try again.'));
         }
         App::auth()->authorize($user = App::auth()->authenticate($credentials, false));
         return App::auth()->login($user, App::request()->get(Auth::REMEMBER_ME_PARAM));
     } catch (BadCredentialsException $e) {
         App::message()->error(__('Invalid username or password.'));
     } catch (AuthException $e) {
         App::message()->error($e->getMessage());
     }
     return App::redirect(App::url()->previous());
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:19,代码来源:AuthController.php

示例5: registerAction

 /**
  * @Request({"user": "array"})
  */
 public function registerAction($data)
 {
     $message = '';
     try {
         if (App::user()->isAuthenticated() || $this->module->config('registration') == 'admin') {
             return App::redirect();
         }
         if (!App::csrf()->validate()) {
             throw new Exception(__('Invalid token. Please try again.'));
         }
         $password = @$data['password'];
         if (trim($password) != $password || strlen($password) < 6) {
             throw new Exception(__('Password must be 6 characters or longer.'));
         }
         $user = User::create(['registered' => new \DateTime(), 'name' => @$data['name'], 'username' => @$data['username'], 'email' => @$data['email'], 'password' => App::get('auth.password')->hash($password), 'status' => User::STATUS_BLOCKED]);
         $token = App::get('auth.random')->generateString(32);
         $admin = $this->module->config('registration') == 'approval';
         if ($verify = $this->module->config('require_verification')) {
             $user->activation = $token;
         } elseif ($admin) {
             $user->activation = $token;
             $user->set('verified', true);
         } else {
             $user->status = User::STATUS_ACTIVE;
         }
         $user->validate();
         $user->save();
         if ($verify) {
             $this->sendVerificationMail($user);
             $message = __('Complete your registration by clicking the link provided in the mail that has been sent to you.');
         } elseif ($admin) {
             $this->sendApproveMail($user);
             $message = __('Your user account has been created and is pending approval by the site administrator.');
         } else {
             $this->sendWelcomeEmail($user);
             $message = __('Your user account has been created.');
         }
     } catch (Exception $e) {
         App::abort(400, $e->getMessage());
     }
     App::message()->success($message);
     return ['message' => $message, 'redirect' => App::url('@user/login', [], true)];
 }
开发者ID:nstaeger,项目名称:pagekit,代码行数:46,代码来源:RegistrationController.php


注:本文中的Pagekit\Application::csrf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。