I’m working with a server-based authentication, so I’m attempting to implement a custom login system in Yii. To learn the system, I tried to create a dummy authentication class that would automatically log in a user. I included the class in the config, but I can’t figure out how to log users in.
Is there a way to automatically log in on the first use of the application (eg as a session is created?) Or is there some better way of achieving this?
The base of this is a custom authentication class:
class MyAuthentication
extends CApplicationComponent
implements IUserIdentity {
private $_username = '';
private $_authenticated = False;
...
public function authenticate()
{
$this->_username = 'exampleUser';
$this->_authenticated = True;
return True;
}
public function getIsAuthenticated()
{
return $this->_authenticated;
}
Since my authentication was based on a server-side variable, I was able to use the
expressionfeature of the accessRules array to check if that variable was true. I wrote a custom class to help:And updated my rules to use an expression check instead of a user check, as described by the documentation: