Пример #1
0
def register(request):
	p_k=employee_k = db.Key.from_path('Users', request.POST['userid'])
	p=db.get(p_k)
	a=""
	if(p!=None):
		a="this email is already registered"
	else:
		a="registered successfully,login above"
		p=Users(key_name=request.POST['userid'],email=request.POST['userid'],name=request.POST['name'],password=request.POST['pass'])
		p.put();
	return render_to_response('index.html', {
            'error_message': a,
        }, )
Пример #2
0
def oauth(request):
	#return HttpResponse(request.GET['code'])
	code = request.GET['code']
	url = 'https://github.com/login/oauth/access_token?'
	values = {'client_id' : client_id,
			  'redirect_uri' : 'http://nitinapp10.appspot.com/oauth/github',
			  'client_secret' : client_secret,
			  'code': code,}
	req = urllib2.Request(url+urllib.urlencode(values))
	response = urllib2.urlopen(req)
	the_page = response.read()
	token = the_page.split('&')
	token = token[0].split('=')
	token = token[1]
	url = 'https://api.github.com/user?'
	
	#return HttpResponse(url+'access_token='+token)
	values = {'access_token' : token,}
	req = urllib2.Request(url+urllib.urlencode(values))
	
	response = urllib2.urlopen(req)
	the_page = response.read()
	null = None
	false = False
	obj = eval(the_page)
	p=Users(key_name=str(obj['id']),email=obj['html_url'],name=obj['name'],password=None)
	p.put();
	 
	#return HttpResponse(token)		
	#return render_to_response('home.html', {
    #        'access_token': token,
    #    },)
	x=uuid.uuid1()
	a=str(x)
	p.sid = a
	p.put()
	return HttpResponseRedirect('/home/'+str(obj['id'])+'/'+ a)