mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-23 01:20:11 +00:00
use bulk email sending on account deletion
This commit is contained in:
parent
ca00796077
commit
b25f786018
22
api.go
22
api.go
@ -539,8 +539,9 @@ func (app *appContext) Announce(gc *gin.Context) {
|
|||||||
// @Router /users [delete]
|
// @Router /users [delete]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @tags Users
|
// @tags Users
|
||||||
func (app *appContext) DeleteUser(gc *gin.Context) {
|
func (app *appContext) DeleteUsers(gc *gin.Context) {
|
||||||
var req deleteUserDTO
|
var req deleteUserDTO
|
||||||
|
var addresses []string
|
||||||
gc.BindJSON(&req)
|
gc.BindJSON(&req)
|
||||||
errors := map[string]string{}
|
errors := map[string]string{}
|
||||||
ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false)
|
ombiEnabled := app.config.Section("ombi").Key("enabled").MustBool(false)
|
||||||
@ -569,18 +570,21 @@ func (app *appContext) DeleteUser(gc *gin.Context) {
|
|||||||
if emailEnabled && req.Notify {
|
if emailEnabled && req.Notify {
|
||||||
addr, ok := app.storage.emails[userID]
|
addr, ok := app.storage.emails[userID]
|
||||||
if addr != nil && ok {
|
if addr != nil && ok {
|
||||||
go func(userID, reason, address string) {
|
addresses = append(addresses, addr.(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(addresses) != 0 {
|
||||||
|
go func(reason string, addresses []string) {
|
||||||
msg, err := app.email.constructDeleted(reason, app)
|
msg, err := app.email.constructDeleted(reason, app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.err.Printf("%s: Failed to construct account deletion email: %s", userID, err)
|
app.err.Printf("Failed to construct account deletion emails: %s", err)
|
||||||
} else if err := app.email.send(msg, address); err != nil {
|
} else if err := app.email.send(msg, addresses...); err != nil {
|
||||||
app.err.Printf("%s: Failed to send to %s: %s", userID, address, err)
|
app.err.Printf("Failed to send account deletion emails: %s", err)
|
||||||
} else {
|
} else {
|
||||||
app.info.Printf("%s: Sent deletion email to %s", userID, address)
|
app.info.Println("Sent account deletion emails")
|
||||||
}
|
|
||||||
}(userID, req.Reason, addr.(string))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}(req.Reason, addresses)
|
||||||
}
|
}
|
||||||
app.jf.CacheExpiry = time.Now()
|
app.jf.CacheExpiry = time.Now()
|
||||||
if len(errors) == len(req.Users) {
|
if len(errors) == len(req.Users) {
|
||||||
|
@ -123,7 +123,7 @@ func (app *appContext) loadRoutes(router *gin.Engine) {
|
|||||||
api := router.Group("/", app.webAuth())
|
api := router.Group("/", app.webAuth())
|
||||||
for _, p := range routePrefixes {
|
for _, p := range routePrefixes {
|
||||||
router.POST(p+"/logout", app.Logout)
|
router.POST(p+"/logout", app.Logout)
|
||||||
api.DELETE(p+"/users", app.DeleteUser)
|
api.DELETE(p+"/users", app.DeleteUsers)
|
||||||
api.GET(p+"/users", app.GetUsers)
|
api.GET(p+"/users", app.GetUsers)
|
||||||
api.POST(p+"/users", app.NewUserAdmin)
|
api.POST(p+"/users", app.NewUserAdmin)
|
||||||
api.POST(p+"/invites", app.GenerateInvite)
|
api.POST(p+"/invites", app.GenerateInvite)
|
||||||
|
Loading…
Reference in New Issue
Block a user