/**
  * Creates a new device from $_POST data.
  *
  * @throws DeviceException
  *  If invalid data was sent.
  */
 public function add()
 {
     if (Session::getInstance()->appstate !== AppState::LOGGEDIN) {
         throw new DeviceException('You can\'t add a new device now.');
     }
     if (Session::getInstance()->incognito) {
         throw new DeviceException('You can\'t create new devices if your using the incognito login mode');
     }
     if (!valid_token()) {
         throw new DeviceException('Invalid token.');
     }
     if (empty($_POST['device-name'])) {
         throw new DeviceException('You need to give your new device a name.');
     }
     if (empty($_POST['device-type']) || !in_array($_POST['device-type'], array_keys(DeviceManager::listAvailableDevices()))) {
         throw new DeviceException('You need to pick a device from the list.');
     }
     if (empty($_POST['device-country']) || !in_array($_POST['device-country'], array_keys(LanguageCodes::$languages))) {
         throw new DeviceException('You need to choose a language for the device.');
     }
     // Sanitize name.
     $name = preg_replace('/[^a-zA-Z0-9äÄöÖüÜß\\.\\-éÉèÈâÂêÊŷŶáÁàÀ@?! ]/', '_', $_POST['device-name']);
     // Create the new device.
     Session::getInstance()->device_manager->checkinNewDevice($_POST['device-type'], $name, $_POST['device-country']);
     $this->render();
 }
Example #2
0
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function actionError()
 {
     $this->device = DeviceManager::getInstance();
     $this->layout = 'application.views.touch.layouts.error';
     if ($error = Yii::app()->errorHandler->error) {
         if (Yii::app()->request->isAjaxRequest) {
             echo $error['message'];
         } else {
             $this->render('error', compact('error'));
         }
     }
 }
 /**
  * Download requested package direct (without needing to be logged in).
  */
 public function direct($package = NULL)
 {
     if (empty($package)) {
         throw new DownloadException('Packagename is required.');
     }
     // Pick a random account from a list of fake accounts.
     $accounts = unserialize(FAKE_ACCOUNTS);
     $email = array_rand($accounts);
     $password = $accounts[$email];
     $account = new GoogleAccount($email, $password);
     // Get device manager for account.
     $device_manager = new DeviceManager(new User($account), $account);
     // Get registrated device for account with current language.
     // Make sure anonymous account has common devices.
     $device_manager->addCommonDevices();
     $devices = $device_manager->listDevices();
     $common_devices = unserialize(COMMON_DEVICES);
     $languages = unserialize(LANGUAGES);
     $device_id = $devices[$common_devices[$languages[LANGUAGE]][0]];
     // Get Market object for account and device.
     $market = new AndroidMarket($account, $device_id);
     // Get download info.
     $info = $market->fetchDownloadInfo($package);
     $this->_prepare($info);
 }
 /**
  * Löscht das Gerät
  * @param from Request DeviceID 
  * @return true/false
  *
  */
 public function deleteDevice($ErrorString = "", $StatusString = "")
 {
     $Request = new Request();
     $ID = $Request->getAsInt("DeviceID");
     $DeviceManager = new DeviceManager();
     $DeviceManager->deleteById($ID);
     /* TODO: Rückgabe prüfen!!! */
     return true;
 }
