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


PHP Application::abort方法代码示例

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


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

示例1: editAction

 /**
  * @Route("/edit")
  * @Request({"id"})
  */
 public function editAction($id = '')
 {
     /** @var \Bixie\Formmaker\FormmakerModule $formmaker */
     $formmaker = App::module('bixie/formmaker');
     if (is_numeric($id)) {
         $field = Field::find($id);
     } else {
         $field = Field::create();
         $field->setFieldType($id);
     }
     if (!$field) {
         App::abort(404, __('Field not found.'));
     }
     if (!($type = $formmaker->getFieldType($field->type))) {
         App::abort(404, __('Type not found.'));
     }
     //default values
     $fixedFields = ['multiple', 'required'];
     if (!$field->id) {
         foreach ($type->getConfig() as $key => $value) {
             if (!in_array($key, $fixedFields)) {
                 $field->set($key, $value);
             }
         }
     }
     //check fixed value
     foreach ($fixedFields as $key) {
         if ($type[$key] != -1) {
             $field->set($key, $type[$key]);
         }
     }
     return ['field' => $field, 'type' => $type, 'roles' => array_values(Role::findAll())];
 }
开发者ID:Eichi,项目名称:pagekit-formmaker,代码行数:37,代码来源:FieldApiController.php

示例2: requestAction

 /**
  * @Request({"email": "string"})
  */
 public function requestAction($email)
 {
     try {
         if (App::user()->isAuthenticated()) {
             return App::redirect();
         }
         if (!App::csrf()->validate()) {
             throw new Exception(__('Invalid token. Please try again.'));
         }
         if (empty($email)) {
             throw new Exception(__('Enter a valid email address.'));
         }
         if (!($user = User::findByEmail($email))) {
             throw new Exception(__('Unknown email address.'));
         }
         if ($user->isBlocked()) {
             throw new Exception(__('Your account has not been activated or is blocked.'));
         }
         $user->activation = App::get('auth.random')->generateString(32);
         $url = App::url('@user/resetpassword/confirm', ['user' => $user->username, 'key' => $user->activation], 0);
         try {
             $mail = App::mailer()->create();
             $mail->setTo($user->email)->setSubject(__('Reset password for %site%.', ['%site%' => App::module('system/site')->config('title')]))->setBody(App::view('system/user:mails/reset.php', compact('user', 'url', 'mail')), 'text/html')->send();
         } catch (\Exception $e) {
             throw new Exception(__('Unable to send confirmation link.'));
         }
         $user->save();
         return ['message' => __('Check your email for the confirmation link.')];
     } catch (Exception $e) {
         App::abort(400, $e->getMessage());
     }
 }
开发者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: match

 /**
  * {@inheritdoc}
  */
 public function match(array $parameters = [])
 {
     if (isset($parameters['id'])) {
         return $parameters;
     }
     if (!isset($parameters['slug'])) {
         App::abort(404, 'Project not found.');
     }
     $slug = $parameters['slug'];
     $id = false;
     foreach ($this->cacheEntries as $entry) {
         if ($entry['slug'] === $slug) {
             $id = $entry['id'];
         }
     }
     if (!$id) {
         if (!($project = Project::where(compact('slug'))->first())) {
             App::abort(404, 'Project not found.');
         }
         $this->addCache($project);
         $id = $project->id;
     }
     $parameters['id'] = $id;
     return $parameters;
 }
开发者ID:4nxiety,项目名称:pagekit-portfolio,代码行数:28,代码来源:UrlResolver.php

示例5: confirmAction

 /**
  * @Request({"user", "key"})
  */
 public function confirmAction($username = "", $activation = "")
 {
     if (empty($username) || empty($activation) || !($user = User::where(compact('username', 'activation'))->first())) {
         App::abort(400, __('Invalid key.'));
     }
     if ($user->isBlocked()) {
         App::abort(400, __('Your account has not been activated or is blocked.'));
     }
     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' => isset($error) ? $error : ''];
 }
开发者ID:pagekit,项目名称:pagekit,代码行数:34,代码来源:ResetPasswordController.php

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

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

