diff --git a/openslides/main.py b/openslides/main.py index 9f3f94301..91f4156d3 100644 --- a/openslides/main.py +++ b/openslides/main.py @@ -173,13 +173,15 @@ def create_or_reset_admin_user(): # can't be imported in global scope as it already requires # the settings module during import from django.contrib.auth.models import User + from openslides.config.models import config try: obj = User.objects.get(username = "admin") except User.DoesNotExist: User.objects.create_superuser( - username = "admin", - password = "admin", - email = "admin@example.com") + username="admin", + password="admin", + email="admin@example.com") + config['admin_password'] = "admin" print("Created default admin user") return diff --git a/openslides/participant/templates/participant/login.html b/openslides/participant/templates/participant/login.html index 3723df145..908ed02d8 100644 --- a/openslides/participant/templates/participant/login.html +++ b/openslides/participant/templates/participant/login.html @@ -27,12 +27,20 @@ {% trans "Your username and password were not accepted. Please try again." %} {% endfor %} - {% endif %} + {% if first_time_message %} +
+ + close + + {{ first_time_message|safe }} +
+ {% endif %} +
{% csrf_token %} diff --git a/openslides/participant/views.py b/openslides/participant/views.py index 36ef71f8a..bb8cfefbb 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -31,6 +31,7 @@ from django.contrib import messages from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User, Group from django.contrib.auth.forms import PasswordChangeForm +from django.contrib.auth.views import login as django_login from django.core.urlresolvers import reverse from django.shortcuts import redirect from django.utils.translation import ugettext as _, ungettext @@ -40,7 +41,7 @@ from openslides.utils.pdf import stylesheet from openslides.utils.template import Tab from openslides.utils.utils import (template, permission_required, gen_confirm_form, ajax_request, decodedict, encodedict, - delete_default_permissions) + delete_default_permissions, html_strong) from openslides.utils.views import FormView, PDFView from openslides.config.models import config @@ -563,6 +564,21 @@ def reset_password(request, user_id): return redirect(reverse('user_edit', args=[user_id])) +def login(request): + try: + admin = User.objects.get(pk=1) + if admin.check_password(config['admin_password']): + first_time_message = _("The password for the user %(user)s is " + "%(password)s. Please change it") % { + 'user': html_strong(admin.username), + 'password': html_strong(config['admin_password'])} + else: + first_time_message = None + except User.DoesNotExist: + first_time_message = None + return django_login(request, template_name='participant/login.html', extra_context={'first_time_message': first_time_message}) + + def register_tab(request): """ Register the participant tab. diff --git a/openslides/urls.py b/openslides/urls.py index 47dd142cf..d3f0e9d91 100644 --- a/openslides/urls.py +++ b/openslides/urls.py @@ -16,9 +16,9 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.shortcuts import redirect from django.utils.importlib import import_module - from openslides.utils.views import FrontPage + handler500 = 'openslides.utils.views.server_error' urlpatterns = patterns('', @@ -59,8 +59,7 @@ urlpatterns += patterns('', (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), url(r'^login/$', - 'django.contrib.auth.views.login', - {'template_name': 'participant/login.html'}, + 'openslides.participant.views.login', name='user_login', ),