Example #6
0
 public function init()
 {
     // setup multi language
     self::_setupLanguage();
     // DETECT DEVICE
     $this->device = DeviceManager::getInstance();
     if (!isset(yii::app()->session['deviceId'])) {
         Yii::app()->session['deviceId'] = $this->device->getDeviceID();
         Yii::app()->session['device'] = $this->device->getInfo('model_name');
         Yii::app()->session['deviceOS'] = $this->device->getDeviceOs();
     }
     $this->deviceOs = Yii::app()->session['deviceOS'];
     // check user login
     if (Yii::app()->user->isGuest) {
         $identity = new UserIdentity(null, null);
         $type = 'autoLogin';
         if ($identity->userAuthenticate($type, $this->deviceOs)) {
             Yii::app()->user->login($identity);
         }
     }
     // get banners
     $this->banners = WapBannerModel::getBanner('wap');
     // reload package state if request
     if (isset($_REQUEST['reloadPackage']) && $_REQUEST['reloadPackage'] == 1) {
         $package = WapUserSubscribeModel::model()->getUserSubscribe(Yii::app()->user->getState('msisdn'));
         //get user_subscribe record by phone
         if ($package) {
             $packageObj = WapPackageModel::model()->findByPk($package->package_id);
             Yii::app()->user->setState('package', $packageObj->code);
         }
     }
     $this->promotion_realtime = WapUserSubscribeModel::model()->checkPromotion(Yii::app()->user->getState('msisdn'));
     if (!isset(Yii::app()->session['isPromotion']) || Yii::app()->session['isPromotion'] == '') {
         if (Yii::app()->user->getState('msisdn')) {
             //Yii::app()->session['isPromotion'] = WapUserSubscribeModel::model()->checkPromotion(Yii::app()->user->getState('msisdn'));
             Yii::app()->session['isPromotion'] = $this->promotion_realtime;
         } else {
             Yii::app()->session['isPromotion'] = "";
         }
     }
     $this->isPromotion = Yii::app()->session['isPromotion'];
     if (Yii::app()->user->getState('msisdn')) {
         $this->userSub = WapUserSubscribeModel::model()->getUserSubscribe(Yii::app()->user->getState('msisdn'));
     } else {
         $this->userSub = "";
     }
     Yii::app()->user->setState('userSub', $this->userSub);
     if (!Yii::app()->user->isGuest && $this->userSub == '') {
         $this->getPopup();
     }
     $this->getPopupKM();
     $this->getPopupCTKM();
     // load config from DB
     $wap_configs = Yii::app()->cache->get("WAP_CONFIG");
     if ($wap_configs === false) {
         $wap_configs = ConfigModel::model()->getConfig('', 'wap');
         Yii::app()->cache->set("WAP_CONFIG", $wap_configs, Yii::app()->params['cacheTime']);
     }
     if (!empty($wap_configs)) {
         foreach ($wap_configs as $key => $info) {
             $config_type = $info['type'];
             if ($config_type == "string") {
                 Yii::app()->params[$key] = $info['value'];
             }
             if ($config_type == "int") {
                 Yii::app()->params[$key] = intval($info['value']);
             }
             if ($config_type == "array") {
                 Yii::app()->params[$key] = unserialize($info['value']);
             }
         }
     }
     $this->updateCache();
     return parent::init();
 }
Example #7
0
 /**
  * 执行查询用户设备信息
  *
  * @return mixed $value 返回最终需要执行完的结果
  * @throws
  * @since 1.0.7
  */
 private function judgeDevice()
 {
     $deviceType = $_REQUEST['device_type'];
     //这里对iPhone/iPad做了一个补偿操作,此前的绑定设备类型出了错误。因为类型是6而不是5
     if (MiniHttp::isiPhone()) {
         $deviceType = 6;
     }
     $deviceName = urldecode($_REQUEST['device_name']);
     $deviceInfo = $_REQUEST['device_info'];
     if (!empty($deviceType) && !empty($deviceName) && !empty($deviceInfo)) {
     } else {
         # 当用户传递过来的设备信息都为空时,表示为三方开发者
         if (empty($deviceType) && empty($deviceName) && empty($deviceInfo)) {
             $deviceType = 10;
             $deviceName = "第三方用户";
             $deviceInfo = "第三方设备";
         } else {
             throw new MAuthorizationException("param_is_null", MConst::HTTP_CODE_400);
         }
     }
     //如被锁定,且是网页端则不进行登录。
     $userName = $_REQUEST['username'];
     if (empty($userName)) {
         $userName = $_POST['username'];
     }
     $name = urldecode($userName);
     $isLock = MiniUser::getInstance()->isLock($name);
     $user = false;
     if (!($isLock && MiniHttp::clientIsBrowser())) {
         $user = self::searchUser();
     }
     if ($user === false) {
         //如果用户在非锁定状态,则错误数+1
         if (!$isLock) {
             MiniUser::getInstance()->setPasswordError($name);
         }
         return false;
     } else {
         //如果用户登录正确,则把密码错误次数清空
         MiniUser::getInstance()->cleanPasswordError($name);
     }
     if (!$user["user_status"]) {
         throw new MAuthorizationException("User has disabled.", MConst::HTTP_CODE_407);
     }
     //对设备进行检测
     $device = DeviceManager::getDevice($user["id"], $deviceType, $deviceName, $deviceInfo);
     return $device;
 }
Example #8
0
 /**
  * 获得当前登录的设备
  * @param $user
  * @return null
  */
 private function getCurrentDevice($user)
 {
     $deviceType = 1;
     if (MiniHttp::isPCClient()) {
         if (MiniHttp::isWindowsOS()) {
             $deviceType = 2;
             //Windows 客户端
         } else {
             if (MiniHttp::isMacOS()) {
                 $deviceType = 3;
                 //Mac 客户端
             } else {
                 $deviceType = 5;
                 //Linux 客户端
             }
         }
     }
     //对设备进行检测
     if ($deviceType == 1) {
         $device = DeviceManager::getDevice($user["id"], MConst::DEVICE_WEB, "web", $_SERVER['HTTP_USER_AGENT']);
     } else {
         $device = MiniUserDevice::getInstance()->getFirstByDeviceTypeAndDeviceName($user["id"], $deviceType);
     }
     return $device;
 }
 public static function set($data)
 {
     self::$data = array_merge(self::$data, $data);
 }