• Stars
    star
    134
  • Rank 263,346 (Top 6 %)
  • Language
    PHP
  • License
    BSD 3-Clause "New...
  • Created over 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Web UI for Yii's authorization manager.

yii-auth

Auth is a module for the Yii PHP framework 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.

Auth was developed to provide a modern and responsive user interface for managing user permissions in Yii projects. To achieve its goals it was built using my popular Twitter Bootstrap extension.

Auth is written according to Yii's conventions and it follows the separation of concerns priciple 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 here.

Requirements

Usage

Setup

Download the latest release from Yii extensions.

Unzip the module under protected/modules/auth and add the following to your application config:

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).

'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:

'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:

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.

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.

public function filters()
{
  return array(
    array('auth.filters.AuthFilter'),
  );
}

For more information on how filters work refer to the framework documentation on Controllers.

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: Version 1.0.6-wip use and require yiistrap!! yiistrap is next generation yii-bootsrap

More Repositories

1

yiistrap

Twitter Bootstrap for the Yii PHP framework.
PHP
286
star
2

php-conversion

Library for converting units and sizes in PHP
PHP
129
star
3

yii-app

A great way to start building your web application with the Yii PHP framework.
CSS
110
star
4

capthatflag

A fast-paced multiplayer capture the flag game written in JavaScript.
CSS
45
star
5

ctf-game

Fast-paced hot seat multiplayer game written in modern JavaScript.
JavaScript
31
star
6

yii-imagemanager

Image manager extension for the Yii PHP framework.
PHP
23
star
7

overseer

Framework agnostic RBAC implementation in PHP
PHP
18
star
8

php-shortid

Library for generating short non-sequential unique identifiers in PHP
PHP
14
star
9

yii-configbuilder

Helper for building application configurations for the Yii PHP framework.
PHP
12
star
10

yii-sentry

Sentry for the Yii PHP framework.
PHP
10
star
11

yii-formatter

A collection of formatters for the Yii PHP framework.
PHP
10
star
12

yii-caviar

Next generation code generation for Yii.
PHP
10
star
13

yiistrap2

Yiistrap for Yii2.
PHP
10
star
14

yii-less

Yii extension for compiling LESS files client and server-side.
PHP
9
star
15

yii-consoletools

A collection of tools for developing console commands for Yii.
PHP
8
star
16

yii-clientscript

A more advanced version of the client script component in Yii.
PHP
6
star
17

yii-seo

Search engine optimization for the Yii PHP framework.
PHP
6
star
18

yii-filemanager

File manager for the Yii PHP framework.
PHP
6
star
19

hubot-twitch

Twitch.tv adapter for Hubot
CoffeeScript
5
star
20

webpack-minimal

Minimalistic Webpack setup with Babel
JavaScript
4
star
21

yii-cms

A modular content management system for the Yii PHP framework.
PHP
3
star
22

hello

A JavaScript powered portfolio for developers.
CSS
3
star
23

yiistrap-widgets

Extension library for Yiistrap.
PHP
3
star
24

php-expression

A modest library for safe evaluation of PHP expressions.
PHP
3
star
25

yii-extension

A starting point for extensions for the Yii PHP framework.
PHP
3
star
26

acolyte

Your personal Twitch robot
JavaScript
2
star
27

yii-i18nattributes

Attribute translations for the Yii PHP framework.
PHP
2
star
28

yii-arbehaviors

A collection of active record behaviors for the Yii PHP framework.
PHP
2
star
29

memory

Memory game for children build with Phaser.
JavaScript
2
star
30

yii-app-advanced

A more advanced version of yii-app https://github.com/Crisu83/yii-app
CSS
2
star
31

react-restricted

Permission-based view restrictions for React.
TypeScript
2
star
32

yii-rights

Automatically exported from code.google.com/p/yii-rights
PHP
2
star
33

yii-globals

Global shorthand functions for commonly used Yii methods.
PHP
2
star
34

yii-image

Image versioning and manipulation for the Yii PHP framework.
PHP
2
star
35

twentyfour-symfony-backbone

Time tracking application built with Symfony2 and Backbone.js.
JavaScript
2
star
36

yii-debug

Debugging tools for the Yii PHP framework.
PHP
1
star
37

foosball-android

Android application for tracking foosball game statistics.
Java
1
star
38

announce

Application for posting announcements.
CSS
1
star
39

rabbitmq-domain-events

A proof of concept implementation of publishing and subscribing to domain events using RabbitMQ.
TypeScript
1
star
40

space-game

A space game developed with Hatchet, a component based game engine for WinJS.
JavaScript
1
star
41

yii-multilingual

Multilingual toolkit for the Yii PHP framework.
PHP
1
star
42

shocker-scripts

A collection of my personal docker shell scripts.
Shell
1
star
43

php-vm

A scalable project template for any PHP application
1
star
44

covid19-graphql

GraphQL API for querying data about Covid-19 across the world.
TypeScript
1
star
45

crisu83

My GitHub profile
1
star
46

yii-ajaxtools

AJAX tools for the Yii PHP framework.
PHP
1
star
47

yiistrap-docs

Documentation for Yiistrap, Twitter Bootstrap for the Yii PHP framework
PHP
1
star
48

yii-composer

Composer callbacks for the Yii PHP framework.
PHP
1
star
49

yii-livereload

Extension for the Yii PHP framework that registers with the Grunt livereload server.
PHP
1
star