SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 432b05a2 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Solve invited reg bug using hidden field in reg form

parent 12ee9bb4
No related branches found
No related tags found
No related merge requests found
...@@ -35,8 +35,7 @@ class RegistrationForm(forms.Form): ...@@ -35,8 +35,7 @@ class RegistrationForm(forms.Form):
password = forms.CharField(label='* Password', widget=forms.PasswordInput()) password = forms.CharField(label='* Password', widget=forms.PasswordInput())
password_verif = forms.CharField(label='* Verify pwd', widget=forms.PasswordInput()) password_verif = forms.CharField(label='* Verify pwd', widget=forms.PasswordInput())
captcha = CaptchaField(label='* I am not a robot') captcha = CaptchaField(label='* I am not a robot')
invited = forms.BooleanField(widget=forms.HiddenInput())
class RegistrationInvitationForm(forms.ModelForm): class RegistrationInvitationForm(forms.ModelForm):
class Meta: class Meta:
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<section> <section>
<h1>Register to SciPost</h1> <h1>Register to SciPost</h1>
{% if welcome_message %}<!-- Temporary: only see form if invited (thus welcome_message exists) --> {% if form.invited %}<!-- Temporary: only see form if invited (thus welcome_message exists) -->
<div class="flex-greybox"> <div class="flex-greybox">
<h2>{{ welcome_message }}</h2> <h2>{{ welcome_message }}</h2>
......
...@@ -114,6 +114,9 @@ def register(request): ...@@ -114,6 +114,9 @@ def register(request):
form = RegistrationForm(request.POST) form = RegistrationForm(request.POST)
Utils.load({'form': form}) Utils.load({'form': form})
if form.is_valid(): if form.is_valid():
if form['invited'] == False:
return render(request, 'scipost/register.html',
{'form': form, 'errormessage': 'Registration is by invitation only at this stage. Come back after 1 May!'})
if Utils.password_mismatch(): if Utils.password_mismatch():
return render(request, 'scipost/register.html', return render(request, 'scipost/register.html',
{'form': form, 'errormessage': 'Your passwords must match'}) {'form': form, 'errormessage': 'Your passwords must match'})
...@@ -128,6 +131,7 @@ def register(request): ...@@ -128,6 +131,7 @@ def register(request):
return HttpResponseRedirect('thanks_for_registering') return HttpResponseRedirect('thanks_for_registering')
else: else:
form = RegistrationForm() form = RegistrationForm()
form['invited'] = False
context = {'form': form} context = {'form': form}
return render(request, 'scipost/register.html', context) return render(request, 'scipost/register.html', context)
...@@ -271,6 +275,7 @@ def accept_invitation(request, key): ...@@ -271,6 +275,7 @@ def accept_invitation(request, key):
form.fields['last_name'].initial = invitation.last_name form.fields['last_name'].initial = invitation.last_name
form.fields['first_name'].initial = invitation.first_name form.fields['first_name'].initial = invitation.first_name
form.fields['email'].initial = invitation.email_address form.fields['email'].initial = invitation.email_address
form.fields['invited'].initial = True
errormessage = '' errormessage = ''
welcome_message = 'Welcome, ' + title_dict[invitation.title] + ' ' + invitation.last_name + ', and thanks in advance for registering (by completing this form)' welcome_message = 'Welcome, ' + title_dict[invitation.title] + ' ' + invitation.last_name + ', and thanks in advance for registering (by completing this form)'
return render(request, 'scipost/register.html', {'form': form, 'errormessage': errormessage, 'welcome_message': welcome_message}) return render(request, 'scipost/register.html', {'form': form, 'errormessage': errormessage, 'welcome_message': welcome_message})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment