Пример #1
0
 public static function registerToken($userId, $device = NULL, $CI = NULL)
 {
     if (is_null($CI)) {
         $CI =& get_instance();
     }
     if (!empty($device)) {
         $deviceData = (array) json_decode($device);
         $CI->load->model('Device_model');
         $existDevice = $CI->Device_model->get_by(array('secure_id' => $deviceData['secureId']));
         if (empty($existDevice)) {
             $insertDevice = $CI->Device_model->create($deviceData);
             if ($insertDevice) {
                 $existDevice = $CI->Device_model->get($insertDevice);
             } else {
                 return FALSE;
             }
         }
     }
     $CI->load->model('User_token_model');
     $time = Util::timeNow();
     $token = self::generateToken($userId);
     $data = array('user_id' => $userId, 'device_id' => !empty($existDevice) ? $existDevice['id'] : NULL, 'ip_address' => RequestManager::getIpAddress(), 'login_time' => $time, 'last_activity' => $time, 'token' => $token, 'token_expired_time' => Util::timeAdd('+6 hours'), 'count_request' => 1, 'status' => self::STATUS_LOGIN);
     $insert = $CI->User_token_model->insert($data);
     if ($insert) {
         return $token;
     } else {
         return FALSE;
     }
 }