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))