浏览代码

Indentation + commentaires modèle LoginForm

dev
父节点
当前提交
d615b17ea6
共有 1 个文件被更改,包括 17 次插入7 次删除
  1. +17
    -7
      common/models/LoginForm.php

+ 17
- 7
common/models/LoginForm.php 查看文件

/** /**
* Login form * Login form
*/ */
class LoginForm extends Model {
class LoginForm extends Model
{


public $username; public $username;
public $password; public $password;
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function rules() {
public function rules()
{
return [ return [


['email', 'filter', 'filter' => 'trim'], ['email', 'filter', 'filter' => 'trim'],
* @param string $attribute the attribute currently being validated * @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule * @param array $params the additional name-value pairs given in the rule
*/ */
public function validatePassword($attribute, $params) {
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) { if (!$this->hasErrors()) {
$user = $this->getUser(); $user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) { if (!$user || !$user->validatePassword($this->password)) {
* *
* @return boolean whether the user is logged in successfully * @return boolean whether the user is logged in successfully
*/ */
public function login() {
public function login()
{
if ($this->validate()) { if ($this->validate()) {
$this->updateDerniereConnexion(); $this->updateDerniereConnexion();
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
* *
* @return User|null * @return User|null
*/ */
public function getUser() {
public function getUser()
{
if ($this->_user === false) { if ($this->_user === false) {
$this->_user = User::findByEmail($this->email); $this->_user = User::findByEmail($this->email);
} }
return $this->_user; return $this->_user;
} }


public function attributeLabels() {
public function attributeLabels()
{
return [ return [
'id' => 'ID', 'id' => 'ID',
'username' => 'Identifiant', 'username' => 'Identifiant',
]; ];
} }


public function updateDerniereConnexion() {
/**
* Met à jour la date de dernière connexion de l'utilisateur.
*/
public function updateDerniereConnexion()
{
$user = $this->getUser(); $user = $this->getUser();
$user->date_derniere_connexion = date('Y-m-d H:i:s'); $user->date_derniere_connexion = date('Y-m-d H:i:s');
$user->save(); $user->save();

正在加载...
取消
保存