本文整理汇总了PHP中Pagekit\Application::redirect方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::redirect方法的具体用法?PHP Application::redirect怎么用?PHP Application::redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagekit\Application
的用法示例。
在下文中一共展示了Application::redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginAction
/**
* @Route("/admin/login", defaults={"_maintenance"=true})
* @Request({"redirect": "string", "message": "string"})
*/
public function loginAction($redirect = '', $message = '')
{
if (App::user()->isAuthenticated()) {
return App::redirect('@system');
}
return ['$view' => ['title' => __('Login'), 'name' => 'system/theme:views/login.php', 'layout' => false], 'last_username' => App::session()->get(Auth::LAST_USERNAME), 'redirect' => $redirect ?: App::url('@system'), 'message' => $message];
}
示例2: indexAction
/**
* @Route("site/page", name="page")
* @Access("site: manage site", admin=true)
*/
public function indexAction()
{
if ($test = Node::fixOrphanedNodes()) {
return App::redirect('@site/page');
}
return ['$view' => ['title' => __('Pages'), 'name' => 'system/site/admin/index.php'], '$data' => ['config' => ['menus' => App::menu()->getPositions()], 'types' => array_values($this->site->getTypes())]];
}
示例3: 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()));
}
}
示例4: 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];
}
示例5: loginAction
/**
* @Route("/admin/login", defaults={"_maintenance"=true})
*/
public function loginAction()
{
if (App::user()->isAuthenticated()) {
return App::redirect('@system');
}
return ['$view' => ['title' => __('Login'), 'name' => 'system/theme:views/login.php', 'layout' => false], 'last_username' => App::session()->get(Auth::LAST_USERNAME), 'redirect' => App::request()->get('redirect') ?: App::url('@system', [], true), 'remember_me_param' => Auth::REMEMBER_ME_PARAM];
}
示例6: categoriesAction
/**
* @Route("categories", name="admin/categories")
* @Access("download: manage categories")
*/
public function categoriesAction()
{
if ($test = Category::fixOrphanedCategories()) {
return App::redirect('@download/categories');
}
return ['$view' => ['title' => __('Categories'), 'name' => 'bixie/download/admin/categories.php'], '$data' => []];
}
示例7: 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);
}
}
示例8: indexAction
public function indexAction()
{
$user = App::user();
if (!$user->isAuthenticated()) {
return App::redirect('@user/login', ['redirect' => App::url()->current()]);
}
return ['$view' => ['title' => __('Your Profile'), 'name' => 'system/user/profile.php'], '$data' => ['user' => ['name' => $user->name, 'email' => $user->email]]];
}
示例9: registrationAction
/**
* registration override page
* @Route("/registration")
*/
public function registrationAction()
{
$user = App::user();
$userprofile = App::module('bixie/userprofile');
if ($user->isAuthenticated()) {
return App::redirect('@userprofile');
}
return ['$view' => ['title' => __('User registration'), 'name' => 'bixie/userprofile/registration.php'], '$data' => ['config' => $userprofile->config(), 'user' => ['id' => null, 'username' => '', 'name' => '', 'email' => '']]];
}
示例10: migrateAction
/**
* @Request({"redirect": "string"}, csrf=true)
*/
public function migrateAction($redirect = null)
{
if ($updates = $this->scripts->hasUpdates()) {
$this->scripts->update();
$message = __('Your Pagekit database has been updated successfully.');
} else {
$message = __('Your database is up to date.');
}
App::config('system')->set('version', App::version());
if ($redirect) {
App::message()->success($message);
return App::redirect($redirect);
}
return App::response()->json(compact('status', 'message'));
}
示例11: 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());
}
示例12: migrateAction
/**
* @Request({"redirect": "string"}, csrf=true)
*/
public function migrateAction($redirect = null)
{
$config = App::config('system');
$manager = new PackageManager();
$scripts = $manager->loadScripts(null, __DIR__ . '/../../scripts.php');
if (isset($scripts['updates'])) {
$updates = $manager->filterUpdates($scripts['updates'], $config->get('version'));
$manager->execute($updates);
}
$config->set('version', App::version());
$message = __('Your Pagekit database has been updated successfully.');
if ($redirect) {
App::message()->success($message);
return App::redirect($redirect);
}
return App::response()->json(compact('status', 'message'));
}
示例13: editAction
/**
* @Route("/project/edit", name="project/edit")
* @Access("portfolio: manage portfolio")
* @Request({"id": "int"})
*/
public function editAction($id = 0)
{
try {
if (!($project = Project::where(compact('id'))->first())) {
if ($id) {
App::abort(404, __('Invalid project id.'));
}
$module = App::module('bixie/portfolio');
$project = Project::create(['data' => [], 'tags' => [], 'date' => new \DateTime()]);
$project->set('markdown', $module->config('markdown'));
}
return ['$view' => ['title' => $id ? __('Edit Project') : __('Add Project'), 'name' => 'bixie/portfolio/admin/project.php'], '$data' => ['config' => App::module('bixie/portfolio')->config(), 'project' => $project, 'tags' => Project::allTags()], 'project' => $project];
} catch (\Exception $e) {
App::message()->error($e->getMessage());
return App::redirect('@portfolio/post');
}
}
示例14: editAction
/**
* @Route("/post/edit", name="post/edit")
* @Access("blog: manage own posts || blog: manage all posts")
* @Request({"id": "int"})
*/
public function editAction($id = 0)
{
try {
if (!($post = Post::where(compact('id'))->related('user')->first())) {
if ($id) {
App::abort(404, __('Invalid post id.'));
}
$module = App::module('blog');
$post = Post::create(['user_id' => App::user()->id, 'status' => Post::STATUS_DRAFT, 'date' => new \DateTime(), 'comment_status' => (bool) $module->config('posts.comments_enabled')]);
$post->set('title', $module->config('posts.show_title'));
$post->set('markdown', $module->config('posts.markdown_enabled'));
}
$user = App::user();
if (!$user->hasAccess('blog: manage all posts') && $post->user_id !== $user->id) {
App::abort(403, __('Insufficient User Rights.'));
}
$roles = App::db()->createQueryBuilder()->from('@system_role')->where(['id' => Role::ROLE_ADMINISTRATOR])->whereInSet('permissions', ['blog: manage all posts', 'blog: manage own posts'], false, 'OR')->execute('id')->fetchAll(\PDO::FETCH_COLUMN);
$authors = App::db()->createQueryBuilder()->from('@system_user')->whereInSet('roles', $roles)->execute('id, username')->fetchAll();
return ['$view' => ['title' => $id ? __('Edit Post') : __('Add Post'), 'name' => 'blog/admin/post-edit.php'], '$data' => ['post' => $post, 'statuses' => Post::getStatuses(), 'roles' => array_values(Role::findAll()), 'canEditAll' => $user->hasAccess('blog: manage all posts'), 'authors' => $authors], 'post' => $post];
} catch (\Exception $e) {
App::message()->error($e->getMessage());
return App::redirect('@blog/post');
}
}
示例15: activateAction
/**
* @Request({"user", "key"})
*/
public function activateAction($username, $activation)
{
if (empty($username) || empty($activation) || !($user = User::where(['username' => $username, 'activation' => $activation, 'status' => User::STATUS_BLOCKED, 'access IS NULL'])->first())) {
App::message()->error(__('Invalid key.'));
return App::redirect();
}
if ($admin = $this->module->config('registration') == 'approval' and !$user->get('verified')) {
$user->activation = App::get('auth.random')->generateString(32);
$this->sendApproveMail($user);
App::message()->success(__('Your email has been verified. Once an administrator approves your account, you will be notified by email.'));
} else {
$user->set('verified', true);
$user->status = User::STATUS_ACTIVE;
$user->activation = '';
$this->sendWelcomeEmail($user);
if ($admin) {
App::message()->success(__('The user\'s account has been activated and the user has been notified about it.'));
} else {
App::message()->success(__('Your account has been activated.'));
}
}
$user->save();
return App::redirect('@user/login');
}