def register(request): if request.method == 'POST': # Get the bound register form form = forms.RegisterForm(request.POST) # Validate the register form if form.is_valid(): validate_new_password_response = validate_new_password( form.cleaned_data['user_password'], form.cleaned_data['user_password_again']) if not validate_new_password_response['successful']: return render( request, 'login/register.html', { 'page_error': 'The passwords you entered do not match. Please enter the same password twice.', 'form': form }) new_user = User( user_email=form.cleaned_data['user_email'], user_password=form.cleaned_data['user_password'], user_team_name=form.cleaned_data['user_team_name'], user_referring_email=form.cleaned_data['user_referring_email']) new_user.user_password = new_user.hash_password() try: new_user.full_clean() except ValidationError as e: return render( request, 'login/register.html', { 'page_error': 'There was a problem during registration. Try again.', 'form': form }) else: new_user.save() request.session['user_id'] = new_user.user_id return HttpResponseRedirect('/home/') else: form = forms.RegisterForm() registration_locked = False week_one = Week.objects.get(week_number=1) if week_one.picks_lock < timezone.now(): registration_locked = True # Renders the register form if it's a new request return render(request, 'login/register.html', { 'form': form, 'registration_locked': registration_locked })
def register(request): if request.method == 'POST': # Get the bound register form form = forms.RegisterForm(request.POST) # Validate the register form if form.is_valid(): validate_new_password_response = validate_new_password(form.cleaned_data['user_password'], form.cleaned_data['user_password_again']) if not validate_new_password_response['successful']: return render(request, 'login/register.html', { 'page_error': 'The passwords you entered do not match. Please enter the same password twice.', 'form': form }) new_user = User( user_email = form.cleaned_data['user_email'], user_password = form.cleaned_data['user_password'], user_team_name = form.cleaned_data['user_team_name'], user_referring_email = form.cleaned_data['user_referring_email'] ) new_user.user_password = new_user.hash_password() try: new_user.full_clean() except ValidationError as e: return render(request, 'login/register.html', { 'page_error': 'There was a problem during registration. Try again.', 'form': form }) else: new_user.save() request.session['user_id'] = new_user.user_id return HttpResponseRedirect('/home/') else: form = forms.RegisterForm() registration_locked = False week_one = Week.objects.get(week_number=1) if week_one.picks_lock < timezone.now(): registration_locked = True # Renders the register form if it's a new request return render(request, 'login/register.html', { 'form': form, 'registration_locked': registration_locked })