src/models/LoginForm.php
public function login()
    {
        if ($this->validate()) {
            $user = $this->getUser();
            $user->detachBehavior('LogBehavior');
            
            // update user model
            $user->updateAttributes([
                'force_reload' => false,
                'login_attempt' => 0,
                'login_attempt_lock_expiration' => null,
                'auth_token' => Yii::$app->security->hashData(Yii::$app->security->generateRandomString(), $user->password_salt),
            ]);
            
            // kill prev user logins
            UserLogin::updateAll(['is_destroyed' => true], ['user_id' => $user->id]);
            
            // create new user login
            $login = new UserLogin([
                'auth_token' => $user->auth_token,
                'user_id' => $user->id,
                'is_destroyed' => false,
            ]);
            $login->save();
            
            // refresh user online list
            UserOnline::refreshUser($user, 'login');
            return $user;
        }
        
        return false;
    }
public function login()
    {
        if ($this->validate()) {
            $user = $this->getUser();
            $user->detachBehavior('LogBehavior');
            
            // update user model
            $user->updateAttributes([
                'force_reload' => false,
                'login_attempt' => 0,
                'login_attempt_lock_expiration' => null,
                'auth_token' => Yii::$app->security->hashData(Yii::$app->security->generateRandomString(), $user->password_salt),
            ]);
            
            // kill prev user logins
            UserLogin::updateAll(['is_destroyed' => true], ['user_id' => $user->id]);
            
            // create new user login
            $login = new UserLogin([
                'auth_token' => $user->auth_token,
                'user_id' => $user->id,
                'is_destroyed' => false,
            ]);
            $login->save();
            
            // refresh user online list
            UserOnline::refreshUser($user, 'login');
            return $user;
        }
        
        return false;
    }
public function login ( ) { if ( $ this -> validate ( ) ) { $ user = $ this -> getUser ( ) ; $ user -> detachBehavior ( 'LogBehavior' ) ; // update user model $ user -> updateAttributes ( [ 'force_reload' => false , 'login_attempt' => 0 , 'login_attempt_lock_expiration' => null , 'auth_token' => Yii :: $ app -> security -> hashData ( Yii :: $ app -> security -> generateRandomString ( ) , $ user -> password_salt ) , ] ) ; // kill prev user logins UserLogin :: updateAll ( [ 'is_destroyed' => true ] , [ 'user_id' => $ user -> id ] ) ; // create new user login $ login = new UserLogin ( [ 'auth_token' => $ user -> auth_token , 'user_id' => $ user -> id , 'is_destroyed' => false , ] ) ; $ login -> save ( ) ; // refresh user online list UserOnline :: refreshUser ( $ user , 'login' ) ; return $ user ; } return false ; }
Login the current user if valid.

@return boolean|\luya\admin\models\User|boolean
Login the current user if valid .