diff --git a/commentaries/templates/commentaries/commentary_detail.html b/commentaries/templates/commentaries/commentary_detail.html index dbfd7b14f25be610c8495f2d26155763e5192653..48ff4b50d9db16dff60c67b88b573df09eebc498 100644 --- a/commentaries/templates/commentaries/commentary_detail.html +++ b/commentaries/templates/commentaries/commentary_detail.html @@ -3,7 +3,8 @@ {% block pagetitle %}: Commentary detail{% endblock pagetitle %} {% block headsup %} -<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> + +<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> --> <script> $(document).ready(function(){ diff --git a/scipost/global_methods.py b/scipost/global_methods.py new file mode 100644 index 0000000000000000000000000000000000000000..bbdf43ddd0b6ecd9dcfd8fdfc74560ebc31ad73e --- /dev/null +++ b/scipost/global_methods.py @@ -0,0 +1,9 @@ +from django.contrib.auth.models import User + +from .models import * + +class Global(object): + + @classmethod + def get_user(cls, request): + Contributor.objects.get(user=request.user) diff --git a/scipost/templates/scipost/FAQ.html b/scipost/templates/scipost/FAQ.html index 586b00200f6d12f7bffdc0207d1859942b4483b6..aa19b009acb3bb58e9e7d58f900e3110f090df94 100644 --- a/scipost/templates/scipost/FAQ.html +++ b/scipost/templates/scipost/FAQ.html @@ -30,7 +30,7 @@ <br/> <h3>Who is behind SciPost?</h3> <ul> - <li>SciPost was founded by <a href="staff.fnwi.uva.nl/j.s.caux">J.-S. Caux</a>, Professor of Theoretical Physics at the University of Amsterdam.</li> + <li>SciPost was founded by <a href="http://staff.fnwi.uva.nl/j.s.caux">J.-S. Caux</a>, Professor of Theoretical Physics at the University of Amsterdam.</li> <li>The legal entity behind SciPost is Stichting SciPost, a not-for-profit Foundation established in Amsterdam. Its (non-remunerated) personnel consists in Prof. J.-S. Caux (chairman), Dr J. van Mameren (secretary) and Dr J. van Wezel (treasurer). </li> </ul> <br/> @@ -51,11 +51,11 @@ <br/> <h3>How is SciPost funded?</h3> <p>SciPost operates non-commercially, encurring minimal costs. Contributors provide all the content and perform all editorial tasks as part of their normal institutional academic duties. Operations are kept running by a team of officers, themselves academically employed.</p> - <p>Support for operational costs is initially provided by the <a href="http://www.nwo.nl/en">NWO</a> in the Netherlands. Long-term operations will be financed by donations from national funding agencies, universities, foundations and individuals</p> + <p>Support for operational costs is initially provided by the <a href="http://www.nwo.nl/en">NWO</a> in the Netherlands. Long-term operations will be financed by donations from national funding agencies, universities, foundations and individuals.</p> <br/> <h3>Which fields of science does SciPost cater to?</h3> <p>The initial rollout of SciPost offers a Physics portal.</p> - <p>Portals in Other fields of science will be opened if the SciPost model proves to be successful.</p> + <p>Portals in other fields of science will be opened if the SciPost model proves to be successful.</p> </div> </div> </section> diff --git a/scipost/templates/scipost/base.html b/scipost/templates/scipost/base.html index 36763107770f7a00fc931a0e2d49dcc24781486e..c10153ebb661632e8e5e817a4d905f590557dfdd 100644 --- a/scipost/templates/scipost/base.html +++ b/scipost/templates/scipost/base.html @@ -4,6 +4,8 @@ {% load staticfiles %} <link rel="stylesheet" type="text/css" href="{% static 'scipost/SciPost.css' %}" /> + <script src="https://code.jquery.com/jquery-2.2.0.min.js"></script> + <title>SciPost{% block pagetitle %}{% endblock pagetitle %}</title> {% block headsup %} diff --git a/scipost/templates/scipost/change_password.html b/scipost/templates/scipost/change_password.html index 29846710f67d3912bf302b7e1041c86b970ce2af..9ff0c90810398f61f4f49df350fa5157e5159a47 100644 --- a/scipost/templates/scipost/change_password.html +++ b/scipost/templates/scipost/change_password.html @@ -4,6 +4,13 @@ {% block bodysup %} +{% if ack %} +<section> + <h1>Your SciPost password has been successfully changed</h1> +</section> + +{% else %} + <section> <h1>Change your SciPost password</h1> <form action="{% url 'scipost:change_password' %}" method="post"> @@ -19,5 +26,6 @@ <p>{{ errormessage }}</p> {% endif %} </section> +{% endif %} {% endblock bodysup %} diff --git a/scipost/templates/scipost/change_password_ack.html b/scipost/templates/scipost/change_password_ack.html deleted file mode 100644 index 8b194e605d0eaa25494edad17885e0bb0b6acbce..0000000000000000000000000000000000000000 --- a/scipost/templates/scipost/change_password_ack.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends 'scipost/base.html' %} - -{% block pagetitle %}: password changed{% endblock pagetitle %} - -{% block bodysup %} - -<section> - <h1>Your SciPost password has been successfully changed</h1> -</section> - -{% endblock bodysup %} diff --git a/scipost/templates/scipost/header.html b/scipost/templates/scipost/header.html index 2c0a8203eb1e252f6ccc0b667b69317f1c4932dc..25575743b398835f2f7aa6dd9b7a33943d149c93 100644 --- a/scipost/templates/scipost/header.html +++ b/scipost/templates/scipost/header.html @@ -1,22 +1,22 @@ {% load staticfiles %} <header> <div class="row"> - <div class="col-3"> + <div class="col-4"> <!-- <a href="{% url 'scipost:index' %}"><h1>SciPost.org</h1></a> --> <h1> <font style="color: rgb(212,237,252)">Sci</font> <font style="color: rgb(247,164,0)">|</font> <font style="color: rgb(104,132,194)">Post</font> <font style="color: rgb(104,132,194)"></font></h1> </div> - <div class="col-3"> + <div class="col-4"> </div> {% if user.is_authenticated %} - <div class="col-6"> + <div class="col-4"> <p> <i>The complete scientific publication portal</i><br /> <i>Managed by professional scientists</i><br /> - <i>For freely, openly, globally and perpetually accessible science</i> + <i>For open, global and perpetual access science</i> </p> </div> {% endif %} diff --git a/scipost/urls.py b/scipost/urls.py index 7cbe5ea09f8948b39bc18fc092629b441d58648f..7f523219051d291162ab64b832007b236f03b54e 100644 --- a/scipost/urls.py +++ b/scipost/urls.py @@ -30,7 +30,7 @@ urlpatterns = [ url(r'^logout$', views.logout_view, name='logout'), url(r'^personal_page$', views.personal_page, name='personal_page'), url(r'^change_password$', views.change_password, name='change_password'), - url(r'^change_password_ack$', views.change_password_ack, name='change_password_ack'), + #url(r'^change_password_ack$', views.change_password_ack, name='change_password_ack'), url(r'^update_personal_data$', views.update_personal_data, name='update_personal_data'), url(r'^update_personal_data_ack$', views.update_personal_data_ack, name='update_personal_data_ack'), ] diff --git a/scipost/utils.py b/scipost/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..26be73d5fe138e67993ab031be34f0e4acfcd062 --- /dev/null +++ b/scipost/utils.py @@ -0,0 +1,75 @@ +import datetime +import hashlib +import random +import string + +from django.contrib.auth.models import User +from django.core.mail import EmailMessage +from django.utils import timezone + +from .models import * + + +class Utils(object): + + @classmethod + def load(cls, dict): + for var_name in dict: + setattr(cls, var_name, dict[var_name]) + + @classmethod + def password_mismatch(cls): + if cls.form.cleaned_data['password'] != cls.form.cleaned_data['password_verif']: + return True + else: + return False + + @classmethod + def username_already_taken(cls): + if User.objects.filter(username=cls.form.cleaned_data['username']).exists(): + return True + else: + return False + + @classmethod + def create_and_save_contributor(cls): + user = User.objects.create_user ( + first_name = cls.form.cleaned_data['first_name'], + last_name = cls.form.cleaned_data['last_name'], + email = cls.form.cleaned_data['email'], + username = cls.form.cleaned_data['username'], + password = cls.form.cleaned_data['password'] + ) + # Set to inactive until activation via email link + user.is_active = False + user.save() + contributor = Contributor ( + user=user, + title = cls.form.cleaned_data['title'], + orcid_id = cls.form.cleaned_data['orcid_id'], + country_of_employment = cls.form.cleaned_data['country_of_employment'], + address = cls.form.cleaned_data['address'], + affiliation = cls.form.cleaned_data['affiliation'], + personalwebpage = cls.form.cleaned_data['personalwebpage'], + ) + contributor.save() + Utils.load({'contributor': contributor}) + + @classmethod + def send_registration_email(cls): + # Generate email activation key and link + salt = "" + for i in range(5): + salt = salt + random.choice(string.ascii_letters) + salt = salt.encode('utf8') + usernamesalt = cls.contributor.user.username + usernamesalt = usernamesalt.encode('utf8') + cls.contributor.activation_key = hashlib.sha1(salt+usernamesalt).hexdigest() + cls.contributor.key_expires = datetime.datetime.strftime(datetime.datetime.now() + datetime.timedelta(days=2), "%Y-%m-%d %H:%M:%S") + cls.contributor.save() + email_text = 'Dear ' + title_dict[cls.contributor.title] + ' ' + cls.contributor.user.last_name + ', \n\nYour request for registration to the SciPost publication portal has been received. You now need to validate your email by visiting this link within the next 48 hours: \n\n' + 'https://scipost.org/activation/' + cls.contributor.activation_key + '\n\nYour registration will thereafter be vetted. Many thanks for your interest. \n\nThe SciPost Team.' + emailmessage = EmailMessage('SciPost registration request received', email_text, 'registration@scipost.org', [cls.contributor.user.email, 'registration@scipost.org'], reply_to=['registration@scipost.org']) + emailmessage.send(fail_silently=False) + + + diff --git a/scipost/views.py b/scipost/views.py index 2ac041b85f0caa81d1a4d09d1529b50fb84c722a..7de287c1d33f55e383fec5804184d24b16853238 100644 --- a/scipost/views.py +++ b/scipost/views.py @@ -16,6 +16,10 @@ from django.db.models import Avg from .models import * from .forms import * +from .global_methods import * +from .utils import * + + from commentaries.models import Commentary from comments.models import Comment, AuthorReply from submissions.models import Submission, Report @@ -58,7 +62,7 @@ def peer_witnessed_refereeing(request): title_dict = dict(TITLE_CHOICES) reg_ref_dict = dict(REGISTRATION_REFUSAL_CHOICES) -def register(request): +def register_old(request): if request.user.is_authenticated(): return HttpResponseRedirect('personal_page') # If POST, process the form data @@ -99,7 +103,6 @@ def register(request): salt = "" for i in range(5): salt = salt + random.choice(string.ascii_letters) - #salt = hashlib.sha1(str(random.random()).encode('utf8')).hexdigest()[:5] salt = salt.encode('utf8') usernamesalt = contributor.user.username usernamesalt = usernamesalt.encode('utf8') @@ -117,6 +120,25 @@ def register(request): errormessage = '' return render(request, 'scipost/register.html', {'form': form, 'errormessage': errormessage}) +def register(request): + if request.user.is_authenticated(): + return HttpResponseRedirect('personal_page') + if request.method == 'POST': + form = RegistrationForm(request.POST) + Utils.load({'form': form}) + if form.is_valid(): + if Utils.password_mismatch(): + return render(request, 'scipost/register.html', {'form': form, 'errormessage': 'Your passwords must match'}) + if Utils.username_already_taken(): + return render(request, 'scipost/register.html', {'form': form, 'errormessage': 'This username is already in use'}) + Utils.create_and_save_contributor() + Utils.send_registration_email() + return HttpResponseRedirect('thanks_for_registering') + else: + form = RegistrationForm() + errormessage = '' + return render(request, 'scipost/register.html', {'form': form, 'errormessage': errormessage}) + def thanks_for_registering(request): return render(request, 'scipost/thanks_for_registering.html') @@ -282,15 +304,17 @@ def change_password(request): # otherwise simply change the pwd: request.user.set_password(form.cleaned_data['password_new']) request.user.save() - return render(request, 'scipost/change_password_ack.html') + #return render(request, 'scipost/change_password_ack.html') + context = {'acknowledgment': True, 'form': PasswordChangeForm()} + return render(request, 'scipost/change_password.html', context) else: form = PasswordChangeForm() return render (request, 'scipost/change_password.html', {'form': form}) -def change_password_ack(request): - return render (request, 'scipost/change_password_ack.html') - +#def change_password_ack(request): +# return render (request, 'scipost/change_password_ack.html') +# def update_personal_data(request): if request.user.is_authenticated: diff --git a/submissions/templates/submissions/submission_detail.html b/submissions/templates/submissions/submission_detail.html index 735ed8f4984a61c23a92bf86790ef815cf4b63c7..b2db52aca5b1a0ee7dbf72f06352789d8cb4591a 100644 --- a/submissions/templates/submissions/submission_detail.html +++ b/submissions/templates/submissions/submission_detail.html @@ -3,7 +3,7 @@ {% block pagetitle %}: submission detail{% endblock pagetitle %} {% block headsup %} -<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> +<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> --> <script> $(document).ready(function(){