feat(profile): Add a way to reset/generate a wifi password
TODO: Maybe switch to a post request, as it modifies the internal state
This commit is contained in:
parent
6a581fcec4
commit
fb70bf13f8
3 changed files with 42 additions and 8 deletions
|
@ -9,15 +9,28 @@
|
|||
</h2>
|
||||
<hr>
|
||||
|
||||
{% if user.kanidm.radius_secret %}
|
||||
<h3 class="has-text-weight-bold mb-3">{% trans "Mot de passe WiFi :" %}</h3>
|
||||
{% if user.kanidm %}
|
||||
<h3 class="has-text-weight-bold mb-3">
|
||||
<span>{% trans "Mot de passe WiFi :" %}</span>
|
||||
{% if user.kanidm.radius_secret %}
|
||||
{% trans "Êtes-vous sûr·e de vouloir réinitialiser votre mot de passe WiFi ?" as confirm_wifi_reset %}
|
||||
<a href="{% url "dgsi:dgn-generate_wifi_password" %}"
|
||||
class="tag is-warning is-light is-medium is-pulled-right"
|
||||
onclick="return confirm('{{ confirm_wifi_reset }}')">{% trans "Réinitialiser le mot de passe WiFi" %}</a>
|
||||
{% endif %}
|
||||
</h3>
|
||||
|
||||
<input id="radius-secret"
|
||||
onclick="document.querySelector('#radius-secret').select()"
|
||||
class="button is-fullwidth is-primary is-size-4"
|
||||
value="{{ user.kanidm.radius_secret }}"
|
||||
readonly />
|
||||
<br>
|
||||
{% if user.kanidm.radius_secret %}
|
||||
<input id="radius-secret"
|
||||
onclick="document.querySelector('#radius-secret').select()"
|
||||
class="button is-fullwidth is-primary is-size-4"
|
||||
value="{{ user.kanidm.radius_secret }}"
|
||||
readonly />
|
||||
<br>
|
||||
{% else %}
|
||||
<a href="{% url "dgsi:dgn-generate_wifi_password" %}"
|
||||
class="button is-fullwidth is-primary is-light is-size-4 block">{% trans "Générer un mot de passe WiFi" %}</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<h3 class="has-text-weight-bold mb-3">{% trans "Adresse e-mail :" %}</h3>
|
||||
|
|
|
@ -20,6 +20,11 @@ urlpatterns = [
|
|||
),
|
||||
# Account views
|
||||
path("accounts/profile/", views.ProfileView.as_view(), name="dgn-profile"),
|
||||
path(
|
||||
"accounts/generate-wifi-password/",
|
||||
views.GenerateWiFiPasswordView.as_view(),
|
||||
name="dgn-generate_wifi_password",
|
||||
),
|
||||
path(
|
||||
"accounts/create/",
|
||||
views.CreateSelfAccountView.as_view(),
|
||||
|
|
|
@ -75,6 +75,22 @@ class ProfileView(LoginRequiredMixin, TemplateView):
|
|||
)
|
||||
|
||||
|
||||
class GenerateWiFiPasswordView(LoginRequiredMixin, RedirectView):
|
||||
url = reverse_lazy("dgsi:dgn-profile")
|
||||
|
||||
def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponseBase:
|
||||
user = User.from_request(self.request)
|
||||
|
||||
if user.kanidm is None:
|
||||
messages.error(self.request, _("Compte DGNum inexistant."))
|
||||
elif not user.kanidm.radius_secret:
|
||||
messages.error(self.request, _("Mot de passe WiFi déjà existant."))
|
||||
else:
|
||||
async_to_sync(klient.call_post)(f"/v1/person/{user.username}/_radius")
|
||||
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
|
||||
# INFO: We subclass AccessMixin and not LoginRequiredMixin because the way we want to
|
||||
# use dispatch means that we need to execute the login check anyways.
|
||||
class CreateSelfAccountView(AccessMixin, SuccessMessageMixin, FormView):
|
||||
|
|
Loading…
Reference in a new issue