Difference between #4 and #8 of
Implementing a User Level Access System

Changes

Title unchanged

Implementing a User Level Access System

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

tutorial, Authentication, tips

Content changed

[...]
Please note that this article is a simple example and good security should be taken into account when we play with authentication systems.

### Step 1. Setting up
a. **Include a field on your user’s table** named, yep you guessed, level
b. **Create an object ‘LevelLookUp’** that will tell us who is who on this system
(create LevelLookUp.php inside protected/component/)
[...]
{
$username = strtolower($this->username);
// from database... change to suit
e your authentication criteria
// -- Nope, I wont include mine --
$user = User::model()->find('LOWER(username)=?', array($username));
[...]
return false;
}
// saving logged users into a state
 
    protected function afterLogin()
 
    {
 
        $this->setState('___uid', $this->id);
 
        return true;
 
    }
     // Load user model. protected function loadUser() { if ( $this->_model === null ) { $this->_model = User::model()->findByPk( $this->getState('___uid')id );
}
return $this->_model;
[...]
```

You can create more methods, like for example, isMember(), or whatever best suits you, in order to display the appropriate view or specific
, data according to the user level.
 
 
 
 
 
27 0
37 followers
Viewed: 70 613 times
Version: 1.1
Category: Tutorials
Written by: Antonio Ramirez
Last updated by: Phil Loaiza
Created on: May 10, 2011
Last updated: 10 years ago
Update Article

Revisions

View all history