def change_profile(request): if request.method == 'POST': form = ChangeProfileForm(request.POST, instance=request.user) capt = CaptchaTestForm(request.POST) print(request.user.check_password('12341234')) if form.is_valid() and capt.is_valid(): print(request.user.check_password('12341234')) if request.user.is_authenticated(): if request.user.check_password(form.cleaned_data['current_password']): try: form.save() if len(form.cleaned_data['new_password']) > 0: request.user.set_password(form.cleaned_data['new_password']) request.user.save() except: return render_to_response('change_profile.html', {'change_profile_form': form, 'capcha_form': capt}, context_instance=RequestContext(request)) return HttpResponseRedirect(domain) return render_to_response('change_profile.html', {'change_profile_form': form, 'capcha_form': capt}, context_instance=RequestContext(request)) else: if request.user.is_authenticated(): if not find_out_if_user_was_registered_using_django_social_auth(request.user): form = ChangeProfileForm(instance=request.user) capt = CaptchaTestForm() return render_to_response('change_profile.html', {'change_profile_form': form, 'capcha_form': capt}, context_instance=RequestContext(request)) else: provider = get_provider(request.user) return HttpResponse('You logged in using ' + provider + " That's all we know. We promise")
def subscribe(request): if request.method == "POST": capt = CaptchaTestForm(request.POST) form = RegisterForm(request.POST) if form.is_valid() and capt.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] email = form.cleaned_data['email'] my_user = None try: my_user = User.objects.create_user(username, email, password) except IntegrityError: return render_to_response('subscribe.html', {'user_form': form}, context_instance=RequestContext(request)) my_user.first_name = form.cleaned_data['first_name'] my_user.last_name = form.cleaned_data['last_name'] my_user.is_staff = False my_user.save() #now log the user in user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password']) if user is not None: auth_login(request, user) return HttpResponseRedirect(domain+'/figure_out_if_post_data_is_in_session') #send the user to log himself in else: #this is for the inappbrowser return HttpResponseRedirect(domain+'/login') else: return render_to_response("subscribe.html", {"user_form": form, 'capcha_form': capt}, context_instance=RequestContext(request)) #method is get else: capt = CaptchaTestForm() form = RegisterForm() return render_to_response("subscribe.html", {"user_form": form, 'capcha_form': capt}, context_instance=RequestContext(request))