add support for bad login notification, review notification code

This commit is contained in:
Yuli
2020-03-21 22:45:47 +02:00
parent f83ef12718
commit 42498a3507
5 changed files with 28 additions and 13 deletions

View File

@@ -47,9 +47,7 @@ type Config struct {
ConsentWithdraw []string `yaml:"consent_withdraw"`
}
Notification struct {
ConsentNotificationURL string `yaml:"consent_notification_url"`
ProfileNotificationURL string `yaml:"profile_notification_url"`
ForgetmeNotificationURL string `yaml:"forgetme_notification_url"`
NotificationURL string `yaml:"notification_url"`
MagicSyncURL string `yaml:"magic_sync_url"`
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 &&
len(e.conf.Notification.MagicSyncToken) != 0 {
e.conf.UI.MagicLookup = true
} else {
e.conf.UI.MagicLookup = false
}
resultJSON, _ := json.Marshal(e.conf.UI)
finalJSON := fmt.Sprintf(`{"status":"ok","ui":%s}`, resultJSON)
@@ -295,7 +295,7 @@ func (e mainEnv) dbCleanupDo() {
if exp > 0 {
e.db.store.DeleteExpired0(storage.TblName.Audit, exp)
}
notifyURL := e.conf.Notification.ConsentNotificationURL
notifyURL := e.conf.Notification.NotificationURL
e.db.expireConsentRecords(notifyURL)
}

View File

@@ -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,
referencecode, freetext, lastmodifiedby, starttime, expiration)
notifyURL := e.conf.Notification.ConsentNotificationURL
notifyURL := e.conf.Notification.NotificationURL
if newStatus == true && len(notifyURL) > 0 {
// change notificate on new record or if status change
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.WriteHeader(200)
w.Write([]byte(`{"status":"ok"}`))
notifyURL := e.conf.Notification.ConsentNotificationURL
notifyURL := e.conf.Notification.NotificationURL
if len(userTOKEN) > 0 {
notifyConsentChange(notifyURL, brief, "no", "token", userTOKEN)
} else {

View File

@@ -9,6 +9,15 @@ import (
"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) {
if len(notifyURL) == 0 {
return

View File

@@ -169,7 +169,7 @@ func (e mainEnv) approveUserRequest(w http.ResponseWriter, r *http.Request, ps h
event.Status = "failed"
event.Msg = "failed to delete"
}
notifyURL := e.conf.Notification.ForgetmeNotificationURL
notifyURL := e.conf.Notification.NotificationURL
notifyForgetMe(notifyURL, resultJSON, "token", userTOKEN)
} else if action == "change-profile" {
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
}
returnUUID(w, userTOKEN)
notifyURL := e.conf.Notification.ProfileNotificationURL
notifyURL := e.conf.Notification.NotificationURL
notifyProfileChange(notifyURL, oldJSON, newJSON, "token", userTOKEN)
} else if action == "change-app-data" {
app := requestInfo["app"].(string)

View File

@@ -92,7 +92,7 @@ func (e mainEnv) userNew(w http.ResponseWriter, r *http.Request, ps httprouter.P
}
event.Record = userTOKEN
returnUUID(w, userTOKEN)
notifyURL := e.conf.Notification.ProfileNotificationURL
notifyURL := e.conf.Notification.NotificationURL
notifyProfileNew(notifyURL, parsedData.jsonData, "token", userTOKEN)
return
}
@@ -208,7 +208,7 @@ func (e mainEnv) userChange(w http.ResponseWriter, r *http.Request, ps httproute
return
}
returnUUID(w, userTOKEN)
notifyURL := e.conf.Notification.ProfileNotificationURL
notifyURL := e.conf.Notification.NotificationURL
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.WriteHeader(200)
fmt.Fprintf(w, `{"status":"ok","result":"done"}`)
notifyURL := e.conf.Notification.ForgetmeNotificationURL
notifyURL := e.conf.Notification.NotificationURL
notifyForgetMe(notifyURL, resultJSON, "token", userTOKEN)
}
@@ -307,6 +307,12 @@ func (e mainEnv) userLogin(w http.ResponseWriter, r *http.Request, ps httprouter
}
}
} 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")
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")