D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
hindiusa.org
/
public_html
/
hindiusa
/
models
/
Filename :
LoginForm.php
back
Copy
<?php namespace app\models; use Yii; use yii\base\Model; /** * LoginForm is the model behind the login form. * * @property-read User|null $user This property is read-only. * */ class LoginForm extends Model { public $email; public $password; public $rememberMe = true; private $_user = false; public function behaviors() { $behaviors = parent::behaviors(); $behaviors[] = [ 'class' => '\ethercreative\loginattempts\LoginAttemptBehavior', // Amount of attempts in the given time period 'attempts' => 10, // the duration, for a regular failure to be stored for // resets on new failure 'duration' => 300, // the unit to use for the duration 'durationUnit' => 'second', // the duration, to disable login after exceeding `attemps` 'disableDuration' => 900, // the unit to use for the disable duration 'disableDurationUnit' => 'second', // the attribute used as the key in the database // and add errors to 'usernameAttribute' => 'email', // the attribute to check for errors 'passwordAttribute' => 'password', // the validation message to return to `usernameAttribute` 'message' => 'Login disabled', ]; return $behaviors; } /** * @return array the validation rules. */ public function rules() { return [ // username and password are both required [['email', 'password'], 'required'], // rememberMe must be a boolean value ['rememberMe', 'boolean'], // password is validated by validatePassword() ['password', 'validatePassword'], ]; } /** * Validates the password. * This method serves as the inline validation for password. * * @param string $attribute the attribute currently being validated * @param array $params the additional name-value pairs given in the rule */ public function validatePassword($attribute, $params) { if (!$this->hasErrors()) { $user = $this->getUser(); if (!$user || !$user->validatePassword($this->password)) { $this->addError($attribute, 'Incorrect email or password.'); } } } /** * Logs in a user using the provided username and password. * @return bool whether the user is logged in successfully */ public function login() { if ($this->validate()) { return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0); } return false; } /** * Finds user by [[email]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = Users::findByEmail($this->email); } return $this->_user; } }