Modified - Personalized the admin-created account notification email with the creator name and a direct set-password link.
This commit is contained in:
@@ -544,3 +544,8 @@ Project Change ID[date-time] - application-version - Type - Summary:
|
||||
108 - [2026-05-06 21:07:26] - v1.27.0-dev-99-gfc43980a5c - Type: Fixed - Made admin-created user notification and invitation emails use the current page locale.
|
||||
- 1 - I modified `services/mailer/mail_user.go` to add locale-aware variants for registration-notify and admin-invite emails, while preserving the existing user-language fallback helpers for other call sites.
|
||||
- 2 - I modified `routers/web/admin/users.go` and `routers/api/v1/admin/user.go` so admin-created account emails now use `ctx.Locale` from the current request instead of always rendering in the new account's empty or default language.
|
||||
|
||||
109 - [2026-05-06 22:11:33] - v1.27.0-dev-100-g70ef46362e - Type: Modified - Personalized the admin-created account notification email with the creator name and a direct set-password link.
|
||||
- 1 - I modified `services/mailer/mail_user.go` so the registration notification email now accepts the admin user, generates a time-limited `reset_password` token URL for the new account, and passes both values into the mail template.
|
||||
- 2 - I modified `routers/web/admin/users.go` and `routers/api/v1/admin/user.go` so the admin-created account notification now includes `ctx.Doer` when sending the non-invite email variant.
|
||||
- 3 - I modified `templates/mail/user/auth/register_notify.tmpl`, `options/locale/locale_en-US.json`, and `options/locale/locale_ro-RO.json` so the email explicitly states that the administrator created the account and instructs the recipient to use a personal password-setup link before signing in.
|
||||
|
||||
@@ -543,9 +543,10 @@
|
||||
"mail.account_request.rejected.text_2": "The account remains blocked until an administrator unblocks it.",
|
||||
"mail.register_notify": "Welcome to %s",
|
||||
"mail.register_notify.title": "%[1]s, welcome to %[2]s",
|
||||
"mail.register_notify.text_1": "This is your registration confirmation email for %s!",
|
||||
"mail.register_notify.text_2": "You can now log in via username: %s.",
|
||||
"mail.register_notify.text_3": "If this account has been created for you, please <a href=\"%s\">set your password</a> first.",
|
||||
"mail.register_notify.text_1": "Administrator \"%[1]s\" created an account for you on %s.",
|
||||
"mail.register_notify.text_1_no_admin": "An account was created for you on %s.",
|
||||
"mail.register_notify.text_2": "You can sign in with username: %s.",
|
||||
"mail.register_notify.text_3": "Before signing in, please use your personal link to <a href=\"%s\">set your password</a>.",
|
||||
"mail.admin_invite": "You are invited to join %s",
|
||||
"mail.admin_invite.title": "Invitation to join %s",
|
||||
"mail.admin_invite.text_1": "Administrator \"%[1]s\" created an account for you and invites you to join %[2]s.",
|
||||
|
||||
@@ -543,9 +543,10 @@
|
||||
"mail.account_request.rejected.text_2": "Contul rămâne blocat până când un administrator îl deblochează.",
|
||||
"mail.register_notify": "Bine ai venit la %s",
|
||||
"mail.register_notify.title": "%[1]s, bine ai venit la %[2]s",
|
||||
"mail.register_notify.text_1": "Acesta este e-mailul de confirmare a înregistrării pentru %s!",
|
||||
"mail.register_notify.text_2": "Acum te poți conecta cu numele de utilizator: %s.",
|
||||
"mail.register_notify.text_3": "Dacă acest cont a fost creat pentru tine, te rugăm să setezi mai întâi <a href=\"%s\">parola</a>.",
|
||||
"mail.register_notify.text_1": "Administratorul \"%[1]s\" a creat un cont pentru tine pe %s.",
|
||||
"mail.register_notify.text_1_no_admin": "A fost creat un cont pentru tine pe %s.",
|
||||
"mail.register_notify.text_2": "Te poți conecta folosind numele de utilizator: %s.",
|
||||
"mail.register_notify.text_3": "Inainte de autentificare, foloseste linkul personal pentru a <a href=\"%s\">seta parola</a>.",
|
||||
"mail.admin_invite": "Esti invitat să te alături la %s",
|
||||
"mail.admin_invite.title": "Invitație la %s",
|
||||
"mail.admin_invite.text_1": "Administratorul „%[1]s” a creat un cont pentru tine și te invită să te alături %[2]s.",
|
||||
|
||||
@@ -340,7 +340,7 @@ func CreateUser(ctx *context.APIContext) {
|
||||
if isAdminInvite {
|
||||
mailer.SendAdminInviteMailWithLocale(ctx.Locale, ctx.Doer, u)
|
||||
} else {
|
||||
mailer.SendRegisterNotifyMailWithLocale(ctx.Locale, u)
|
||||
mailer.SendRegisterNotifyMailWithLocale(ctx.Locale, ctx.Doer, u)
|
||||
}
|
||||
}
|
||||
ctx.JSON(http.StatusCreated, convert.ToUser(ctx, u, ctx.Doer))
|
||||
|
||||
@@ -934,7 +934,7 @@ func NewUserPost(ctx *context.Context) {
|
||||
if isAdminInvite {
|
||||
mailer.SendAdminInviteMailWithLocale(ctx.Locale, ctx.Doer, u)
|
||||
} else if form.SendNotify {
|
||||
mailer.SendRegisterNotifyMailWithLocale(ctx.Locale, u)
|
||||
mailer.SendRegisterNotifyMailWithLocale(ctx.Locale, ctx.Doer, u)
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("admin.users.new_success", u.Name))
|
||||
|
||||
@@ -181,18 +181,26 @@ func SendActivateEmailMail(u *user_model.User, email string) error {
|
||||
|
||||
// SendRegisterNotifyMail triggers a notify e-mail by admin created a account.
|
||||
func SendRegisterNotifyMail(u *user_model.User) {
|
||||
SendRegisterNotifyMailWithLocale(translation.NewLocale(u.Language), u)
|
||||
SendRegisterNotifyMailWithLocale(translation.NewLocale(u.Language), nil, u)
|
||||
}
|
||||
|
||||
func SendRegisterNotifyMailWithLocale(locale translation.Locale, u *user_model.User) {
|
||||
func SendRegisterNotifyMailWithLocale(locale translation.Locale, admin, u *user_model.User) {
|
||||
if setting.MailService == nil || !u.IsActive {
|
||||
return
|
||||
}
|
||||
opts := &user_model.TimeLimitCodeOptions{Purpose: user_model.TimeLimitCodeResetPassword}
|
||||
setPasswordURL := fmt.Sprintf("%suser/reset_password?code=%s", setting.AppURL, url.QueryEscape(user_model.GenerateUserTimeLimitCode(opts, u)))
|
||||
adminName := ""
|
||||
if admin != nil {
|
||||
adminName = admin.Name
|
||||
}
|
||||
data := map[string]any{
|
||||
"locale": locale,
|
||||
"DisplayName": u.DisplayName(),
|
||||
"Username": u.Name,
|
||||
"Language": locale.Language(),
|
||||
"locale": locale,
|
||||
"DisplayName": u.DisplayName(),
|
||||
"AdminName": adminName,
|
||||
"Username": u.Name,
|
||||
"SetPasswordURL": setPasswordURL,
|
||||
"Language": locale.Language(),
|
||||
}
|
||||
|
||||
var content bytes.Buffer
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
<title>{{.locale.Tr "mail.register_notify.title" (.DisplayName|DotEscape) AppName}}</title>
|
||||
</head>
|
||||
|
||||
{{$set_pwd_url := printf "%[1]suser/forgot_password" AppUrl}}
|
||||
<body>
|
||||
<p>{{.locale.Tr "mail.hi_user_x" (.DisplayName|DotEscape)}}</p><br>
|
||||
<p>{{.locale.Tr "mail.register_notify.text_1" AppName}}</p><br>
|
||||
{{if .AdminName}}
|
||||
<p>{{.locale.Tr "mail.register_notify.text_1" (.AdminName|DotEscape) AppName}}</p><br>
|
||||
{{else}}
|
||||
<p>{{.locale.Tr "mail.register_notify.text_1_no_admin" AppName}}</p><br>
|
||||
{{end}}
|
||||
<p>{{.locale.Tr "mail.register_notify.text_2" .Username}}</p><p><a href="{{AppUrl}}user/login">{{AppUrl}}user/login</a></p><br>
|
||||
<p>{{.locale.Tr "mail.register_notify.text_3" $set_pwd_url}}</p><br>
|
||||
<p>{{.locale.Tr "mail.register_notify.text_3" .SetPasswordURL}}</p><br>
|
||||
|
||||
<p>© <a href="{{AppUrl}}">{{AppName}}</a></p>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user