Add user info endpoint
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-12-30 14:06:25 -05:00
parent cc63f82427
commit 9803136783

View File

@ -179,6 +179,29 @@ func getVerifications(w http.ResponseWriter, r *http.Request) {
}
fmt.Fprintf(w, string(verifications))
}
func getUser(w http.ResponseWriter, r *http.Request) {
loggedIn, _ := detectUser(r, "getVerifications")
if !loggedIn {
notFoundPage(w, r)
return
}
vars := mux.Vars(r)
username := vars["userID"]
if len(username) == 0 {
username = r.FormValue("userID")
}
m, err := dg.GuildMember(config.GuildID, username)
if err != nil {
log.LogErrorType(err)
}
ret, err := json.Marshal(m)
if err != nil {
log.LogErrorType(err)
}
fmt.Fprintf(w, string(ret))
}
func runWeb() {
defer log.PanicSafe()
router := mux.NewRouter().StrictSlash(true)
@ -191,6 +214,7 @@ func runWeb() {
router.HandleFunc("/api/verifications", getVerifications)
router.HandleFunc("/api/probations", getProbations)
router.HandleFunc("/api/passreq", reqPass)
router.HandleFunc("/api/user", getUser)
router.HandleFunc("/", greetUser)
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
log.LogInfo("Starting server")