diff --git a/plinth/modules/users/templates/users_firstboot.html b/plinth/modules/users/templates/users_firstboot.html index 6fb326b81..4229413e6 100644 --- a/plinth/modules/users/templates/users_firstboot.html +++ b/plinth/modules/users/templates/users_firstboot.html @@ -10,21 +10,57 @@ {% block content %}

{% trans "Administrator Account" %}

-

- {% blocktrans trimmed %} - Choose a username and password to access this web interface. - The password can be changed later. This user will be granted - administrative privileges. Other users can be added later. - {% endblocktrans %} -

+ {% if not admin_users %} +

+ {% blocktrans trimmed %} + Choose a username and password to access this web interface. + The password can be changed later. This user will be granted + administrative privileges. Other users can be added later. + {% endblocktrans %} +

-
- {% csrf_token %} + + {% csrf_token %} - {{ form|bootstrap }} + {{ form|bootstrap }} - -
+ + + {% else %} + + +

+ {% blocktrans trimmed %} + The following administrator accounts exist in the system. + {% endblocktrans %} +

+ + + +

+ {% blocktrans trimmed %} + Delete these accounts from command line and refresh the page to create + an account that is usable with {{ box_name }}. On the command line run + the command 'echo "{password}" | /usr/share/plinth/actions/users + remove-user {username}'. If an account is already usable with + {{ box_name }}, skip this step. + {% endblocktrans %} +

+ +
+ {% csrf_token %} + + +
+ {% endif %} {% endblock %} - diff --git a/plinth/modules/users/views.py b/plinth/modules/users/views.py index 3cb9a365c..f11b55d55 100644 --- a/plinth/modules/users/views.py +++ b/plinth/modules/users/views.py @@ -6,6 +6,7 @@ from django.contrib.auth import update_session_auth_hash from django.contrib.auth.models import User from django.contrib.messages.views import SuccessMessageMixin from django.core.exceptions import PermissionDenied +from django.http import HttpResponseRedirect from django.urls import reverse, reverse_lazy from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy @@ -185,6 +186,24 @@ class FirstBootView(django.views.generic.CreateView): form_class = FirstBootForm + def dispatch(self, request, *args, **kwargs): + """Check if there is no possibility to create a new admin account.""" + if request.method == 'POST' and 'skip' in request.POST: + first_boot.mark_step_done('users_firstboot') + return HttpResponseRedirect(reverse(first_boot.next_step())) + + return super().dispatch(request, *args, **kwargs) + + def get_context_data(self, *args, **kwargs): + """Add admin users to context data.""" + context = super().get_context_data(*args, **kwargs) + + output = actions.superuser_run('users', ['get-group-users', 'admin']) + admin_users = output.strip().split('\n') if output.strip() else [] + context['admin_users'] = admin_users + + return context + def get_form_kwargs(self): """Make request available to the form (to insert messages)""" kwargs = super(FirstBootView, self).get_form_kwargs()