chore: fix users returning password at api + GeSupportedDm null return
This commit is contained in:
parent
9765b77e32
commit
1489573f89
|
|
@ -52,7 +52,7 @@ func StartApi(a Api) {
|
|||
authentication.HandleFunc("/register", a.registerUser).Methods("POST")
|
||||
// Keep the line above commented to avoid people get unintended admin privileges.
|
||||
// Uncomment it only once for you to get admin privileges and create new users.
|
||||
// authentication.HandleFunc("/admin/register", a.registerAdminUser).Methods("POST")
|
||||
//authentication.HandleFunc("/admin/register", a.registerAdminUser).Methods("POST")
|
||||
iot := r.PathPrefix("/api/device").Subrouter()
|
||||
iot.HandleFunc("", a.retrieveDevices).Methods("GET")
|
||||
iot.HandleFunc("/{sn}/get", a.deviceGetMsg).Methods("PUT")
|
||||
|
|
@ -112,13 +112,18 @@ func (a *Api) retrieveDevices(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (a *Api) retrieveUsers(w http.ResponseWriter, r *http.Request) {
|
||||
devices, err := a.Db.FindAllUsers()
|
||||
users, err := a.Db.FindAllUsers()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = json.NewEncoder(w).Encode(devices)
|
||||
|
||||
for _, x := range users {
|
||||
delete(x, "password")
|
||||
}
|
||||
|
||||
err = json.NewEncoder(w).Encode(users)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
|
@ -315,7 +320,7 @@ func (a *Api) deviceGetSupportedParametersMsg(w http.ResponseWriter, r *http.Req
|
|||
select {
|
||||
case msg := <-a.MsgQueue[msg.Header.MsgId]:
|
||||
log.Printf("Received Msg: %s", msg.Header.MsgId)
|
||||
json.NewEncoder(w).Encode(msg.Body.GetResponse().GetSetResp())
|
||||
json.NewEncoder(w).Encode(msg.Body.GetResponse().GetGetSupportedDmResp())
|
||||
return
|
||||
case <-time.After(time.Second * 28):
|
||||
log.Printf("Request %s Timed Out", msg.Header.MsgId)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
type User struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Password string `json:"password"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Level int `json:"level"`
|
||||
}
|
||||
|
||||
|
|
@ -26,11 +26,11 @@ func (d *Database) RegisterUser(user User) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func (d *Database) FindAllUsers() ([]User, error) {
|
||||
var result []User
|
||||
func (d *Database) FindAllUsers() ([]map[string]interface{}, error) {
|
||||
var result []map[string]interface{}
|
||||
cursor, err := d.users.Find(d.ctx, bson.D{{}})
|
||||
if err != nil {
|
||||
return []User{}, err
|
||||
return []map[string]interface{}{}, err
|
||||
}
|
||||
if err = cursor.All(d.ctx, &result); err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user