示例8: deleteAction

 /**
  * @Route("/{id}", methods="DELETE", requirements={"id"="\d+"})
  * @Request({"id": "int"}, csrf=true)
  */
 public function deleteAction($id)
 {
     if (!($widget = Widget::find($id))) {
         App::abort(404, 'Widget not found.');
     }
     $widget->delete();
     return ['message' => 'success'];
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:12,代码来源:WidgetApiController.php

示例9: saveAction

 /**
  * @Request({"id", "data"}, csrf=true)
  */
 public function saveAction($id, $data)
 {
     if (!$id || !($record = TestBD::find($id))) {
         App::abort(404, __('Record not found.'));
     }
     $record->save($data);
     return ['res' => 'success'];
 }
开发者ID:anjey58,项目名称:pagekit_todo_bd,代码行数:11,代码来源:ToDoBDAjaxController.php

示例10: indexAction

 public function indexAction($id = 0)
 {
     if (!($page = Page::find($id))) {
         App::abort(404, __('Page not found.'));
     }
     $page->content = App::content()->applyPlugins($page->content, ['page' => $page, 'markdown' => $page->get('markdown')]);
     return ['$view' => ['title' => $page->title, 'name' => 'system/site/page.php'], 'page' => $page, 'node' => App::node()];
 }
开发者ID:pagekit,项目名称:pagekit,代码行数:8,代码来源:PageController.php

示例11: adminMenuAction

 /**
  * @Access(admin=true)
  * @Request({"order": "array"})
  */
 public function adminMenuAction($order)
 {
     if (!$order) {
         App::abort(400, __('Missing order data.'));
     }
     $user = User::find(App::user()->id);
     $user->set('admin.menu', $order);
     $user->save();
     return ['message' => __('Order saved.')];
 }
开发者ID:pagekit,项目名称:pagekit,代码行数:14,代码来源:AdminController.php

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

示例13: editAction

 /**
  * @Access("user: manage users")
  * @Request({"id": "int"})
  */
 public function editAction($id = 0)
 {
     if (!$id) {
         $user = User::create(['roles' => [Role::ROLE_AUTHENTICATED]]);
     } else {
         if (!($user = User::find($id))) {
             App::abort(404, 'User not found.');
         }
     }
     return ['$view' => ['title' => $id ? __('Edit User') : __('Add User'), 'name' => 'system/user/admin/user-edit.php'], '$data' => ['user' => $user, 'config' => ['statuses' => User::getStatuses(), 'roles' => array_values($this->getRoles($user)), 'emailVerification' => App::module('system/user')->config('require_verification'), 'currentUser' => App::user()->id]]];
 }
开发者ID:rifal89,项目名称:pagekit,代码行数:15,代码来源:UserController.php

示例14: editAction

 /**
  * @Request({"id": "int", "type": "string"})
  */
 public function editAction($id = 0, $type = null)
 {
     if (!$id) {
         $widget = Widget::create(['type' => $type]);
     } else {
         if (!($widget = Widget::find($id))) {
             App::abort(404, 'Widget not found.');
         }
     }
     return ['$view' => ['title' => __('Widgets'), 'name' => 'system/widget/edit.php'], '$data' => ['widget' => $widget, 'config' => ['menus' => App::menu(), 'nodes' => array_values(Node::query()->get()), 'roles' => array_values(Role::findAll()), 'types' => array_values(App::widget()->all()), 'positions' => array_values(App::position()->all())]]];
 }
开发者ID:pagekit,项目名称:pagekit,代码行数:14,代码来源:WidgetController.php

示例15: onLateRequest

 /**
  * Reads the access expressions and evaluates them on the current user.
  */
 public function onLateRequest($event, $request)
 {
     if (!($access = $request->attributes->get('_access'))) {
         return;
     }
     foreach ($access as $expression) {
         if (!App::user()->hasAccess($expression)) {
             App::abort(403, __('Insufficient User Rights.'));
         }
     }
 }
开发者ID:LibraryOfLawrence,项目名称:pagekit,代码行数:14,代码来源:AccessListener.php


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