remove auth.password in email server search api
This commit is contained in:
parent
a53344871c
commit
3709f5683d
|
@ -5,6 +5,7 @@
|
||||||
package email
|
package email
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
@ -15,6 +16,7 @@ import (
|
||||||
"infini.sh/framework/core/orm"
|
"infini.sh/framework/core/orm"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"src/github.com/buger/jsonparser"
|
||||||
"src/github.com/gopkg.in/gomail.v2"
|
"src/github.com/gopkg.in/gomail.v2"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -137,6 +139,9 @@ func (h *EmailAPI) updateEmailServer(w http.ResponseWriter, req *http.Request, p
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if obj.Auth.Password != "" && newObj.Auth.Password == "" && obj.Auth.Username == newObj.Auth.Username {
|
||||||
|
newObj.Auth.Password = obj.Auth.Password
|
||||||
|
}
|
||||||
|
|
||||||
//protect
|
//protect
|
||||||
newObj.ID = id
|
newObj.ID = id
|
||||||
|
@ -246,6 +251,26 @@ func (h *EmailAPI) searchEmailServer(w http.ResponseWriter, req *http.Request, p
|
||||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//remove password field
|
||||||
|
hitsBuf := bytes.Buffer{}
|
||||||
|
hitsBuf.Write([]byte("["))
|
||||||
|
jsonparser.ArrayEach(res.Raw, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
|
||||||
|
value = jsonparser.Delete(value, "_source", "auth", "password")
|
||||||
|
hitsBuf.Write(value)
|
||||||
|
hitsBuf.Write([]byte(","))
|
||||||
|
}, "hits", "hits")
|
||||||
|
buf := hitsBuf.Bytes()
|
||||||
|
if buf[len(buf)-1] == ',' {
|
||||||
|
buf[len(buf)-1] = ']'
|
||||||
|
}else{
|
||||||
|
hitsBuf.Write([]byte("]"))
|
||||||
|
}
|
||||||
|
res.Raw, err = jsonparser.Set(res.Raw, hitsBuf.Bytes(), "hits", "hits")
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
h.ErrorInternalServer(w, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
h.Write(w, res.Raw)
|
h.Write(w, res.Raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue