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


PHP Application::auth方法代码示例

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


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

示例1: saveAction

 /**
  * @Request({"user": "array"}, csrf=true)
  */
 public function saveAction($data)
 {
     $user = App::user();
     if (!$user->isAuthenticated()) {
         App::abort(404);
     }
     try {
         $user = User::find($user->id);
         if ($password = @$data['password_new']) {
             if (!App::auth()->getUserProvider()->validateCredentials($user, ['password' => @$data['password_old']])) {
                 throw new Exception(__('Invalid Password.'));
             }
             if (trim($password) != $password || strlen($password) < 3) {
                 throw new Exception(__('Invalid Password.'));
             }
             $user->password = App::get('auth.password')->hash($password);
         }
         if (@$data['email'] != $user->email) {
             $user->set('verified', false);
         }
         $user->name = @$data['name'];
         $user->email = @$data['email'];
         $user->validate();
         $user->save();
         return ['message' => 'success'];
     } catch (Exception $e) {
         App::abort(400, $e->getMessage());
     }
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:32,代码来源:ProfileController.php

示例2: 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

示例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: logoutAction

 /**
  * @Response("json")
  * @Request({"credentials": "array"})
  */
 public function logoutAction($credentials)
 {
     try {
         $user = App::auth()->getUserProvider()->findByUsername($credentials["username"]);
         App::auth()->logout($user);
         return ['success' => true, 'message' => "You are disconnected"];
     } catch (AuthException $e) {
         return ['success' => false, 'message' => "An error has occurred"];
     }
 }
开发者ID:sdaoudi,项目名称:rimbo,代码行数:14,代码来源:ApiController.php

示例5: detailsAction

 /**
  * @Access("userprofile: view profiles")
  * @Route("/{id}", methods="GET", name="id")
  * @Request({"id": "int"})
  */
 public function detailsAction($id)
 {
     if (!($user = App::auth()->getUserProvider()->find((int) $id)) or !($profileUser = ProfileUser::load($user))) {
         App::abort(404, __('User not found.'));
     }
     if ($breadcrumbs = App::module('bixie/breadcrumbs')) {
         $breadcrumbs->addUrl(['title' => $user->name, 'url' => '']);
     }
     return ['$view' => ['title' => __('User Profile'), 'name' => 'bixie/userprofile/profile-details.php'], '$data' => [], 'config' => App::module('bixie/userprofile')->config(), 'profileUser' => $profileUser, 'node' => App::node()];
 }
开发者ID:Bixie,项目名称:pagekit-userprofile,代码行数:15,代码来源:ProfilesController.php

示例6: 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

示例7: generate

 /**
  * {@inheritdoc}
  */
 public function generate(array $parameters = [])
 {
     $id = $parameters['id'];
     $slug_key = App::module('bixie/userprofile')->config('slug_key', 'username');
     if (!isset($this->cacheEntries[$id])) {
         if (!($user = App::auth()->getUserProvider()->find((int) $id))) {
             throw new RouteNotFoundException('Userprofile not found!');
         }
         $this->addCache($user);
     }
     $meta = $this->cacheEntries[$id];
     $parameters['slug'] = $meta[$slug_key];
     unset($parameters['id']);
     return $parameters;
 }
开发者ID:Bixie,项目名称:pagekit-userprofile,代码行数:18,代码来源:UrlResolver.php

示例8: onRequest

 /**
  * Checks for the "system: access admin area" and redirects to login.
  */
 public function onRequest($event, $request)
 {
     if (App::auth()->getUser() or !in_array('system: access admin area', $request->attributes->get('_access', []))) {
         return;
     }
     $params = [];
     // redirect to default URL for POST requests and don't explicitly redirect the default URL
     if ('POST' !== $request->getMethod() && $request->attributes->get('_route') != '@system') {
         $params['redirect'] = App::url()->current(true);
     }
     $event->setResponse(App::response()->redirect('@system/login', $params));
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:15,代码来源:AccessListener.php

示例9: onRequest

 /**
  * Logout blocked users.
  */
 public function onRequest()
 {
     if ($user = App::auth()->getUser() and $user->isBlocked()) {
         App::auth()->logout();
     }
 }
开发者ID:itplanes,项目名称:pagekit,代码行数:9,代码来源:AuthorizationListener.php


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