def connect(request): global session_manager profile_id = request.GET.get('profile_id') peer_id, session_id = session_manager.join_or_create_session(profile_id,request.event.slug) response_data = {} if int(peer_id) != int(profile_id): profilesDao = ProfilesDao() profile = profilesDao.get_by_id(int(profile_id)) # TODO: Fix ugly hack if 'last_heartbeat' in profile: del profile['last_heartbeat'] # UGLY HACK response_data['peerProfile'] = profile #response_data['sessionId'] = '2_MX40MTgwNTc5Mn4xMjcuMC4wLjF-VGh1IFNlcCAyNiAwMjoxMDo1OCBQRFQgMjAxM34wLjkzMzI0MDF-' #response_data['token'] = 'T1==cGFydG5lcl9pZD00MTgwNTc5MiZzZGtfdmVyc2lvbj10YnJ1YnktdGJyYi12MC45MS4yMDExLTAyLTE3JnNpZz0wMzU3MDAwYWU0NDg2ODU0NjhhNmNiMTJhZTEzMDc3MDU3MDE3ZTNhOnJvbGU9cHVibGlzaGVyJnNlc3Npb25faWQ9Ml9NWDQwTVRnd05UYzVNbjR4TWpjdU1DNHdMakYtVkdoMUlGTmxjQ0F5TmlBd01qb3hNRG8xT0NCUVJGUWdNakF4TTM0d0xqa3pNekkwTURGLSZjcmVhdGVfdGltZT0xMzgwMTg2NjU5Jm5vbmNlPTAuMDk5NTY4MzE4NTc0ODE1MDcmZXhwaXJlX3RpbWU9MTM4MDI3MzA2NSZjb25uZWN0aW9uX2RhdGE9' response_data['peerId'] = peer_id response_data['sessionId'] = session_id print "RESP",response_data return HttpResponse(json.dumps(response_data), content_type="application/json")
def api_create_profile(request,event_slug): if request.POST.get('api_key') != SECRET_API_KEY: return HttpResponse(json.dumps({'success':False,'reason':'bad_api_key'}), content_type="application/json") profilesDao = ProfilesDao() client_ip = request.POST.get('ip', get_client_ip(request)) geoip_info_response = requests.get('http://freegeoip.net/json/%s'%client_ip) if geoip_info_response.status_code == 200: geoip_info = geoip_info_response.json() else: # TODO: Log a bad response code somewhere geoip_info = None profile_id = profilesDao.create_new_profile( name=request.POST['name'], email=request.POST['email'], country=request.POST['country'], city=request.POST['city'], interests=request.POST['interests'], event_slug=event_slug, ip=client_ip, geoip_info=geoip_info) return HttpResponse(json.dumps({'success':True,'user_id':profile_id}), content_type="application/json")
def create_profile(request): profile_id = None if request.POST.get('name'): # you did POST - need to create your profile and load page profilesDao = ProfilesDao() client_ip = get_client_ip(request) # Get geoip info geoip_info_response = None try: geoip_info_response = requests.get('http://freegeoip.net/json/%s'%client_ip, timeout=1.0) except: pass if geoip_info_response and geoip_info_response.status_code == 200: geoip_info = geoip_info_response.json() else: # TODO: Log a bad response code somewhere geoip_info = None profile_id = profilesDao.create_new_profile( name=request.POST['name'], email=request.POST['email'], country=request.POST['country'], city=request.POST['city'], interests=request.POST['interests'], event_slug=request.event.slug, ip=client_ip, geoip_info=geoip_info) analytics.identify(request.POST['email'], { 'name': request.POST['name'], 'city': request.POST['city'], 'interests': request.POST['interests'], 'eventSlug': request.event.slug, 'ip': get_client_ip(request) }) analytics.track(request.POST['email'], 'Joined event', { 'eventSlug' : request.event.slug, 'country' : request.POST['country'], 'ip' : get_client_ip(request) }) request.session['profile_id'] = profile_id; return shortcuts.redirect('/chat') else: return shortcuts.redirect('/')