rename email

This commit is contained in:
root
2020-08-20 18:55:50 +00:00
parent 2f38724af0
commit 74dab856c4
2 changed files with 18 additions and 0 deletions

View File

@@ -66,3 +66,7 @@ func (e mainEnv) pluginUserLookup(email string) {
// not implemented
}
func (dbobj dbcon) GlobalUserChangeEmail(oldEmail string, newEmail string) {
// not implemented
}

View File

@@ -138,6 +138,15 @@ func (dbobj dbcon) updateUserRecordDo(jsonDataPatch []byte, userTOKEN string, ev
if err != nil {
return nil, nil, false, err
}
var raw2 map[string]interface{}
err = json.Unmarshal(decrypted, &raw2)
if err != nil {
return nil, nil, false, err
}
oldEmail := ""
if _, ok := raw2["email"]; ok {
oldEmail = normalizeEmail(raw2["email"].(string))
}
// merge
fmt.Printf("old json: %s\n", decrypted)
fmt.Printf("json patch: %s\n", jsonDataPatch)
@@ -157,6 +166,7 @@ func (dbobj dbcon) updateUserRecordDo(jsonDataPatch []byte, userTOKEN string, ev
// create new user record
bdoc := bson.M{}
keys := []string{"login", "email", "phone"}
newEmail := ""
for _, idx := range keys {
//fmt.Printf("Checking %s\n", idx)
actionCode := 1
@@ -167,6 +177,7 @@ func (dbobj dbcon) updateUserRecordDo(jsonDataPatch []byte, userTOKEN string, ev
if len(newIdxFinalValue) > 0 {
if idx == "email" {
newIdxFinalValue = normalizeEmail(newIdxFinalValue)
newEmail = newIdxFinalValue
} else if idx == "phone" {
newIdxFinalValue = normalizePhone(newIdxFinalValue, conf.Sms.DefaultCountry)
}
@@ -219,6 +230,9 @@ func (dbobj dbcon) updateUserRecordDo(jsonDataPatch []byte, userTOKEN string, ev
if err != nil {
return nil, nil, false, err
}
if oldEmail != newEmail && len(oldEmail) > 0 && len(newEmail) > 0 {
dbobj.GlobalUserChangeEmail(oldEmail, newEmail)
}
if event != nil {
event.Before = encData0
event.After = encodedStr