Multiple usertypes and logins

While developing my latest project with Yii I have encountered the following problem

The system should support 3 types of users: admins, intranet users and clients

Because I did not use the advanced RBAC structure for this I just added some information to the UserIdentity and it works great. My only problem are the loginforms. I have one loginform on the frontend website, it is intended for the client users. The admins and intranet users login on the backend. Because I did not want to show the backend (which has a different theme) login to my clients I set the default loginUrl in my config to the loginform of the clients. Now when an admin for example gets logged out because of inactivity and has to log in again, he is redirected to the client login screen, which does not work for him because client users are in a separate DB table, so he has to enter the right URL again.

I tried to set the loginUrl for each user, but that does not work. Are there any suggestions for this?

I have done something simiral.

My solution at Backend controller.


   public function __construct() {

        //url for login

        Yii::app()->user->loginUrl=array('Backend/login');

        //url for error reporting

        Yii::app()->errorHandler->errorAction='Backend/Error';

        parent::__construct('Backend');

    }

If I understand correct, the loginUrl is not stored in the session of a user, but has to be set on every controller to which the user has access to… Thanks for the solution!

My solution was to modify the UserIdentity component’s authenticate function like so

public function authenticate()


{


    $user=User::model()->find('email=?',array($this->username));


    if($user===null)


    {


        $user=@Client::model()->find('email=?',array($this->username));


    }


    else


    {


        $this->setState('isAdmin',1);


    }


    if($user===null)


    {


        $this->errorCode=self::ERROR_USERNAME_INVALID;


    }


    else if(md5($this->password)!==$user->password)


    {


        $this->errorCode=self::ERROR_PASSWORD_INVALID;


    }


    else


    {


        $this->_id=$user->id;


        $this->setState('isActive',$user->isActive);


        $user->lastLogin=date('U');


        $user->save();


        $this->errorCode=self::ERROR_NONE;


    }


    return !$this->errorCode;


}

So, I check for an admin user first, then for a client. The limitation here is that Clients and Users can’t have the same username (I use the email address & force unique values).

This way I can use the same login form for everyone.

Obviously, it’s easy enough to extend this to check more tables (I’ll be adding Suppliers to ours).

Thanks for the reply but in my case I do want to have more loginforms for different types of users.

The client users will see our fancy design (frontend) and the admins have to do with the standard Yii design.

I could ofcourse let the admins login from the frontend as well and in that case your solution would work.

But for the sake of uniform design for my backend I decided to do it this way and the solution of dimis283 works great!