-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial release based on original Yii-Auth extension developed by @cn…
…iska
- Loading branch information
Showing
1,986 changed files
with
651,586 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea/* | ||
demo/assets/* | ||
demo/protected/config/main.php | ||
demo/protected/runtime/* | ||
releases/* | ||
composer* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
/** | ||
* AuthModule class file. | ||
* @author Ricardo Obregón <ricardo@obregon.co> | ||
* @author Christoffer Niska <ChristofferNiska@gmail.com> | ||
* @copyright Copyright © Christoffer Niska 2012- | ||
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License | ||
* @package auth | ||
* @version 1.6.0 | ||
*/ | ||
|
||
/** | ||
* Web module for managing Yii's built-in authorization manager (CAuthManager). | ||
*/ | ||
class AuthModule extends CWebModule | ||
{ | ||
/** | ||
* @var boolean whether to enable the RBAC strict mode. | ||
* When enabled items cannot be assigned children of the same type. | ||
*/ | ||
public $strictMode = true; | ||
/** | ||
* @var string name of the user model class. | ||
* Change this if your user model name is different than the default value. | ||
*/ | ||
public $userClass = 'User'; | ||
/** | ||
* @var string name of the user id column. | ||
* Change this if the id column in your user table is different than the default value. | ||
*/ | ||
public $userIdColumn = 'id'; | ||
/** | ||
* @var string name of the user name column. | ||
* Change this if the name column in your user table is different than the default value. | ||
*/ | ||
public $userNameColumn = 'name'; | ||
/** | ||
* @var string the application layout. | ||
* Change this if you wish to use a different layout with the module. | ||
*/ | ||
public $defaultLayout = 'application.views.layouts.main'; | ||
/** | ||
* @var array map of flash message keys to use for the module. | ||
*/ | ||
public $flashKeys = array(); | ||
/** | ||
* @var string string the id of the default controller for this module. | ||
*/ | ||
public $defaultController = 'assignment'; | ||
/** | ||
* @var boolean whether to force copying of assets. | ||
* Useful during development and when upgrading the module. | ||
*/ | ||
public $forceCopyAssets = false; | ||
/** | ||
* @var string path to view files for this module. | ||
* Specify this to use your own views instead of those shipped with the module. | ||
*/ | ||
public $viewDir; | ||
|
||
private $_assetsUrl; | ||
|
||
/** | ||
* Initializes the module. | ||
*/ | ||
public function init() | ||
{ | ||
$this->setImport( | ||
array( | ||
'auth.components.*', | ||
'auth.controllers.*', | ||
'auth.models.*', | ||
'auth.widgets.*', | ||
) | ||
); | ||
|
||
$this->registerCss(); | ||
|
||
$this->flashKeys = array_merge( | ||
$this->flashKeys, | ||
array( | ||
'error' => 'error', | ||
'info' => 'info', | ||
'success' => 'success', | ||
'warning' => 'warning', | ||
) | ||
); | ||
|
||
if (isset($this->viewDir)) { | ||
if (strpos($this->viewDir, '.')) { | ||
$this->viewDir = Yii::getPathOfAlias($this->viewDir); | ||
} | ||
|
||
$this->setLayoutPath($this->viewDir . DIRECTORY_SEPARATOR . 'layouts'); | ||
$this->setViewPath($this->viewDir); | ||
} | ||
} | ||
|
||
/** | ||
* Registers the module CSS. | ||
*/ | ||
public function registerCss() | ||
{ | ||
Yii::app()->clientScript->registerCssFile($this->getAssetsUrl() . '/css/auth.css'); | ||
} | ||
|
||
/** | ||
* The pre-filter for controller actions. | ||
* @param CController $controller the controller. | ||
* @param CAction $action the action. | ||
* @return boolean whether the action should be executed. | ||
* @throws CException|CHttpException if user is denied access. | ||
*/ | ||
public function beforeControllerAction($controller, $action) | ||
{ | ||
if (parent::beforeControllerAction($controller, $action)) { | ||
$user = Yii::app()->getUser(); | ||
|
||
if ($user instanceof AuthWebUser) { | ||
if ($user->isAdmin) { | ||
return true; | ||
} elseif ($user->isGuest) { | ||
$user->loginRequired(); | ||
} | ||
} else { | ||
throw new CException('WebUser component is not an instance of AuthWebUser.'); | ||
} | ||
} | ||
throw new CHttpException(401, Yii::t('AuthModule.main', 'Access denied.')); | ||
} | ||
|
||
/** | ||
* Returns the URL to the published assets folder. | ||
* @return string the URL. | ||
*/ | ||
protected function getAssetsUrl() | ||
{ | ||
if (isset($this->_assetsUrl)) { | ||
return $this->_assetsUrl; | ||
} else { | ||
$assetsPath = Yii::getPathOfAlias('auth.assets'); | ||
$assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, $this->forceCopyAssets); | ||
|
||
return $this->_assetsUrl = $assetsUrl; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the module version number. | ||
* @return string the version. | ||
*/ | ||
public function getVersion() | ||
{ | ||
return '1.6.0'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Copyright (c) 2013, Ricardo Obregón | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of the Ricardo Obregón nor the | ||
names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,121 @@ | ||
authbooster | ||
=========== | ||
Auth-Booster | ||
======== | ||
|
||
Auth Module for YiiFramework comaptible with YiiBooster | ||
Originally developed by Christoffer Niska (aka @cniska) but since Auth is not now compatible anymore with Yii-Booster I decided to create a fork with all the power of Yii-Auth + Yii-Booster compatibility. | ||
|
||
AuthBooster is a module for the [Yii PHP framework](http://www.yiiframework.com) that provides a web user interface for Yii's built-in authorization manager (CAuthManager). | ||
You can read more about Yii's authorization manager in the framework documentation under [Authentication and Authorization](http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#role-based-access-control). | ||
|
||
AuthBooster is developed to provide a modern and responsive user interface for managing user permissions in Yii projects. | ||
To achieve its goals it was built using [Twitter Bootstrap extension YiiBooster](http://www.yiiframework.com/extension/yiibooster). | ||
|
||
AuthBooster is written according to Yii's conventions and it follows the [separation of concerns](http://en.wikipedia.org/wiki/Separation_of_concerns) principle and therefore it doesn't require you to extend from its classes. | ||
Instead it provides additional functionality for the authorization manager through a single behavior. | ||
|
||
### Demo | ||
|
||
You can try out the live demo (soon). | ||
|
||
### Requirements | ||
|
||
* [Twitter Bootstrap extension for Yii](http://www.yiiframework.com/extension/yiibooster) version 1.0.7 or above | ||
|
||
## Usage | ||
|
||
### Setup | ||
|
||
Download the latest release from [Yii extensions](http://www.yiiframework.com/extension/authbooster). | ||
|
||
Unzip the module under ***protected/modules/auth*** and add the following to your application config: | ||
|
||
```php | ||
return array( | ||
'modules' => array( | ||
'auth', | ||
), | ||
'components' => array( | ||
'authManager' => array( | ||
..... | ||
'behaviors' => array( | ||
'auth' => array( | ||
'class' => 'auth.components.AuthBehavior', | ||
), | ||
), | ||
), | ||
'user' => array( | ||
'class' => 'auth.components.AuthWebUser', | ||
'admins' => array('admin', 'foo', 'bar'), // users with full access | ||
), | ||
), | ||
); | ||
``` | ||
***protected/config/main.php*** | ||
|
||
Please note that while the module doesn't require you to use a database, if you wish to use ***CDbAuthManager*** you need it's schema (it can be found in the framework under web/auth). | ||
|
||
### Configuration | ||
|
||
Configure the module to suit your needs. Here's a list of the available configurations (with default values). | ||
|
||
```php | ||
'auth' => array( | ||
'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type. | ||
'userClass' => 'User', // the name of the user model class. | ||
'userIdColumn' => 'id', // the name of the user id column. | ||
'userNameColumn' => 'name', // the name of the user name column. | ||
'defaultLayout' => 'application.views.layouts.main', // the layout used by the module. | ||
'viewDir' => null, // the path to view files to use with this module. | ||
), | ||
``` | ||
|
||
#### Enabling caching | ||
|
||
To enable caching for ***CDbAuthManager*** you can use ***CachedDbAuthManager*** that provides caching for access checks. | ||
Here's an example configuration for the component: | ||
|
||
```php | ||
'authManager'=>array( | ||
'class'=>'auth.components.CachedDbAuthManager', | ||
'cachingDuration'=>3600, | ||
), | ||
``` | ||
|
||
### Checking access | ||
|
||
When you wish to check if the current user has a certain permission you can use the ***CWebUser::checkAccess()*** method which can be access from anywhere in your application through ***Yii::app()*** like so: | ||
|
||
```php | ||
if (Yii::app()->user->checkAccess('itemName')) // itemName = name of the operation | ||
{ | ||
// access is allowed. | ||
} | ||
``` | ||
|
||
In order to keep your permissions dynamic you should never check for a specific role or task, instead you should always check for an operation. | ||
For more information on Yii's authorization manager refer to the framework documentation on [Authentication and Authorization](http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#role-based-access-control). | ||
|
||
#### Checking access using a filter | ||
|
||
You can also use a filter to automatically check access before controller actions are called. | ||
Operations used with this filter has to be named as follows ***(moduleId.)controllerId.actionId***, where ***moduleId*** is optional. | ||
You can also use a wildcard ***controllerId.**** instead of the actionId to cover all actions in the controller or ***module.**** instead of the controllerId to cover all controllers in the module. | ||
|
||
```php | ||
public function filters() | ||
{ | ||
return array( | ||
array('auth.filters.AuthFilter'), | ||
), | ||
} | ||
``` | ||
|
||
For more information on how filters work refer to the framework documentation on [Controllers](http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#filter). | ||
|
||
### Internationalization | ||
|
||
Do you wish to provide a translation for Auth? If so, please do a pull request for it. | ||
Translations should be placed in the messages folder under a folder named according to its locale (e.g. en_us). | ||
|
||
### Note | ||
|
||
Note: This version DOES NOT require yiistrap!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.auth-module h1 { | ||
margin: 0 0 30px; | ||
} | ||
|
||
.auth-module h3 { | ||
line-height: 100%; | ||
} | ||
|
||
.auth-module small { | ||
color: #888; | ||
} | ||
|
||
.auth-module .title-row .btn-group { | ||
margin-bottom: 12px; | ||
} | ||
|
||
.auth-module .detail-view .null { | ||
color: #888; | ||
} | ||
|
||
.auth-module .disabled { | ||
color: #888; | ||
} | ||
|
||
.auth-module .item-description-column { | ||
width: 65%; | ||
} | ||
|
||
.auth-module .actions-column { | ||
width: 30px; | ||
} | ||
|
||
.auth-module .assignment-items-column { | ||
width: 580px; | ||
} |
Oops, something went wrong.