The server for Open Course World
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add /api/admin/user_info/{pid}

jneen 942d2b00 7a4a9700

+27
+27
api/user.go
··· 2 2 3 3 import ( 4 4 "encoding/json" 5 + "errors" 5 6 "fmt" 6 7 "math/rand" 7 8 "net/http" ··· 13 14 user_state "smm2_gameserver/nex/connection/user" 14 15 "smm2_gameserver/nex/datastore" 15 16 "smm2_gameserver/nex/id" 17 + 18 + "github.com/gorilla/mux" 19 + // "gorm.io/gorm" 16 20 ) 17 21 18 22 func parsePid(pidStr string) (datastore.Pid, error) { ··· 226 230 return 227 231 } 228 232 }).Methods("POST") 233 + 234 + Secure("/api/admin/user_info/{pid}", func(w http.ResponseWriter, r *http.Request, user orm.User) { 235 + if !user.Role.Admin { 236 + reportError(w, r, errors.New("you do not have admin permissions")) 237 + return 238 + } 239 + 240 + pid, err := parsePid(mux.Vars(r)["pid"]) 241 + if err != nil { 242 + reportError(w, r, err) 243 + return 244 + } 245 + 246 + var pidUser orm.User 247 + result := db.Model(&orm.User{}).Where("id = ?", pid).First(&pidUser) 248 + if result.Error != nil { 249 + reportError(w, r, result.Error) 250 + return 251 + } 252 + 253 + w.Header().Set("Content-Type", "application/json") 254 + json.NewEncoder(w).Encode(pidUser) 255 + }).Methods("GET") 229 256 }