Exemple #1
0
def login_as_patient(request):
	form = LoginForm(request.POST or None)
	if form.is_valid():
		username = form.cleaned_data['username']
		password = form.cleaned_data['password']
		try:
			user = User.objects.get(primary_email=username,
									password=password)
		except:
			print 'password not matching'
		else:
			request.session['user'] = user
			return HttpResponseRedirect('/know')

	return render_to_response('login_as_patient.html',{'form':form},RequestContext(request))
Exemple #2
0
def login_as_doctor(request):
	patients = []
	a = []
	form = LoginForm(request.POST or None)
	try:
		content  = request.session['content']
		headers = request.session['headers']
	except:
		request.session['loggedin'] = 0
		if form.is_valid():
			username = form.cleaned_data['username']
			password = form.cleaned_data['password']
			r = connect_to_api(username, password)
			request.session['content'] = r.content
			request.session['headers'] = r.headers
			return HttpResponseRedirect('/login/doctor')
	else:		

		request.session['loggedin'] = 1
		print request.session['headers']
		xauth_token = headers['set-cookie'].split(';')[0]
		xauth_token = xauth_token.split('=')[1]
		headers = {'X-AUTH-TOKEN' : xauth_token}

		try:
			patients = request.session['patients']
		except:
			r = requests.get(PATIENT_API_URL, headers=headers)
			patients = json.loads(r.content)['patients']
			request.session['patients'] = patients

		for users in patients:
			try:
				primary_mobile = users['primary_mobile']
			except:
				primary_mobile = "Mobile not Given"
			try:
				primary_email = users['primary_email']
			except:
				primary_email = "Email not Given"
			save_user(users['id'], 
					  users['name'],
					  primary_email, 
					  primary_mobile, 
					  users['practice_id'], 
					  users['has_photo'])
		try:
			doctor = request.session['doctor']
			print doctor
		except:
			r = requests.get(DOCTOR_API_URL, headers=headers)
			doctor = json.loads(r.content)
			request.session['doctor'] = doctor
		save_doctor(doctor['id'], doctor['name'])
		campaigns = Campaign.objects.filter(doctor_id=doctor['id'])
		for items in campaigns:
			user_campaign = UserCampaign.objects.filter(campaign=items.id, seen_campaign=True)
			a.append((len(user_campaign), items.campaign_name))

	loggedin = request.session['loggedin']
	return render_to_response('login_as_doctor.html',{'content':patients,
													  'campaign':a,
													  'form':form,
													  'loggedin':loggedin},RequestContext(request))