Skip to content

Commit

Permalink
fix status
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Feb 7, 2016
1 parent af004f7 commit a64bf9a
Show file tree
Hide file tree
Showing 34 changed files with 2,430 additions and 1,622 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/dictionaries/hafid.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

735 changes: 735 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions .idea/yii2-mimin.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

namespace hscstudio\mimin;

/**
* Class Module
* @package hscstudio\mimin
*/
class Module extends \yii\base\Module
{
/**
* @var string
*/
public $controllerNamespace = 'hscstudio\mimin\controllers';

/**
*
*/
public function init()
{
parent::init();
Expand Down
202 changes: 101 additions & 101 deletions components/AccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,116 +30,116 @@
*/
class AccessControl extends \yii\base\ActionFilter
{
/**
* @var User User for check access.
*/
private $_user = 'user';
/**
* @var User User for check access.
*/
private $_user = 'user';

/**
* @var array List of action that not need to check access.
*/
public $allowActions = [];
/**
* @var array List of action that not need to check access.
*/
public $allowActions = [];

/**
* Get user
* @return User
*/
public function getUser()
{
if (!$this->_user instanceof User) {
$this->_user = Instance::ensure($this->_user, User::className());
}
return $this->_user;
}
/**
* Get user
* @return User
*/
public function getUser()
{
if (!$this->_user instanceof User) {
$this->_user = Instance::ensure($this->_user, User::className());
}
return $this->_user;
}

/**
* Set user
* @param User|string $user
*/
public function setUser($user)
{
$this->_user = $user;
}
/**
* Set user
* @param User|string $user
*/
public function setUser($user)
{
$this->_user = $user;
}

/**
* @inheritdoc
*/
public function beforeAction($action)
{
$actionId = $action->getUniqueId();
$user = $this->getUser();
if ($user->can('/' . $actionId)) {
return true;
}
$obj = $action->controller;
do {
if ($user->can('/' . ltrim($obj->getUniqueId() . '/*', '/'))) {
return true;
}
$obj = $obj->module;
} while ($obj !== null);
$this->denyAccess($user);
}
/**
* @inheritdoc
*/
public function beforeAction($action)
{
$actionId = $action->getUniqueId();
$user = $this->getUser();
if ($user->can('/' . $actionId)) {
return true;
}
$obj = $action->controller;
do {
if ($user->can('/' . ltrim($obj->getUniqueId() . '/*', '/'))) {
return true;
}
$obj = $obj->module;
} while ($obj !== null);
$this->denyAccess($user);
}

/**
* Denies the access of the user.
* The default implementation will redirect the user to the login page if he is a guest;
* if the user is already logged, a 403 HTTP exception will be thrown.
* @param yii\web\User $user the current user
* @throws yii\web\ForbiddenHttpException if the user is already logged in.
*/
protected function denyAccess($user)
{
if ($user->getIsGuest()) {
$user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
}
}
/**
* Denies the access of the user.
* The default implementation will redirect the user to the login page if he is a guest;
* if the user is already logged, a 403 HTTP exception will be thrown.
* @param yii\web\User $user the current user
* @throws yii\web\ForbiddenHttpException if the user is already logged in.
*/
protected function denyAccess($user)
{
if ($user->getIsGuest()) {
$user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
}
}

/**
* @inheritdoc
*/
protected function isActive($action)
{
$uniqueId = $action->getUniqueId();
if ($uniqueId === Yii::$app->getErrorHandler()->errorAction) {
return false;
}
/**
* @inheritdoc
*/
protected function isActive($action)
{
$uniqueId = $action->getUniqueId();
if ($uniqueId === Yii::$app->getErrorHandler()->errorAction) {
return false;
}

$user = $this->getUser();
if ($user->getIsGuest() && is_array($user->loginUrl) && isset($user->loginUrl[0]) && $uniqueId === trim($user->loginUrl[0], '/')) {
return false;
}
$user = $this->getUser();
if ($user->getIsGuest() && is_array($user->loginUrl) && isset($user->loginUrl[0]) && $uniqueId === trim($user->loginUrl[0], '/')) {
return false;
}

if ($this->owner instanceof Module) {
// convert action uniqueId into an ID relative to the module
$mid = $this->owner->getUniqueId();
$id = $uniqueId;
if ($mid !== '' && strpos($id, $mid . '/') === 0) {
$id = substr($id, strlen($mid) + 1);
}
} else {
$id = $action->id;
}
if ($this->owner instanceof Module) {
// convert action uniqueId into an ID relative to the module
$mid = $this->owner->getUniqueId();
$id = $uniqueId;
if ($mid !== '' && strpos($id, $mid . '/') === 0) {
$id = substr($id, strlen($mid) + 1);
}
} else {
$id = $action->id;
}

foreach ($this->allowActions as $route) {
if (substr($route, -1) === '*') {
$route = rtrim($route, "*");
if ($route === '' || strpos($id, $route) === 0) {
return false;
}
} else {
if ($id === $route) {
return false;
}
}
}
foreach ($this->allowActions as $route) {
if (substr($route, -1) === '*') {
$route = rtrim($route, "*");
if ($route === '' || strpos($id, $route) === 0) {
return false;
}
} else {
if ($id === $route) {
return false;
}
}
}

if ($action->controller->hasMethod('allowAction') && in_array($action->id, $action->controller->allowAction())) {
return false;
}
if ($action->controller->hasMethod('allowAction') && in_array($action->id, $action->controller->allowAction())) {
return false;
}

return true;
}
return true;
}
}
Loading

0 comments on commit a64bf9a

Please sign in to comment.