I am modifying the code of User Identification stolen from the blog demo.
I understand that the user authentication is done as follows.
(1) component/UserIdentity.php
It returns several status in $this->errorCode.
(2) models/LoginForm.php
It judges the situation from the $identity->errorCode and sets the results by using $this->addError() method.
I added another situation (USER_TO_BE_REGISTERED) by using $this->addError because if I do not, it means no error to the upper function.
BTW, ERROR_NONE means that the user is in the db and password is OK.
ERROR_PASSWORD_INVALID means as written.
(3) controllers/SiteController.php
It checks the validation by using $form->validate(), and I would like to distinguish those three conditions here.
Then, in the SiteController, I wanted to have a method that removes the error from the lower function such as authenticate(). Otherwise, could you please give me a better solution?
I think this is better. What I have done is almost the same(?) but I think mine is not as good as yours.
class LoginForm extends CFormModel
{
public $errorCode;
...
public function authenticate($attribute,$params)
...
$this->errorCode = $identity->errorCode;
...
SiteController:
if ($form->errorCode == UserIdentity::USER_TO_BE_REGISTERED) {
Though I haven’t tested clearErrors(), my user identification module is now working. Thanks!
I have just tested your suggestion of CModel.clearErrors(). I think it almost works fine.
Adding the error code and removing it are OK. One thing that I have noticed that I have to distinguish the status of USER_TO_BE_REGISTERED from the errorCode anyway. So, I decided to use errorCode and thus do not have to remove error codes. Thanks.