def device_login(cls, did): uid = cls.did_to_uid(did) is_new = False if uid is None: uid = cls.create_user(did, cls.DID2UID) is_new = True Log.info("create user by did: uid=%d" % uid) return (uid, is_new)
def fb_login(cls, did, fbid, fb_name, frd_list): uid = cls.fbid_to_uid(fbid) is_new = False if uid is None: uid = cls.did_to_uid(did) # create new account if device already binded to a fb id if uid is None or cls.did_to_fbid(did) is not None: uid = cls.create_user(fbid, cls.FBID2UID) is_new = True Log.info("create user by fb: uid=%d" % uid) else: # clear device id map to enable new login by did? Redis().hset(cls.FBID2UID, fbid, uid) Redis().hset(cls.DID2FBID, did, fbid) Log.info("move user to fb map: uid=%d" % uid) #update info user = User(uid) user.setName(fb_name) if not user.fbid: #import friends for 1st time uid_list = [] for f in frd_list: u = cls.fbid_to_uid(f) if u is not None: uid_list.append(u) if len(uid_list) > 0: Social.importFriends(uid, uid_list) user.fbid = fbid return (uid, is_new)
def api(request): try: para = json.loads(request.body) Log.info('Request: %s' % (log_kv(para))) cmd = para['cmd'] if cmd in API_ROUTER: processPara(para) if cmd == 'login': if request.META.has_key('HTTP_X_REAL_IP'): para['ip'] = request.META['HTTP_X_REAL_IP'] else: para['ip'] = request.META['REMOTE_ADDR'] if cmd != 'verify_purchase' and para['version'] < Config.MIN_VERSION: Log.info('unsupported version: %d' % para['version']) return HttpResponse(genResponse(Error.VERSION_TOO_LOW)) if cmd != 'login' and cmd != 'verify_purchase': if not Session.is_valid(para['uid'], para['sid']): Log.error('session invalid') return HttpResponse(genResponse(Error.INVALID_SESSION)) ret = API_ROUTER[cmd](para) response = genResponse(ret, para['uid']) Log.info('Request: %s, Response: %s' % (para, response)) return HttpResponse(response, content_type="application/json") else: Log.error('unknown cmd') return HttpResponse(genResponse(Error.UNKNOWN_CMD)) except Exception, e: traceback.print_exc() Log.error(traceback.format_exc()) return HttpResponseServerError("Unknown error: %s" % str(e))
def cfg_host(self, nameport, *args): np = Tool.hostport(nameport, Defaults.PORT) name = np[0] port = len(np)>1 and Tool.intval(np[1]) or _PORT pw = len(np)>2 and np[2] or '' sa = socket.getaddrinfo(name, port) if not sa: Log.err("cannot resolve %s",name) return for a in sa: if a[0] != socket.AF_INET and a[0] != socket.AF_INET6: Log.warn("wrong family {0} for {1}", Tool.sockfam(a[0]), name) continue if a[1] != socket.SOCK_DGRAM: Log.info("ignore type {0} for {1}", Tool.socktype(a[1]), name) continue if a[2] != socket.IPPROTO_UDP: Log.info("ignore proto {0} for {1}", Tool.sockproto(a[2]), name) continue Log.info("host {0}: {2} {1}", name, a[4], Tool.sockfam(a[0])) self.target.add(a[0], a[4], pw)