Ejemplo n.º 1
0
def add_friend(request, friend_id):
        self_user = get_object_or_404(UserProfile, user = request.user.id)
	friend = get_object_or_404(UserProfile, user_id = friend_id)

	UserProfile.add_friend(self_user, friend, 1)
#	print (a.to_person)
	return HttpResponse(friend)
Ejemplo n.º 2
0
def home(request):
	not_friends = []
	all_users = UserProfile.objects.all()
	self_userprofile = get_object_or_404(UserProfile, user = request.user.id)

#	for user in all_users:
#		if UserProfile.is_friend(self_userprofile, user):
#			continue
#		else:
#			not_friends.append(user)
#	not_friends = UserProfile.objects.all()
#	friends = FriendRelations.objects.filter(from_person = request.user)
        self_user = get_object_or_404(UserProfile, user = request.user.id)
	friends = UserProfile.get_friends(self_user, 1)

	following = FollowRelations.objects.filter(from_person  = request.user.id)
	followers = FollowRelations.objects.filter(to_person = request.user.id)

        return render_to_response("networks/home.html", {
							'all_users':all_users,
#                                                        'not_friends': not_friends,
                                                        'friends': friends,
                                                        'following': following,
                                                        'followers': followers
                                                        },
                                                                context_instance = RequestContext(request))
Ejemplo n.º 3
0
def signup(request):
	next_page = request.POST.get('next', None)
	if request.user.is_authenticated():
		return HttpResponseRedirect('/home/')
	if request.method == 'POST':
		print("As post")
		new_data = request.POST.copy()
		form = SignupForm(new_data)
		print("data binded to form")
		if form.errors:
			print(form.errors)
		if form.is_valid():
			print("valid form.")
			first_name = form.cleaned_data['first_name']
			last_name = form.cleaned_data['last_name']
			username = form.cleaned_data['username']
			password = form.cleaned_data['password1']
			email = form.cleaned_data['email']
			designation = form.cleaned_data['designation']
			gender = form.cleaned_data['gender']
			dob = form.cleaned_data['dob']
			college = form.cleaned_data['college']
			course = form.cleaned_data['course']
			year = form.cleaned_data['year']

			print(email)
			# if there are no form or field errors:
			if form.errors is None or len(form.errors) <= 0:	
				new_user = form.save(new_data)
				new_user.is_active = False
				new_user.save()
#				User.objects.create_user()

				print(new_user.username)
				print(new_user.email)	
				print(new_user.password)
				print(new_data["email"])
				print(new_data["course"])			
				
				# Generating account activation key 
				salt = sha.new(str(random.random())).hexdigest()[:5]
				activation_key = sha.new(salt+new_user.email).hexdigest()
				key_expires = timezone.now() + datetime.timedelta(1)
				new_profile = UserProfile(user=new_user, gender=gender, dob=dob, college=college, course=course, year=year)
				new_signup_data = SignupData(user=new_user, activation_key=activation_key, key_expires=key_expires)
				new_profile.save()
		
				# sending key to user's email account

				#try:
				subject = 'Archilane.com account confirmation'
				from_email = '*****@*****.**'	
			
				text_content = "Account confirmation mail</br>"
				html_content = "<p>To activate your account click on this link within<span style='color:red;'>24 hours</span>:<a href='http://test.archilane.com/signup/%s'>www.archilane.com/signup/%s</a></p>"%(new_signup_data.activation_key,new_signup_data.activation_key)
				email = EmailMultiAlternatives(subject, text_content, from_email, [new_user.email])
				
				email.attach_alternative(html_content, 'text/html')
				
				print(email)

				if email.send():
					print("email.send()")
					new_signup_data.save()
					return render_to_response('frontend/landing_page/mail_sent.html', context_instance=RequestContext(request))	
				else:
					return render_to_response('login_form/retry_email_sending.html', context_instance=RequestContext(request))		
				#except: return render_to_response('login_form/email_sending_failed.html', context_instance=RequestContext(request))
				

				return HttpResponseRedirect('/site_auth/signin/')
			else:
				message = "Signup errors"
				return render_to_response('frontend/landing_page/landing_page.html',{'message':message}, context_instance = RequestContext(request))		
		else:
			message = "Invalid form"
			return render_to_response('frontend/landing_page/landing_page.html', {'message':message}, context_instance = RequestContext(request))
		#form = SignupForm()
	return render_to_response('frontend/landing_page/landing_page.html', context_instance = RequestContext(request))
Ejemplo n.º 4
0
def del_friend(request, friend_id):
        self_user = get_object_or_404(UserProfile, user = request.user.id)
        friend = get_object_or_404(UserProfile, user_id = friend_id)

        UserProfile.remove_friend(self_user, friend, 1)
        return HttpResponse("Done..deleted succesfully")