diff --git a/commentaries/views.py b/commentaries/views.py index 4d2a94b2b60b4a05ad6482cd149fa3f3a29c7351..4d666905e3b0f82842817ecb0102b73c1e32e849 100644 --- a/commentaries/views.py +++ b/commentaries/views.py @@ -15,9 +15,11 @@ from .forms import * from comments.models import Comment, AuthorReply from comments.forms import CommentForm -from contributors.forms import AuthenticationForm +from contributors.forms import TITLE_CHOICES, AuthenticationForm from ratings.forms import CommentRatingForm, AuthorReplyRatingForm, CommentaryRatingForm +title_dict = dict(TITLE_CHOICES) # Convert titles for use in emails + ################ # Commentaries ################ @@ -73,24 +75,24 @@ def vet_commentary_request_ack(request, commentary_id): # accept the commentary as is commentary.vetted = True commentary.save() - email_text = 'The Commentary Page you have requested, concerning publication with title ' + commentary.pub_title + ' by ' + commentary.author_list + ', has been activated. You are now welcome to submit your comments.' + '\n\nThank you for your contribution, \nThe SciPost Team.' - emailmessage = EmailMessage('SciPost Commentary Page activated', email_text, 'commentaries@scipost.org', [request.user.email, 'commentaries@scipost.org'], reply_to=['commentaries@scipost.org']) + email_text = 'Dear ' + title_dict[commentary.requested_by.title] + ' ' + commentary.requested_by.user.last_name + ', \n\n The Commentary Page you have requested, concerning publication with title ' + commentary.pub_title + ' by ' + commentary.author_list + ', has been activated. You are now welcome to submit your comments.' + '\n\nThank you for your contribution, \nThe SciPost Team.' + emailmessage = EmailMessage('SciPost Commentary Page activated', email_text, 'commentaries@scipost.org', [commentary.requested_by.user.email, 'commentaries@scipost.org'], reply_to=['commentaries@scipost.org']) emailmessage.send(fail_silently=False) elif form.cleaned_data['action_option'] == '0': # re-edit the form starting from the data provided form2 = RequestCommentaryForm(initial={'pub_title': commentary.pub_title, 'arxiv_link': commentary.arxiv_link, 'pub_DOI_link': commentary.pub_DOI_link, 'author_list': commentary.author_list, 'pub_date': commentary.pub_date, 'pub_abstract': commentary.pub_abstract}) commentary.delete() - email_text = 'The Commentary Page you have requested, concerning publication with title ' + commentary.pub_title + ' by ' + commentary.author_list + ', has been activated (with slight modifications to your submitted details). You are now welcome to submit your comments.' + '\n\nThank you for your contribution, \nThe SciPost Team.' - emailmessage = EmailMessage('SciPost Commentary Page activated', email_text, 'commentaries@scipost.org', [request.user.email, 'commentaries@scipost.org'], reply_to=['commentaries@scipost.org']) + email_text = 'Dear ' + title_dict[commentary.requested_by.title] + ' ' + commentary.requested_by.user.last_name + ', \n\n The Commentary Page you have requested, concerning publication with title ' + commentary.pub_title + ' by ' + commentary.author_list + ', has been activated (with slight modifications to your submitted details). You are now welcome to submit your comments.' + '\n\nThank you for your contribution, \nThe SciPost Team.' + emailmessage = EmailMessage('SciPost Commentary Page activated', email_text, 'commentaries@scipost.org', [commentary.requested_by.user.email, 'commentaries@scipost.org'], reply_to=['commentaries@scipost.org']) emailmessage.send(fail_silently=False) context = {'form': form2 } return render(request, 'commentaries/request_commentary.html', context) elif form.cleaned_data['action_option'] == '2': # the commentary request is simply rejected - email_text = 'The Commentary Page you have requested, concerning publication with title ' + commentary.pub_title + ' by ' + commentary.author_list + ', has not been activated for the following reason: ' + form.cleaned_data['refusal_reason'] + '.\n\nThank you for your interest, \nThe SciPost Team.' + email_text = 'Dear ' + title_dict[commentary.requested_by.title] + ' ' + commentary.requested_by.user.last_name + ', \n\n The Commentary Page you have requested, concerning publication with title ' + commentary.pub_title + ' by ' + commentary.author_list + ', has not been activated for the following reason: ' + form.cleaned_data['refusal_reason'] + '.\n\nThank you for your interest, \nThe SciPost Team.' if form.cleaned_data['email_response_field']: email_text += '\n\nFurther explanations: ' + form.cleaned_data['email_response_field'] - emailmessage = EmailMessage('SciPost Commentary Page activated', email_text, 'commentaries@scipost.org', [request.user.email, 'commentaries@scipost.org'], reply_to=['comentaries@scipost.org']) + emailmessage = EmailMessage('SciPost Commentary Page activated', email_text, 'commentaries@scipost.org', [commentary.requested_by.user.email, 'commentaries@scipost.org'], reply_to=['comentaries@scipost.org']) emailmessage.send(fail_silently=False) commentary.delete() diff --git a/comments/views.py b/comments/views.py index 751cc881eb441c4189cb90e4fa4cf89d303b3022..dffc8d9ea196c17e7858c43a9c3ca6402c8f24ff 100644 --- a/comments/views.py +++ b/comments/views.py @@ -37,7 +37,7 @@ def vet_submitted_comment_ack(request, comment_id): # accept the comment as is comment.status = 1 comment.save() - email_text = 'The Comment you have submitted, concerning publication with title ' + email_text = 'Dear ' + comment.author.title + ' ' + comment.author.last_name + ', \n\n The Comment you have submitted, concerning publication with title ' if comment.commentary is not None: email_text + comment.commentary.pub_title + ' by ' + comment.commentary.author_list elif comment.submission is not None: diff --git a/contributors/forms.py b/contributors/forms.py index 8344a17caa795756f8759cc6f7c6bb953fbd2913..bd7d1be6367c90f4136831be8f75165e9b458201 100644 --- a/contributors/forms.py +++ b/contributors/forms.py @@ -21,6 +21,7 @@ class RegistrationForm(forms.Form): personalwebpage = forms.URLField(label='Personal web page', required=False) username = forms.CharField(label='username', max_length=100) password = forms.CharField(label='password', widget=forms.PasswordInput()) + password_verif = forms.CharField(label='verify pwd', widget=forms.PasswordInput()) class VetRegistrationForm(forms.Form): promote_to_rank_1 = forms.BooleanField(required=False) diff --git a/contributors/templates/contributors/register.html b/contributors/templates/contributors/register.html index 4220fe7a660bed0a2105c92d672515373ee4426e..cfe41fed883e5989d5b2b5e9bb60f300c98b14df 100644 --- a/contributors/templates/contributors/register.html +++ b/contributors/templates/contributors/register.html @@ -15,6 +15,9 @@ </table> <input type="submit" value="Submit" /> </form> + {% if errormessage %} + <p>{{ errormessage }}</p> + {% endif %} </section> {% endblock bodysup %} diff --git a/contributors/views.py b/contributors/views.py index 0eac4377e072583cf9706ab4cf85aacdf9f234d2..3270154b91a600365f5ab03e418a66e30f11fb6f 100644 --- a/contributors/views.py +++ b/contributors/views.py @@ -19,6 +19,8 @@ from comments.models import Comment, AuthorReply from reports.models import Report from submissions.models import Submission +title_dict = dict(TITLE_CHOICES) +reg_ref_dict = dict(REGISTRATION_REFUSAL_CHOICES) ################ # Registration @@ -31,6 +33,12 @@ def register(request): form = RegistrationForm(request.POST) # check whether it's valid if form.is_valid(): + # check for mismatching passwords + if form.cleaned_data['password'] != form.cleaned_data['password_verif']: + return render(request, 'contributors/register.html', {'form': form, 'errormessage': 'Your passwords must match'}) + # check for already-existing username + if User.objects.filter(username=form.cleaned_data['username']).exists(): + return render(request, 'contributors/register.html', {'form': form, 'errormessage': 'This username is already in use'}) # create the user user = User.objects.create_user ( first_name = form.cleaned_data['first_name'], @@ -47,7 +55,7 @@ def register(request): personalwebpage = form.cleaned_data['personalwebpage'], ) contributor.save() - email_text = 'Dear ' + contributor.title + ' ' + contributor.user.last_name + ', \n Your request for registration to the SciPost publication portal has been received, and will be processed soon. Many thanks for your interest. \n\n The SciPost Team.' + email_text = 'Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + ', \n\n Your request for registration to the SciPost publication portal has been received, and will be processed soon. Many thanks for your interest. \n\n The SciPost Team.' emailmessage = EmailMessage('SciPost registration request received', email_text, 'registration@scipost.org', [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) emailmessage.send(fail_silently=False) return HttpResponseRedirect('thanks_for_registering') @@ -55,7 +63,8 @@ def register(request): else: form = RegistrationForm() - return render(request, 'contributors/register.html', {'form': form}) + errormessage = '' + return render(request, 'contributors/register.html', {'form': form, 'errormessage': errormessage}) def thanks_for_registering(request): @@ -79,14 +88,15 @@ def vet_registration_request_ack(request, contributor_id): if form.cleaned_data['promote_to_rank_1']: contributor.rank = 1 contributor.save() - email_text = 'Dear ' + contributor.title + ' ' + contributor.user.last_name + ', \n Your registration to the SciPost publication portal has been accepted. You can now login and contribute. \n\n The SciPost Team.' - emailmessage = EmailMessage('SciPost registration accepted', email_text, 'registration@scipost.org', [contributor.user.email, 'jscaux@gmail.com'], reply_to=['J.S.Caux@uva.nl']) + email_text = 'Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + ', \n\n Your registration to the SciPost publication portal has been accepted. You can now login and contribute. \n\n The SciPost Team.' + emailmessage = EmailMessage('SciPost registration accepted', email_text, 'registration@scipost.org', [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) emailmessage.send(fail_silently=False) else: - email_text = 'Dear ' + contributor.title + ' ' + contributor.user.last_name + ', \n Your registration to the SciPost publication portal has been turned down, the reason being: ' + form.cleaned_data['refusal_reason'] + '. You can however still view all SciPost contents, just not submit papers, comments or votes. We nonetheless thank you for your interest. \n\n The SciPost Team.' + ref_reason = int(form.cleaned_data['refusal_reason']) + email_text = 'Dear ' + title_dict[contributor.title] + ' ' + contributor.user.last_name + ', \n\n Your registration to the SciPost publication portal has been turned down, the reason being: ' + reg_ref_dict[ref_reason] + '. You can however still view all SciPost contents, just not submit papers, comments or votes. We nonetheless thank you for your interest. \n\n The SciPost Team.' if form.cleaned_data['email_response_field']: email_text += '\n\nFurther explanations: ' + form.cleaned_data['email_response_field'] - emailmessage = EmailMessage('SciPost registration: unsuccessful', email_text, 'noreply@scipost.org', [contributor.user.email, 'jscaux@gmail.com'], reply_to=['J.S.Caux@uva.nl']) + emailmessage = EmailMessage('SciPost registration: unsuccessful', email_text, 'registration@scipost.org', [contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) emailmessage.send(fail_silently=False) contributor.rank = form.cleaned_data['refusal_reason'] contributor.save() @@ -100,7 +110,7 @@ def login_view(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) - if user is not None: + if user is not None and user.contributor.rank > 0: if user.is_active: login(request, user) contributor = Contributor.objects.get(user=request.user) @@ -123,10 +133,6 @@ def logout_view(request): def personal_page(request): if request.user.is_authenticated(): contributor = Contributor.objects.get(user=request.user) - # email testing 2015-12-16: works! - #emailmessage = EmailMessage('Welcome to your personal page.', 'Hello', 'noreply@scipost.org', [contributor.user.email, 'jscaux@gmail.com'], reply_to=['J.S.Caux@uva.nl']) - #emailmessage.send(fail_silently=False) - # if an editor, count the number of actions required: nr_reg_to_vet = 0 nr_submissions_to_process = 0