add handling for request-exists

This commit is contained in:
root
2020-08-18 17:17:14 +00:00
parent 56e42e580e
commit 085b276098
7 changed files with 20 additions and 13 deletions

View File

@@ -220,14 +220,14 @@ func (e mainEnv) agreementWithdraw(w http.ResponseWriter, r *http.Request, ps ht
}
if authResult == "login" && selfService == false {
rtoken, err := e.db.saveUserRequest("agreement-withdraw", userTOKEN, "", brief, nil)
rtoken, rstatus, err := e.db.saveUserRequest("agreement-withdraw", userTOKEN, "", brief, nil)
if err != nil {
returnError(w, r, "internal error", 405, err, event)
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
fmt.Fprintf(w, `{"status":"ok","result":"request-created","rtoken":"%s"}`, rtoken)
fmt.Fprintf(w, `{"status":"ok","result":"%s","rtoken":"%s"}`, rstatus, rtoken)
return
}
switch mode {

View File

@@ -24,7 +24,7 @@ type requestEvent struct {
Reason string `json:"reason"`
}
func (dbobj dbcon) saveUserRequest(action string, token string, app string, brief string, change []byte) (string, error) {
func (dbobj dbcon) saveUserRequest(action string, token string, app string, brief string, change []byte) (string, string, error) {
now := int32(time.Now().Unix())
bdoc := bson.M{}
bdoc["token"] = token
@@ -39,7 +39,7 @@ func (dbobj dbcon) saveUserRequest(action string, token string, app string, brie
record, err := dbobj.store.LookupRecord(storage.TblName.Requests, bdoc)
if record != nil {
fmt.Printf("This record already exists.\n")
return record["rtoken"].(string), nil
return record["rtoken"].(string), "request-exists", nil
}
rtoken, _ := uuid.GenerateUUID()
bdoc["when"] = now
@@ -48,12 +48,12 @@ func (dbobj dbcon) saveUserRequest(action string, token string, app string, brie
if change != nil {
encodedStr, err := dbobj.userEncrypt(token, change)
if err != nil {
return "", err
return "", "", err
}
bdoc["change"] = encodedStr
}
_, err = dbobj.store.CreateRecord(storage.TblName.Requests, &bdoc)
return rtoken, err
return rtoken, "request-created", err
}
func (dbobj dbcon) getRequests(status string, offset int32, limit int32) ([]byte, int64, error) {

View File

@@ -117,14 +117,14 @@ func (e mainEnv) userappChange(w http.ResponseWriter, r *http.Request, ps httpro
}
}
}
rtoken, err := e.db.saveUserRequest("change-app-data", userTOKEN, appName, "", jsonData)
rtoken, rstatus, err := e.db.saveUserRequest("change-app-data", userTOKEN, appName, "", jsonData)
if err != nil {
returnError(w, r, "internal error", 405, err, event)
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
fmt.Fprintf(w, `{"status":"ok","result":"request-created","rtoken":"%s"}`, rtoken)
fmt.Fprintf(w, `{"status":"ok","result":"%s","rtoken":"%s"}`, rstatus, rtoken)
}
func (e mainEnv) userappList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

View File

@@ -201,14 +201,14 @@ func (e mainEnv) userChange(w http.ResponseWriter, r *http.Request, ps httproute
if authResult == "login" {
event.Title = "user change-profile request"
if e.conf.SelfService.UserRecordChange == false || adminRecordChanged == true {
rtoken, err := e.db.saveUserRequest("change-profile", userTOKEN, "", "", parsedData.jsonData)
rtoken, rstatus, err := e.db.saveUserRequest("change-profile", userTOKEN, "", "", parsedData.jsonData)
if err != nil {
returnError(w, r, "internal error", 405, err, event)
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
fmt.Fprintf(w, `{"status":"ok","result":"request-created","rtoken":"%s"}`, rtoken)
fmt.Fprintf(w, `{"status":"ok","result":"%s","rtoken":"%s"}`, rstatus, rtoken)
return
}
}
@@ -265,14 +265,14 @@ func (e mainEnv) userDelete(w http.ResponseWriter, r *http.Request, ps httproute
if authResult == "login" {
event.Title = "user forget-me request"
if e.conf.SelfService.ForgetMe == false {
rtoken, err := e.db.saveUserRequest("forget-me", userTOKEN, "", "", nil)
rtoken, rstatus, err := e.db.saveUserRequest("forget-me", userTOKEN, "", "", nil)
if err != nil {
returnError(w, r, "internal error", 405, err, event)
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
fmt.Fprintf(w, `{"status":"ok","result":"request-created","rtoken":"%s"}`, rtoken)
fmt.Fprintf(w, `{"status":"ok","result":"%s","rtoken":"%s"}`, rstatus, rtoken)
return
}
}

View File

@@ -108,6 +108,8 @@ if (conf["custom_css_link"]) {
var data = JSON.parse(xhr0.responseText);
if (data.status == "ok" && data.result && data.result == "request-created") {
showAlert("Admin request created to approve your app data changes.");
} else if (data.status == "ok" && data.result && data.result == "request-exists") {
showAlert("Similar request already exists for Admin approval.");
}
} else if (xhr0.status > 400 && xhr0.status < 500) {
document.location = "/";

View File

@@ -125,6 +125,8 @@ if (conf["custom_css_link"]) {
var data = JSON.parse(xhr.responseText);
if (data.status == "ok" && data.result && data.result == "request-created") {
showAlert("Admin request created to withdraw your consent.");
} else if (data.status == "ok" && data.result && data.result == "request-exists") {
showAlert("Similar request already exists for Admin approval.");
} else {
document.location.reload();
}

View File

@@ -120,7 +120,6 @@ if (conf["custom_css_link"]) {
forgetMeDo();
confirmModal.modal('hide');
});
confirmModal.modal('show');
}
function forgetMeDo(brief) {
@@ -133,6 +132,8 @@ if (conf["custom_css_link"]) {
var data = JSON.parse(xhr.responseText);
if (data.status == "ok" && data.result && data.result == "request-created") {
showAlert("Admin request created to cancel your account.");
} else if (data.status == "ok" && data.result && data.result == "request-exists") {
showAlert("Similar request already exists for Admin approval.");
} else {
bunker_logout();
}
@@ -157,6 +158,8 @@ if (conf["custom_css_link"]) {
var data = JSON.parse(xhr0.responseText);
if (data.status == "ok" && data.result && data.result == "request-created") {
showAlert("Admin request created to approve changes in your profile.");
} else if (data.status == "ok" && data.result && data.result == "request-exists") {
showAlert("Similar request already exists for Admin approval.");
}
} else if (xhr0.status === 403) {
document.location = "/";