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")
|
authentication.HandleFunc("/register", a.registerUser).Methods("POST")
|
||||||
// Keep the line above commented to avoid people get unintended admin privileges.
|
// 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.
|
// 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 := r.PathPrefix("/api/device").Subrouter()
|
||||||
iot.HandleFunc("", a.retrieveDevices).Methods("GET")
|
iot.HandleFunc("", a.retrieveDevices).Methods("GET")
|
||||||
iot.HandleFunc("/{sn}/get", a.deviceGetMsg).Methods("PUT")
|
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) {
|
func (a *Api) retrieveUsers(w http.ResponseWriter, r *http.Request) {
|
||||||
devices, err := a.Db.FindAllUsers()
|
users, err := a.Db.FindAllUsers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = json.NewEncoder(w).Encode(devices)
|
|
||||||
|
for _, x := range users {
|
||||||
|
delete(x, "password")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.NewEncoder(w).Encode(users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +320,7 @@ func (a *Api) deviceGetSupportedParametersMsg(w http.ResponseWriter, r *http.Req
|
||||||
select {
|
select {
|
||||||
case msg := <-a.MsgQueue[msg.Header.MsgId]:
|
case msg := <-a.MsgQueue[msg.Header.MsgId]:
|
||||||
log.Printf("Received Msg: %s", 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
|
return
|
||||||
case <-time.After(time.Second * 28):
|
case <-time.After(time.Second * 28):
|
||||||
log.Printf("Request %s Timed Out", msg.Header.MsgId)
|
log.Printf("Request %s Timed Out", msg.Header.MsgId)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
type User struct {
|
type User struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password,omitempty"`
|
||||||
Level int `json:"level"`
|
Level int `json:"level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,11 +26,11 @@ func (d *Database) RegisterUser(user User) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) FindAllUsers() ([]User, error) {
|
func (d *Database) FindAllUsers() ([]map[string]interface{}, error) {
|
||||||
var result []User
|
var result []map[string]interface{}
|
||||||
cursor, err := d.users.Find(d.ctx, bson.D{{}})
|
cursor, err := d.users.Find(d.ctx, bson.D{{}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []User{}, err
|
return []map[string]interface{}{}, err
|
||||||
}
|
}
|
||||||
if err = cursor.All(d.ctx, &result); err != nil {
|
if err = cursor.All(d.ctx, &result); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user