def register(request): WEB_FILES, LIVE_SITE, totalNumberOfGames, sendBackUrl, startOffset, \ user, userId, message, topHits, topRated = initialVars(request) #Need this in the event that they don't process the form and nav to login sendBackUrl = '/' if request.method == 'GET': # Form has no data yet. request.session['sendBackUrl'] = request.GET.get('sendBack', '/') captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR']) form = RegisterUser(initial={'captchaHash': captchaHash}) return render_to_response('register.html', locals()) elif request.method == 'POST': # Form has data. form = RegisterUser(request.POST) if form.is_valid(): name = form.cleaned_data['name'] password1 = form.cleaned_data['password1'] password2 = form.cleaned_data['password2'] captchaHash = form.cleaned_data['captchaHash'] captchaEntry = form.cleaned_data['captchaEntry'] captchaEntry = captchaEntry.lower() description = form.cleaned_data['description'] if password1 != password2: captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR']) form = RegisterUser(initial={ 'captchaHash': captchaHash, 'name': name }) error = 'Passwords do not match. Please re-enter.' #log(request, 'REGISTERUSERERROR', name, "Password don\'t match") return render_to_response('register.html', locals()) SALT = flashburrito.settings.SECRET_KEY[:20] hashEntry = sha.new(SALT + captchaEntry).hexdigest() if captchaHash == hashEntry: # User entered valid Captcha code User.objects.create_user(name, '', password1) user = authenticate(username=name, password=password1) if description != "": userProfile = UserProfile(user=user, description=description) userProfile.save() #log(request, 'REGISTERUSER', name, 'Valid Registration') login(request, user) else: # User entered invalid Captcha code captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR']) form = RegisterUser(initial={ 'captchaHash': captchaHash, 'name': name }) error = 'Invalid Captcha Code. Please Enter again.' #log(request, 'REGISTERUSERERROR', name, "Invalid Captcha Code") return render_to_response('register.html', locals()) else: # Form is not valid captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR']) #TODO should parse through form and log exact error #log(request, 'REGISTERUSERERROR', "Bad Form", "Other: Form is Not Valid") return render_to_response('register.html', locals()) sendBackUrl = request.session.get('sendBackUrl', '/') request.session['sendBackUrl'] = None return HttpResponseRedirect(sendBackUrl)
def register(request): WEB_FILES, LIVE_SITE, totalNumberOfGames, sendBackUrl, startOffset, \ user, userId, message, topHits, topRated = initialVars(request) #Need this in the event that they don't process the form and nav to login sendBackUrl = '/' if request.method == 'GET': # Form has no data yet. request.session['sendBackUrl'] = request.GET.get('sendBack', '/') captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR'] ) form = RegisterUser(initial={'captchaHash': captchaHash}) return render_to_response('register.html', locals()) elif request.method == 'POST': # Form has data. form = RegisterUser(request.POST) if form.is_valid(): name = form.cleaned_data['name'] password1 = form.cleaned_data['password1'] password2 = form.cleaned_data['password2'] captchaHash = form.cleaned_data['captchaHash'] captchaEntry = form.cleaned_data['captchaEntry'] captchaEntry = captchaEntry.lower() description = form.cleaned_data['description'] if password1 != password2: captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR'] ) form = RegisterUser(initial={'captchaHash': captchaHash, 'name': name}) error = 'Passwords do not match. Please re-enter.' #log(request, 'REGISTERUSERERROR', name, "Password don\'t match") return render_to_response('register.html', locals()) SALT = flashburrito.settings.SECRET_KEY[:20] hashEntry = sha.new(SALT+captchaEntry).hexdigest() if captchaHash == hashEntry: # User entered valid Captcha code User.objects.create_user(name, '', password1) user = authenticate(username=name, password=password1) if description != "": userProfile = UserProfile( user=user, description=description ) userProfile.save() #log(request, 'REGISTERUSER', name, 'Valid Registration') login(request, user) else: # User entered invalid Captcha code captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR'] ) form = RegisterUser(initial={'captchaHash': captchaHash, 'name': name}) error = 'Invalid Captcha Code. Please Enter again.' #log(request, 'REGISTERUSERERROR', name, "Invalid Captcha Code") return render_to_response('register.html', locals()) else: # Form is not valid captchaImageURL, captchaHash = makeCaptchaImage( request.META['REMOTE_ADDR'] ) #TODO should parse through form and log exact error #log(request, 'REGISTERUSERERROR', "Bad Form", "Other: Form is Not Valid") return render_to_response('register.html', locals()) sendBackUrl = request.session.get('sendBackUrl', '/') request.session['sendBackUrl'] = None return HttpResponseRedirect(sendBackUrl)