Beispiel #1
0
 public function saveLoginInfo($lastLoginTime, $ipAddress)
 {
     $model = new UsersLogin();
     $model->user_id = \Yii::$app->user->identity;
     $model->login_time = $lastLoginTime;
     $model->ip_address = $ipAddress;
     if (!$model->save()) {
         var_dump($model->errors);
         exit;
     }
 }
Beispiel #2
0
 /**
  * Get push-tokens of app logged in users
  * @param array $pushReceivers
  * @return array $pushTokens
  */
 private static function _getTokensOfLoggedInUsers($pushReceivers)
 {
     $pushTokens = array();
     foreach ($pushReceivers as $key => $pushReceiverId) {
         // Get user push token
         $tokenData = UsersLogin::select('device_push_token', 'device_type')->where('user_id', '=', $pushReceiverId)->where('status', '=', 1)->get()->toArray();
         foreach ($tokenData as $value) {
             $pushTokens[] = $value;
         }
     }
     return $pushTokens;
 }
Beispiel #3
0
 /**
  * To logout user
  * @param int $userId
  * @param string $deviceId
  * @return array $this->messages
  */
 public function logOutUser($userId, $deviceId)
 {
     UserModel::where('id', '=', $userId)->update(array('login_status' => 0));
     $objectModelUsersLogin = new UsersLogin();
     $objectModelUsersLogin->logOutUser($userId, $deviceId);
     $token = $this->generateToken(0, $deviceId);
     $this->messages['status'] = $this->successStatus;
     $this->messages['access_token'] = $token;
     return $this->messages;
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUsersLogins()
 {
     return $this->hasMany(UsersLogin::className(), ['user_id' => 'id']);
 }
Beispiel #5
0
 /**
  * Checking is the users login status according to the user id 
  * 
  * @param integer $userId
  * @return string
  */
 public static function checkUsersLoginStatus($userId)
 {
     if (!empty($userId)) {
         $userLoginStatus = UsersLogin::USER_VERY_ACTIVE;
         $currentDate = new \DateTime();
         $past7daysDate = (new \DateTime())->sub(new \DateInterval('P7D'));
         $past14daysDate = (new \DateTime())->sub(new \DateInterval('P14D'));
         $past30daysDate = (new \DateTime())->sub(new \DateInterval('P30D'));
         $query = UsersLogin::where('user_id', '=', $userId);
         $_7daysRecord = $query->whereBetween('login_time', array($past7daysDate->format('Y-m-d'), $currentDate->format('Y-m-d')))->get();
         if (!$_7daysRecord->count()) {
             $_14daysRecord = $query->whereBetween('login_time', array($past14daysDate->format('Y-m-d'), $past7daysDate->format('Y-m-d')))->get();
             if (!$_14daysRecord->count()) {
                 $_30daysRecord = $query->whereBetween('login_time', array($past30daysDate->format('Y-m-d'), $past14daysDate->format('Y-m-d')))->get();
                 return !$_30daysRecord->count() ? UsersLogin::USER_IN_ACTIVE : UsersLogin::USER_LITTLE_ACTIVE;
             }
             $userLoginStatus = UsersLogin::USER_ACTIVE;
         }
         return $userLoginStatus;
     }
 }