#306 show admin password if it hasn't changed

This commit is contained in:
Oskar Hahn 2012-07-18 10:46:07 +02:00
parent 68b7a22375
commit b327d41ee6
4 changed files with 37 additions and 12 deletions

View File

@ -173,6 +173,7 @@ 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:
@ -180,6 +181,7 @@ def create_or_reset_admin_user():
username="admin",
password="admin",
email="admin@example.com")
config['admin_password'] = "admin"
print("Created default admin user")
return

View File

@ -27,12 +27,20 @@
<em>{% trans "Your username and password were not accepted. Please try again." %}</em>
{% endfor %}
</div>
{% endif %}
{% if first_time_message %}
<div class="notification info">
<a class="close" href="#">
<img alt="close" title="{% trans 'Close this notification' %}" src="{% static 'images/icons/cross.png' %}">
</a>
<em>{{ first_time_message|safe }}</em>
</div>
{% endif %}
<script>
$("div.notification").click(function () {
$(this).hide("fast");
});
</script>
{% endif %}
<form method="post" action="{% url user_login %}">
{% csrf_token %}
<table>

View File

@ -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.

View File

@ -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',
),