mvccore/ext-auth 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mvccore/ext-auth

Composer 安装命令:

composer require mvccore/ext-auth

包简介

MvcCore - Extension - Auth - authentication module with automatic authentication module type detection by loaded classes.

README 文档

README

Latest Stable Version License PHP Version

Authentication module with automatic authentication module type detection by loaded classes.

Installation

composer require mvccore/ext-auth

Usage

Add this to Bootstrap.php or to very application beginning, before application routing.

\MvcCore\Ext\Auth::GetInstance()
	->SetPasswordHashSalt('s9E56/QH6!a69sJML9aS$6s+')
	->SetUserClass('\\MvcCore\\Ext\\Auths\\Users\\SystemConfig');

For system config users, you need to specify users in system.ini like this:

[users]
0.userName		= admin
0.fullName		= Administrator
0.passwordHash	= $2y$10$czlFNTYvUUg2IWE2OXNKTO8PB5xPGXz9i8IH7Fa7M0YsPlSLriJZu
; admin password is `demo`

To get sign in form into view in your application controller:

...
	public function IndexAction () {
		if ($this->user !== NULL)
			self::Redirect($this->Url('administration_index_page'));
		$this->view->SignInForm = \MvcCore\Ext\Auth::GetInstance()
			->GetSignInForm()
			->SetValues(array(// set signed in url to administration index page by default:
				'successUrl' => $this->Url('administration_index_page'),
			));
	}
...

To get sign out form into view in your application controller:

...
	public function PreDispatch () {
		parent::PreDispatch();
		if ($this->viewEnabled && $this->user) {
			$this->view->SignOutForm =\MvcCore\Ext\Auth::GetInstance()
				->GetSignOutForm()
				->SetValues(array(
					'successUrl' => $this->Url('login_page')
				));
		}
	}
...

For any forms CSRF errors - you can call in base controller Init() action:

...
	public function Init() {
		parent::Init();
		// when any CSRF token is outdated or not the same - sign out user by default
		$this->application->AddSecurityErrorHandler(function (\MvcCore\IRequest $req, \MvcCore\IResponse $res, ?\MvcCore\Ext\Form $form = NULL) {
			\MvcCore\Ext\Auth\User::LogOut();
			self::Redirect($this->Url(
				'Index:Index',
				array('absolute' => TRUE, 'sourceUrl'	=> rawurlencode($form->ErrorUrl))
			));
		});
	}
...

To translate your signin and signout form visible elements, use:

\MvcCore\Ext\Auth::GetInstance()->SetTranslator(function ($key, $lang = NULL) {
	// your custom translator model/service:
	return \App\Models\Translator::GetInstance()->Translate($key, $lang);
});

统计信息

  • 总下载量: 3.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2017-01-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固