def query_userid(self, device_id): #先查anonymous_device device = db_helper.query_anonymous_device(device_id) if device is None: return -1 elif device.flag == 0: return 0 else: #已绑定,查user_device device = db_helper.query_user_device(device_id) assert device is not None return device.userid
def POST(self): self.init() #判断当前ip登陆设备数,3台以上屏蔽 # if self._ip != '14.127.235.24': # device_list = db_helper.query_ip_history(self._ip) # if self._device_id not in device_list and len(device_list) >= 3: # logger.info('too many devices on ip: %s, total_device: %d' %(self._ip, len(device_list))) # return json.dumps({'rtn': 1}) #判断当前ip登陆过的设备,每个类型的设备只能登陆1次 if self._ip not in ['183.14.0.221', '121.14.98.49', '14.153.253.143', '113.92.102.40']: mm = db_helper.query_ip_history(self._ip) if self._device_id not in mm and self._platform in set(mm.values()): logger.info('too many devices on ip: %s, device_list: %s' %(self._ip, str(mm))) return json.dumps({'rtn': 1}) #先查anonymous_device device = db_helper.query_anonymous_device(self._device_id) if device is None: #查不到,直接插入 db_helper.insert_anonymous_device(self._device_id, self._mac, self._idfa, self._platform) self._new_device = True logger.debug('new device, %s' %self._device_id) #初次安装奖励1元 self.recharge(self._device_id, 100, '初次安装奖励') elif device.flag == 0: #未绑定 pass else: #已绑定,查user_device与user_info device = db_helper.query_user_device(self._device_id) #能查到 assert device is not None #被屏蔽用户 if self.is_banned(device.userid): logger.info('banned user!! userid:%d' %device.userid) return json.dumps({'rtn': 2}) user = db_helper.query_user_info(device.userid) assert user is not None logger.debug('user: %s' %str(user.__dict__)) self._userid = user.userid self._phone_num = user.phone_num self._invite_code = user.invite_code self._inviter = user.inviter_code #记录login_history self._login_history_entry.userid = self._userid db_helper.record_login_history(self._login_history_entry) resp = { 'rtn': 0, 'userid': self._userid, 'device_id': self._device_id, 'new_device': self._new_device, 'invite_code': self._invite_code, 'phone_num': self._phone_num, 'inviter': self._inviter } logger.debug('resp: %s' %str(resp)) return json.dumps(resp)
def POST(self): self.init() #判断当前ip登陆设备数,3台以上屏蔽 # if self._ip != '14.127.235.24': # device_list = db_helper.query_ip_history(self._ip) # if self._device_id not in device_list and len(device_list) >= 3: # logger.info('too many devices on ip: %s, total_device: %d' %(self._ip, len(device_list))) # return json.dumps({'rtn': 1}) #判断当前ip登陆过的设备,每个类型的设备只能登陆1次 if False: if self._ip not in [ '127.0.0.1', '183.14.0.221', '121.14.98.49', '14.153.253.143', '113.92.102.40' ]: mm = db_helper.query_ip_history(self._ip) if self._device_id not in mm and self._platform in set( mm.values()): logger.info('too many devices on ip: %s, device_list: %s' % (self._ip, str(mm))) return json.dumps({'rtn': 1}) #先查anonymous_device device = db_helper.query_anonymous_device(self._device_id) if device is None: #查不到,直接插入 db_helper.insert_anonymous_device(self._device_id, self._mac, self._idfa, self._platform) self._new_device = True logger.debug('new device, %s' % self._device_id) #初次安装奖励1元 self.recharge(self._device_id, 100, '初次安装奖励', 0) elif device.flag == 0: #未绑定 pass else: #已绑定,查user_device与user_info device = db_helper.query_user_device(self._device_id) #能查到 assert device is not None #被屏蔽用户 if self.is_banned(device.userid): logger.info('banned user!! userid:%d' % device.userid) return json.dumps({'rtn': 2}) user = db_helper.query_user_info(device.userid) assert user is not None logger.debug('user: %s' % str(user.__dict__)) self._userid = user.userid self._phone_num = user.phone_num self._invite_code = user.invite_code self._inviter = user.inviter_code #记录login_history self._login_history_entry.userid = self._userid db_helper.record_login_history(self._login_history_entry) resp = { 'rtn': 0, 'userid': self._userid, 'device_id': self._device_id, 'new_device': self._new_device, 'invite_code': self._invite_code, 'phone_num': self._phone_num, 'inviter': self._inviter } logger.debug('resp: %s' % str(resp)) return json.dumps(resp)