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:
@ -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
|
||||
|
Reference in New Issue
Block a user