I have been working to make an application having different mechanism for the user authentications. What I would like to do is to distinguish users, it means that every one can register his/her username and password.
Well, let me take an example as a blog demo for the time being. What I have done is as follows.
Modified the code of protected/components/UserIdentity.php
Q2. I think it is not good for the components to change the view using redirect method. What do you think is the smart way? One idea is to set another return code in the component and redirect in the model, but it failed because models do not have a redirect method. I have to do it in the controller but I do not know how to do it.
2. You can use Yii::app()->controller->redirect().
Do you think it is fine as well to change the view in the components? It may work but I do not know it is recommended or not according to the 'Yii style' if it exists.
Thanks Qian, I see, and I hope redirection may work. But before going further, I have a problem of login for the new user just being registered. I have modified the code as follows.
class LoginForm extends CFormModel
{ case UserIdentity::ERROR_NONE:
case UserIdentity::USER_REGISTERED:
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($identity,$duration);
break;
:
public function authenticate($attribute,$params)
{
if(!$this->hasErrors()) // we only want to authenticate when no input errors
{
$identity=new UserIdentity($this->username,$this->password);
$identity->authenticate();
switch($identity->errorCode)
{
case UserIdentity::ERROR_NONE:
+ case UserIdentity::USER_REGISTERED:
* $identity->errorCode = UserIdentity::ERROR_NONE;
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($identity,$duration);
break;
I tested the login status just as the user who is already registered, but failed. I added (*) line but it is of no help. Why are these two status different?
[Edit]
May be the $_id variable in the $identity… I should check.