|
|
@ -282,7 +282,7 @@ func (app *appContext) NewUserAdmin(gc *gin.Context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app.jf.CacheExpiry = time.Now()
|
|
|
|
app.jf.CacheExpiry = time.Now()
|
|
|
|
if app.config.Section("password_resets").Key("enabled").MustBool(false) {
|
|
|
|
if emailEnabled {
|
|
|
|
app.storage.emails[id] = req.Email
|
|
|
|
app.storage.emails[id] = req.Email
|
|
|
|
app.storage.storeEmails()
|
|
|
|
app.storage.storeEmails()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -500,15 +500,16 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if emailEnabled && app.config.Section("welcome_email").Key("enabled").MustBool(false) && req.Email != "" {
|
|
|
|
if (emailEnabled && app.config.Section("welcome_email").Key("enabled").MustBool(false) && req.Email != "") || telegramTokenIndex != -1 {
|
|
|
|
app.debug.Printf("%s: Sending welcome email to %s", req.Username, req.Email)
|
|
|
|
name := app.getAddressOrName(user.ID)
|
|
|
|
|
|
|
|
app.debug.Printf("%s: Sending welcome message to %s", req.Username, name)
|
|
|
|
msg, err := app.email.constructWelcome(req.Username, expiry, app, false)
|
|
|
|
msg, err := app.email.constructWelcome(req.Username, expiry, app, false)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.err.Printf("%s: Failed to construct welcome email: %v", req.Username, err)
|
|
|
|
app.err.Printf("%s: Failed to construct welcome message: %v", req.Username, err)
|
|
|
|
} else if err := app.email.send(msg, req.Email); err != nil {
|
|
|
|
} else if err := app.sendByID(msg, user.ID); err != nil {
|
|
|
|
app.err.Printf("%s: Failed to send welcome email: %v", req.Username, err)
|
|
|
|
app.err.Printf("%s: Failed to send welcome message: %v", req.Username, err)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
app.info.Printf("%s: Sent welcome email to \"%s\"", req.Username, req.Email)
|
|
|
|
app.info.Printf("%s: Sent welcome message to \"%s\"", req.Username, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app.jf.CacheExpiry = time.Now()
|
|
|
|
app.jf.CacheExpiry = time.Now()
|
|
|
@ -575,7 +576,20 @@ func (app *appContext) EnableDisableUsers(gc *gin.Context) {
|
|
|
|
"GetUser": map[string]string{},
|
|
|
|
"GetUser": map[string]string{},
|
|
|
|
"SetPolicy": map[string]string{},
|
|
|
|
"SetPolicy": map[string]string{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var addresses []string
|
|
|
|
sendMail := emailEnabled || app.config.Section("telegram").Key("enabled").MustBool(false)
|
|
|
|
|
|
|
|
var msg *Message
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if sendMail {
|
|
|
|
|
|
|
|
if req.Enabled {
|
|
|
|
|
|
|
|
msg, err = app.email.constructEnabled(req.Reason, app, false)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
msg, err = app.email.constructDisabled(req.Reason, app, false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
app.err.Printf("Failed to construct account enabled/disabled emails: %v", err)
|
|
|
|
|
|
|
|
sendMail = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, userID := range req.Users {
|
|
|
|
for _, userID := range req.Users {
|
|
|
|
user, status, err := app.jf.UserByID(userID, false)
|
|
|
|
user, status, err := app.jf.UserByID(userID, false)
|
|
|
|
if status != 200 || err != nil {
|
|
|
|
if status != 200 || err != nil {
|
|
|
@ -590,31 +604,13 @@ func (app *appContext) EnableDisableUsers(gc *gin.Context) {
|
|
|
|
app.err.Printf("Failed to set policy for user \"%s\" (%d): %v", userID, status, err)
|
|
|
|
app.err.Printf("Failed to set policy for user \"%s\" (%d): %v", userID, status, err)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if emailEnabled && req.Notify {
|
|
|
|
if sendMail && req.Notify {
|
|
|
|
addr, ok := app.storage.emails[userID]
|
|
|
|
if err := app.sendByID(msg, userID); err != nil {
|
|
|
|
if addr != nil && ok {
|
|
|
|
app.err.Printf("Failed to send account enabled/disabled email: %v", err)
|
|
|
|
addresses = append(addresses, addr.(string))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(addresses) != 0 {
|
|
|
|
|
|
|
|
go func(reason string, addresses []string) {
|
|
|
|
|
|
|
|
var msg *Message
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if req.Enabled {
|
|
|
|
|
|
|
|
msg, err = app.email.constructEnabled(reason, app, false)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
msg, err = app.email.constructDisabled(reason, app, false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
app.err.Printf("Failed to construct account enabled/disabled emails: %v", err)
|
|
|
|
|
|
|
|
} else if err := app.email.send(msg, addresses...); err != nil {
|
|
|
|
|
|
|
|
app.err.Printf("Failed to send account enabled/disabled emails: %v", err)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
app.info.Println("Sent account enabled/disabled emails")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}(req.Reason, addresses)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
app.jf.CacheExpiry = time.Now()
|
|
|
|
app.jf.CacheExpiry = time.Now()
|
|
|
|
if len(errors["GetUser"]) != 0 || len(errors["SetPolicy"]) != 0 {
|
|
|
|
if len(errors["GetUser"]) != 0 || len(errors["SetPolicy"]) != 0 {
|
|
|
|
gc.JSON(500, errors)
|
|
|
|
gc.JSON(500, errors)
|
|
|
@ -634,10 +630,19 @@ func (app *appContext) EnableDisableUsers(gc *gin.Context) {
|
|
|
|
// @tags Users
|
|
|
|
// @tags Users
|
|
|
|
func (app *appContext) DeleteUsers(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)
|
|
|
|
|
|
|
|
sendMail := emailEnabled || app.config.Section("telegram").Key("enabled").MustBool(false)
|
|
|
|
|
|
|
|
var msg *Message
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if sendMail {
|
|
|
|
|
|
|
|
msg, err = app.email.constructDeleted(req.Reason, app, false)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
app.err.Printf("Failed to construct account deletion emails: %v", err)
|
|
|
|
|
|
|
|
sendMail = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
for _, userID := range req.Users {
|
|
|
|
for _, userID := range req.Users {
|
|
|
|
if ombiEnabled {
|
|
|
|
if ombiEnabled {
|
|
|
|
ombiUser, code, err := app.getOmbiUser(userID)
|
|
|
|
ombiUser, code, err := app.getOmbiUser(userID)
|
|
|
@ -660,25 +665,12 @@ func (app *appContext) DeleteUsers(gc *gin.Context) {
|
|
|
|
errors[userID] += msg
|
|
|
|
errors[userID] += msg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if emailEnabled && req.Notify {
|
|
|
|
if sendMail && req.Notify {
|
|
|
|
addr, ok := app.storage.emails[userID]
|
|
|
|
if err := app.sendByID(msg, userID); err != nil {
|
|
|
|
if addr != nil && ok {
|
|
|
|
app.err.Printf("Failed to send account deletion email: %v", err)
|
|
|
|
addresses = append(addresses, addr.(string))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(addresses) != 0 {
|
|
|
|
|
|
|
|
go func(reason string, addresses []string) {
|
|
|
|
|
|
|
|
msg, err := app.email.constructDeleted(reason, app, false)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
app.err.Printf("Failed to construct account deletion emails: %v", err)
|
|
|
|
|
|
|
|
} else if err := app.email.send(msg, addresses...); err != nil {
|
|
|
|
|
|
|
|
app.err.Printf("Failed to send account deletion emails: %v", err)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
app.info.Println("Sent account deletion emails")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}(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) {
|
|
|
|
respondBool(500, false, gc)
|
|
|
|
respondBool(500, false, gc)
|
|
|
@ -735,29 +727,21 @@ func (app *appContext) ExtendExpiry(gc *gin.Context) {
|
|
|
|
func (app *appContext) Announce(gc *gin.Context) {
|
|
|
|
func (app *appContext) Announce(gc *gin.Context) {
|
|
|
|
var req announcementDTO
|
|
|
|
var req announcementDTO
|
|
|
|
gc.BindJSON(&req)
|
|
|
|
gc.BindJSON(&req)
|
|
|
|
if !emailEnabled {
|
|
|
|
if !(emailEnabled || app.config.Section("telegram").Key("enabled").MustBool(false)) {
|
|
|
|
respondBool(400, false, gc)
|
|
|
|
respondBool(400, false, gc)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addresses := []string{}
|
|
|
|
|
|
|
|
for _, userID := range req.Users {
|
|
|
|
|
|
|
|
addr, ok := app.storage.emails[userID]
|
|
|
|
|
|
|
|
if !ok || addr == "" {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
addresses = append(addresses, addr.(string))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
msg, err := app.email.constructTemplate(req.Subject, req.Message, app)
|
|
|
|
msg, err := app.email.constructTemplate(req.Subject, req.Message, app)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
app.err.Printf("Failed to construct announcement emails: %v", err)
|
|
|
|
app.err.Printf("Failed to construct announcement messages: %v", err)
|
|
|
|
respondBool(500, false, gc)
|
|
|
|
respondBool(500, false, gc)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
} else if err := app.email.send(msg, addresses...); err != nil {
|
|
|
|
} else if err := app.sendByID(msg, req.Users...); err != nil {
|
|
|
|
app.err.Printf("Failed to send announcement emails: %v", err)
|
|
|
|
app.err.Printf("Failed to send announcement messages: %v", err)
|
|
|
|
respondBool(500, false, gc)
|
|
|
|
respondBool(500, false, gc)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app.info.Printf("Sent announcement email to %d users", len(addresses))
|
|
|
|
app.info.Println("Sent announcement messages")
|
|
|
|
respondBool(200, true, gc)
|
|
|
|
respondBool(200, true, gc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|