LoginForm
| Inheritance | class LoginForm » CFormModel » CModel » CComponent |
|---|---|
| Implements | IteratorAggregate, Traversable, ArrayAccess |
| Source Code | app/models/LoginForm.php |
LoginForm class.
LoginForm is the data structure for keeping
user login form data. It is used by the 'login' action of 'SiteController'.
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| attributes | array | Returns all attribute values. | CModel |
| errors | array | Returns the errors for all attribute or a single attribute. | CModel |
| iterator | CMapIterator | Returns an iterator for traversing the attributes in the model. | CModel |
| password | LoginForm | ||
| rememberMe | LoginForm | ||
| safeAttributeNames | array | Returns the attribute names that are safe to be massively assigned. | CModel |
| scenario | string | Returns the scenario that this model is used in. | CModel |
| username | LoginForm | ||
| validatorList | CList | Returns all the validators declared in the model. | CModel |
| validators | array | Returns the validators applicable to the current scenario. | CModel |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __call() | Calls the named method which is not a class method. | CComponent |
| __construct() | Constructor. | CFormModel |
| __get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
| __isset() | Checks if a property value is null. | CComponent |
| __set() | Sets value of a component property. | CComponent |
| __unset() | Sets a component property to be null. | CComponent |
| addError() | Adds a new error to the specified attribute. | CModel |
| addErrors() | Adds a list of errors. | CModel |
| asa() | Returns the named behavior object. | CComponent |
| attachBehavior() | Attaches a behavior to this component. | CComponent |
| attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
| attachEventHandler() | Attaches an event handler to an event. | CComponent |
| attributeLabels() | Declares attribute labels. | LoginForm |
| attributeNames() | Returns the list of attribute names. | CFormModel |
| authenticate() | Authenticates the password. | LoginForm |
| behaviors() | Returns a list of behaviors that this model should behave as. | CModel |
| canGetProperty() | Determines whether a property can be read. | CComponent |
| canSetProperty() | Determines whether a property can be set. | CComponent |
| clearErrors() | Removes errors for all attributes or a single attribute. | CModel |
| createValidators() | Creates validator objects based on the specification in rules. | CModel |
| detachBehavior() | Detaches a behavior from the component. | CComponent |
| detachBehaviors() | Detaches all behaviors from the component. | CComponent |
| detachEventHandler() | Detaches an existing event handler. | CComponent |
| disableBehavior() | Disables an attached behavior. | CComponent |
| disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
| enableBehavior() | Enables an attached behavior. | CComponent |
| enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
| evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
| generateAttributeLabel() | Generates a user friendly attribute label. | CModel |
| getAttributeLabel() | Returns the text label for the specified attribute. | CModel |
| getAttributes() | Returns all attribute values. | CModel |
| getError() | Returns the first error of the specified attribute. | CModel |
| getErrors() | Returns the errors for all attribute or a single attribute. | CModel |
| getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
| getIterator() | Returns an iterator for traversing the attributes in the model. | CModel |
| getSafeAttributeNames() | Returns the attribute names that are safe to be massively assigned. | CModel |
| getScenario() | Returns the scenario that this model is used in. | CModel |
| getValidatorList() | Returns all the validators declared in the model. | CModel |
| getValidators() | Returns the validators applicable to the current scenario. | CModel |
| hasErrors() | Returns a value indicating whether there is any validation error. | CModel |
| hasEvent() | Determines whether an event is defined. | CComponent |
| hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
| hasProperty() | Determines whether a property is defined. | CComponent |
| init() | Initializes this model. | CFormModel |
| isAttributeRequired() | Returns a value indicating whether the attribute is required. | CModel |
| isAttributeSafe() | Returns a value indicating whether the attribute is safe for massive assignments. | CModel |
| login() | Logs in the user using the given username and password in the model. | LoginForm |
| offsetExists() | Returns whether there is an element at the specified offset. | CModel |
| offsetGet() | Returns the element at the specified offset. | CModel |
| offsetSet() | Sets the element at the specified offset. | CModel |
| offsetUnset() | Unsets the element at the specified offset. | CModel |
| onAfterConstruct() | This event is raised after the model instance is created by new operator. | CModel |
| onAfterValidate() | This event is raised after the validation is performed. | CModel |
| onBeforeValidate() | This event is raised before the validation is performed. | CModel |
| onUnsafeAttribute() | This method is invoked when an unsafe attribute is being massively assigned. | CModel |
| raiseEvent() | Raises an event. | CComponent |
| rules() | Declares the validation rules. | LoginForm |
| setAttributes() | Sets the attribute values in a massive way. | CModel |
| setScenario() | Sets the scenario for the model. | CModel |
| unsetAttributes() | Sets the attributes to be null. | CModel |
| validate() | Performs the validation. | CModel |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| afterConstruct() | This method is invoked after a model instance is created by new operator. | CModel |
| afterValidate() | This method is invoked after validation ends. | CModel |
| beforeValidate() | This method is invoked before validation starts. | CModel |
Events
| Event | Description | Defined By |
|---|---|---|
| onAfterConstruct | This event is raised after the model instance is created by new operator. | CModel |
| onBeforeValidate | This event is raised before the validation is performed. | CModel |
| onAfterValidate | This event is raised after the validation is performed. | CModel |
| onUnsafeAttribute | This method is invoked when an unsafe attribute is being massively assigned. | CModel |
Property Details
password
property
public $password;
rememberMe
property
public $rememberMe;
username
property
public $username;
Method Details
attributeLabels()
method
|
public void attributeLabels()
|
Source Code: app/models/LoginForm.php#36 (show)
public function attributeLabels()
{
return array(
'rememberMe'=>'Remember me next time',
);
}
Declares attribute labels.
authenticate()
method
|
public void authenticate($attribute, $params)
| ||
| $attribute | ||
| $params | ||
Source Code: app/models/LoginForm.php#47 (show)
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
}
}
Authenticates the password. This is the 'authenticate' validator as declared in rules().
login()
method
|
public boolean login()
| ||
| {return} | boolean | whether login is successful |
Source Code: app/models/LoginForm.php#61 (show)
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}
Logs in the user using the given username and password in the model.
rules()
method
|
public void rules()
|
Source Code: app/models/LoginForm.php#21 (show)
public function rules()
{
return array(
// username and password are required
array('username, password', 'required'),
// rememberMe needs to be a boolean
array('rememberMe', 'boolean'),
// password needs to be authenticated
array('password', 'authenticate'),
);
}
Declares the validation rules. The rules state that username and password are required, and password needs to be authenticated.