modules/api/v2/models/Login.php
/**
     * Logs in a user using the provided email and password.
     * @return false
     */
Logs in a user using the provided email and password.
@return false
Logs in a user using the provided email and password . @return false
public function login()
    {
        if (!empty(Yii::$app->request->post('is_login_from'))) {
            $loginFrom = Yii::$app->request->post('is_login_from');
            if ($this->getUser($loginFrom)) {
                $modelDevice = UserDevice::find()->where(['notification_token' => Yii::$app->request->post('notification_token'), 'device_platform' => Yii::$app->request->post('device_platform'), 'user_id' => $this->_user->id])->one();
                if (empty($modelDevice)) {
                    $accessToken = $this->_user->generateAccessToken();
                    $accessTokenExpiredAt = date('Y-m-d h:i:s', time() + (3600 * 24 * 365));
                    $this->_user->access_token_expired_at = $accessTokenExpiredAt;
                } else {
                    $accessToken = $this->_user->access_token;
                    $accessTokenExpiredAt = $this->_user->access_token_expired_at;
                    $this->_user->access_token_expired_at = $accessTokenExpiredAt;
                }
                $this->_user->save();
                Yii::$app->user->login($this->_user, 3600 * 24 * 365);
                $this->access_token = $accessToken;
                $this->access_token_expired_at = $accessTokenExpiredAt;
                $this->token_type = ucfirst(Yii::$app->params['token_type']);
                return true;
            }
        } else if ($this->validate()) {
            if ($this->getUser()) {
                Yii::$app->request->post('notification_token');
                Yii::$app->request->post('device_platform');
                $modelDevice = UserDevice::find()->where(['notification_token' => Yii::$app->request->post('notification_token'), 'device_platform' => Yii::$app->request->post('device_platform'), 'user_id' => $this->_user->id])->one();
                if (empty($modelDevice)) {
                    $accessToken = $this->_user->generateAccessToken();
                    $accessTokenExpiredAt = date('Y-m-d h:i:s', time() + (3600 * 24 * 365));
                    $this->_user->access_token_expired_at = $accessTokenExpiredAt;
                } else {
                    $accessToken = $this->_user->access_token;
                    if (empty($this->_user->access_token) || is_null($this->_user->access_token)) {
                        $accessToken = $this->_user->generateAccessToken();
                    }
                    $accessTokenExpiredAt = date('Y-m-d h:i:s', time() + (3600 * 24 * 365));
                    $this->_user->access_token_expired_at = $accessTokenExpiredAt;
                }
                $this->_user->save();
                Yii::$app->user->login($this->_user, 3600 * 24 * 365);
                $this->access_token = $accessToken;
                $this->access_token_expired_at = $accessTokenExpiredAt;
                $this->token_type = ucfirst(Yii::$app->params['token_type']);
                return true;
            }
        }
        return false;
    }
public function login ( ) { if ( ! empty ( Yii :: $ app -> request -> post ( 'is_login_from' ) ) ) { $ loginFrom = Yii :: $ app -> request -> post ( 'is_login_from' ) ; if ( $ this -> getUser ( $ loginFrom ) ) { $ modelDevice = UserDevice :: find ( ) -> where ( [ 'notification_token' => Yii :: $ app -> request -> post ( 'notification_token' ) , 'device_platform' => Yii :: $ app -> request -> post ( 'device_platform' ) , 'user_id' => $ this -> _user -> id ] ) -> one ( ) ; if ( empty ( $ modelDevice ) ) { $ accessToken = $ this -> _user -> generateAccessToken ( ) ; $ accessTokenExpiredAt = date ( 'Y-m-d h:i:s' , time ( ) + ( 3600 * 24 * 365 ) ) ; $ this -> _user -> access_token_expired_at = $ accessTokenExpiredAt ; } else { $ accessToken = $ this -> _user -> access_token ; $ accessTokenExpiredAt = $ this -> _user -> access_token_expired_at ; $ this -> _user -> access_token_expired_at = $ accessTokenExpiredAt ; } $ this -> _user -> save ( ) ; Yii :: $ app -> user -> login ( $ this -> _user , 3600 * 24 * 365 ) ; $ this -> access_token = $ accessToken ; $ this -> access_token_expired_at = $ accessTokenExpiredAt ; $ this -> token_type = ucfirst ( Yii :: $ app -> params [ 'token_type' ] ) ; return true ; } } else if ( $ this -> validate ( ) ) { if ( $ this -> getUser ( ) ) { Yii :: $ app -> request -> post ( 'notification_token' ) ; Yii :: $ app -> request -> post ( 'device_platform' ) ; $ modelDevice = UserDevice :: find ( ) -> where ( [ 'notification_token' => Yii :: $ app -> request -> post ( 'notification_token' ) , 'device_platform' => Yii :: $ app -> request -> post ( 'device_platform' ) , 'user_id' => $ this -> _user -> id ] ) -> one ( ) ; if ( empty ( $ modelDevice ) ) { $ accessToken = $ this -> _user -> generateAccessToken ( ) ; $ accessTokenExpiredAt = date ( 'Y-m-d h:i:s' , time ( ) + ( 3600 * 24 * 365 ) ) ; $ this -> _user -> access_token_expired_at = $ accessTokenExpiredAt ; } else { $ accessToken = $ this -> _user -> access_token ; if ( empty ( $ this -> _user -> access_token ) || is_null ( $ this -> _user -> access_token ) ) { $ accessToken = $ this -> _user -> generateAccessToken ( ) ; } $ accessTokenExpiredAt = date ( 'Y-m-d h:i:s' , time ( ) + ( 3600 * 24 * 365 ) ) ; $ this -> _user -> access_token_expired_at = $ accessTokenExpiredAt ; } $ this -> _user -> save ( ) ; Yii :: $ app -> user -> login ( $ this -> _user , 3600 * 24 * 365 ) ; $ this -> access_token = $ accessToken ; $ this -> access_token_expired_at = $ accessTokenExpiredAt ; $ this -> token_type = ucfirst ( Yii :: $ app -> params [ 'token_type' ] ) ; return true ; } } return false ; }
Logs in a user using the provided email and password.
Logs in a user using the provided email and password .
//$accessTokenExpiredAt = date('Y-m-d h:i:s', time() + Yii::$app->params['token_expire_time']); //                $accessToken = $this->_user->generateAccessToken(); //                $accessTokenExpiredAt = date('Y-m-d h:i:s', time() + Yii::$app->params['token_expire_time']); //                $this->_user->access_token_expired_at = $accessTokenExpiredAt; //Yii::$app->user->login($this->_user, 60 * 60 * 24 * 365); //Yii::$app->user->login($this->_user, time() + Yii::$app->params['token_expire_time']); //$accessTokenExpiredAt = date('Y-m-d h:i:s', time() + Yii::$app->params['token_expire_time']); //$accessTokenExpiredAt = $this->_user->access_token_expired_at; //Yii::$app->user->login($this->_user, time() + Yii::$app->params['token_expire_time']); //} else if (!empty(Yii::$app->request->post('is_login_from')) && (!empty(Yii::$app->request->post('facebook_id')) || !empty(Yii::$app->request->post('apple_id')))) {