1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-07-07 13:04:01 +02:00

Send password init mail

This commit is contained in:
Alexandre Iooss
2019-08-09 23:12:56 +02:00
parent d1806fd727
commit 8b27710266
5 changed files with 58 additions and 92 deletions

View File

@ -3,7 +3,9 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib import admin
from django.contrib import messages
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import PasswordResetForm
from django.core.urlresolvers import reverse
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
@ -72,6 +74,23 @@ class UserAdmin(VersionAdmin, BaseUserAdmin):
}),
)
def save_model(self, request, obj, form, change):
"""
On creation, send a password init mail
"""
super().save_model(request, obj, form, change)
if not change:
# Virtually fill the password reset form
password_reset = PasswordResetForm(data={'email': obj.email})
if password_reset.is_valid():
password_reset.save(request=request,
use_https=request.is_secure())
messages.success(request, _("An email to set the password"
" was sent."))
else:
messages.error(request, _("The email is invalid."))
def is_adherent(self, obj):
"""
Get current membership year and check if user is there