mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-11-29 12:33:49 +00:00
add support for bad login notification, review notification code
This commit is contained in:
@@ -47,9 +47,7 @@ type Config struct {
|
|||||||
ConsentWithdraw []string `yaml:"consent_withdraw"`
|
ConsentWithdraw []string `yaml:"consent_withdraw"`
|
||||||
}
|
}
|
||||||
Notification struct {
|
Notification struct {
|
||||||
ConsentNotificationURL string `yaml:"consent_notification_url"`
|
NotificationURL string `yaml:"notification_url"`
|
||||||
ProfileNotificationURL string `yaml:"profile_notification_url"`
|
|
||||||
ForgetmeNotificationURL string `yaml:"forgetme_notification_url"`
|
|
||||||
MagicSyncURL string `yaml:"magic_sync_url"`
|
MagicSyncURL string `yaml:"magic_sync_url"`
|
||||||
MagicSyncToken string `yaml:"magic_sync_token"`
|
MagicSyncToken string `yaml:"magic_sync_token"`
|
||||||
}
|
}
|
||||||
@@ -158,6 +156,8 @@ func (e mainEnv) uiConfigurationDump(w http.ResponseWriter, r *http.Request, ps
|
|||||||
if len(e.conf.Notification.MagicSyncURL) != 0 &&
|
if len(e.conf.Notification.MagicSyncURL) != 0 &&
|
||||||
len(e.conf.Notification.MagicSyncToken) != 0 {
|
len(e.conf.Notification.MagicSyncToken) != 0 {
|
||||||
e.conf.UI.MagicLookup = true
|
e.conf.UI.MagicLookup = true
|
||||||
|
} else {
|
||||||
|
e.conf.UI.MagicLookup = false
|
||||||
}
|
}
|
||||||
resultJSON, _ := json.Marshal(e.conf.UI)
|
resultJSON, _ := json.Marshal(e.conf.UI)
|
||||||
finalJSON := fmt.Sprintf(`{"status":"ok","ui":%s}`, resultJSON)
|
finalJSON := fmt.Sprintf(`{"status":"ok","ui":%s}`, resultJSON)
|
||||||
@@ -295,7 +295,7 @@ func (e mainEnv) dbCleanupDo() {
|
|||||||
if exp > 0 {
|
if exp > 0 {
|
||||||
e.db.store.DeleteExpired0(storage.TblName.Audit, exp)
|
e.db.store.DeleteExpired0(storage.TblName.Audit, exp)
|
||||||
}
|
}
|
||||||
notifyURL := e.conf.Notification.ConsentNotificationURL
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
e.db.expireConsentRecords(notifyURL)
|
e.db.expireConsentRecords(notifyURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ func (e mainEnv) consentAccept(w http.ResponseWriter, r *http.Request, ps httpro
|
|||||||
}
|
}
|
||||||
newStatus, _ := e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, lawfulbasis, consentmethod,
|
newStatus, _ := e.db.createConsentRecord(userTOKEN, mode, address, brief, message, status, lawfulbasis, consentmethod,
|
||||||
referencecode, freetext, lastmodifiedby, starttime, expiration)
|
referencecode, freetext, lastmodifiedby, starttime, expiration)
|
||||||
notifyURL := e.conf.Notification.ConsentNotificationURL
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
if newStatus == true && len(notifyURL) > 0 {
|
if newStatus == true && len(notifyURL) > 0 {
|
||||||
// change notificate on new record or if status change
|
// change notificate on new record or if status change
|
||||||
if len(userTOKEN) > 0 {
|
if len(userTOKEN) > 0 {
|
||||||
@@ -246,7 +246,7 @@ func (e mainEnv) consentWithdraw(w http.ResponseWriter, r *http.Request, ps http
|
|||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
w.Write([]byte(`{"status":"ok"}`))
|
w.Write([]byte(`{"status":"ok"}`))
|
||||||
notifyURL := e.conf.Notification.ConsentNotificationURL
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
if len(userTOKEN) > 0 {
|
if len(userTOKEN) > 0 {
|
||||||
notifyConsentChange(notifyURL, brief, "no", "token", userTOKEN)
|
notifyConsentChange(notifyURL, brief, "no", "token", userTOKEN)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func notifyBadLogin(notifyURL string, mode string, address string) {
|
||||||
|
if len(notifyURL) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
requestBody := fmt.Sprintf(`{"action":"%s","address":"%s","mode":"%s"}`,
|
||||||
|
"badlogin", address, mode)
|
||||||
|
go notify(notifyURL, []byte(requestBody))
|
||||||
|
}
|
||||||
|
|
||||||
func notifyProfileNew(notifyURL string, profile []byte, mode string, address string) {
|
func notifyProfileNew(notifyURL string, profile []byte, mode string, address string) {
|
||||||
if len(notifyURL) == 0 {
|
if len(notifyURL) == 0 {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ func (e mainEnv) approveUserRequest(w http.ResponseWriter, r *http.Request, ps h
|
|||||||
event.Status = "failed"
|
event.Status = "failed"
|
||||||
event.Msg = "failed to delete"
|
event.Msg = "failed to delete"
|
||||||
}
|
}
|
||||||
notifyURL := e.conf.Notification.ForgetmeNotificationURL
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
notifyForgetMe(notifyURL, resultJSON, "token", userTOKEN)
|
notifyForgetMe(notifyURL, resultJSON, "token", userTOKEN)
|
||||||
} else if action == "change-profile" {
|
} else if action == "change-profile" {
|
||||||
oldJSON, newJSON, lookupErr, err := e.db.updateUserRecord(requestInfo["change"].([]uint8), userTOKEN, event, e.conf)
|
oldJSON, newJSON, lookupErr, err := e.db.updateUserRecord(requestInfo["change"].([]uint8), userTOKEN, event, e.conf)
|
||||||
@@ -182,7 +182,7 @@ func (e mainEnv) approveUserRequest(w http.ResponseWriter, r *http.Request, ps h
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
returnUUID(w, userTOKEN)
|
returnUUID(w, userTOKEN)
|
||||||
notifyURL := e.conf.Notification.ProfileNotificationURL
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
notifyProfileChange(notifyURL, oldJSON, newJSON, "token", userTOKEN)
|
notifyProfileChange(notifyURL, oldJSON, newJSON, "token", userTOKEN)
|
||||||
} else if action == "change-app-data" {
|
} else if action == "change-app-data" {
|
||||||
app := requestInfo["app"].(string)
|
app := requestInfo["app"].(string)
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ func (e mainEnv) userNew(w http.ResponseWriter, r *http.Request, ps httprouter.P
|
|||||||
}
|
}
|
||||||
event.Record = userTOKEN
|
event.Record = userTOKEN
|
||||||
returnUUID(w, userTOKEN)
|
returnUUID(w, userTOKEN)
|
||||||
notifyURL := e.conf.Notification.ProfileNotificationURL
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
notifyProfileNew(notifyURL, parsedData.jsonData, "token", userTOKEN)
|
notifyProfileNew(notifyURL, parsedData.jsonData, "token", userTOKEN)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ func (e mainEnv) userChange(w http.ResponseWriter, r *http.Request, ps httproute
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
returnUUID(w, userTOKEN)
|
returnUUID(w, userTOKEN)
|
||||||
notifyURL := e.conf.Notification.ProfileNotificationURL
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
notifyProfileChange(notifyURL, oldJSON, newJSON, "token", userTOKEN)
|
notifyProfileChange(notifyURL, oldJSON, newJSON, "token", userTOKEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,7 +271,7 @@ func (e mainEnv) userDelete(w http.ResponseWriter, r *http.Request, ps httproute
|
|||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
fmt.Fprintf(w, `{"status":"ok","result":"done"}`)
|
fmt.Fprintf(w, `{"status":"ok","result":"done"}`)
|
||||||
notifyURL := e.conf.Notification.ForgetmeNotificationURL
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
notifyForgetMe(notifyURL, resultJSON, "token", userTOKEN)
|
notifyForgetMe(notifyURL, resultJSON, "token", userTOKEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,6 +307,12 @@ func (e mainEnv) userLogin(w http.ResponseWriter, r *http.Request, ps httprouter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if mode == "phone" || mode == "email" {
|
||||||
|
notifyURL := e.conf.Notification.NotificationURL
|
||||||
|
notifyBadLogin(notifyURL, mode, address)
|
||||||
|
returnError(w, r, "not found", 405, errors.New("not found"), event)
|
||||||
|
return
|
||||||
|
}
|
||||||
fmt.Println("user record not found, still returning ok status")
|
fmt.Println("user record not found, still returning ok status")
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
|||||||
Reference in New Issue
Block a user