I have a login page that uses LDAP ...
Controller
Public Function Actionlogin () { $model = new LoginForm; If it is AJAX validation request if (isset ($_post[' Ajax ')) && $_post[' ajax '] = = = ' LoginForm ') { echo CA Ctiveform::validate ($model); Yii::app ()->end (); } if (Isset ($_post[' loginform ')) { $model->attributes = $_post[' LoginForm ']; Var_dump ($model->attributes); Question one if ($model->validate () && $model->login ()) { $this->redirect (Array (' form/ Index ')); } } $this->render (' login ', array (' model ' = $model)); }
In my loginform model, I'm going to take the value of UserDomain, but it's always empty.
Class LoginForm extends Cformmodel {public $username; Public $password; Public $userdomain; Private $_identity; /** * Declares the validation rules. * The rules state that username and password is required, * and password needs to be authenticated. */Public Function rules () {return array (//username and password is required array (' US Ername ', ' Required ', ' message ' = ' Pls Key in Your NT account. ', Array (' Password ', ' Required ', ' message ' =& Gt ' Pls Key in Your NT Password. '), Array (' UserDomain ', ' Required ', ' message ' = ' pls Select Your Domain Host '). ' ),//password needs to be authenticated array (' Password ', ' Authenticate '),); }/** * declares attribute labels. */Public Function attributelabels () {return array (' userdomain ' = ' User Domain '); }/** * Authenticates the password. * This is the ' AuthenTicate ' validator as declared in rules (). */Public function authenticate ($attribute, $params) {if (! $this->haserrors ()) {$this->_ident ity = new Useridentity ($this->username, $this->password, $this->userdomain); if (! $this->_identity->authenticate ()) $this->adderror (' Password ', ' incorrect username or password .'); }}/** * Logs in the user using the given username and password in the model. * @return Boolean whether login is successful */Public function login () {if ($this->_identity = = = null) {$this->_identity = new Useridentity ($this->username, $this->password, $this->userdomain); $this->_identity->authenticate (); } if ($this->_identity->errorcode = = = Useridentity::error_none) {return true; } else {return false; } }}
But I read it here in question one, it's worth it.
Username ' = = String ' Dasdasda ' (length=8)
' Password ' = String ' asdasdasd ' (length=9)
' UserDomain ' = String ' xxxxx ' (length=5)
Reply to discussion (solution)
I'll check it out a little bit more carefully.
UserDomain has been passed to model.
But I uploaded it from model to component/useridentity without userdomain/.
Here's the problem.
The Cuseridentity constructor
By default only constructs Username,password ...
So you can't pass the value to cuseridentity.
A method must be defined inside the component/useridentity.
Pass the UserDomain in.