Browse Source

API Endpoints for Verifications and Pending.

hkremer/rebranding
Gregory Rudolph 4 years ago
parent
commit
277fda3a6d
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 2
      main.go
  2. 48
      site-api.go

2
main.go

@ -155,7 +155,7 @@ func runPurge(s *discordgo.Session) { @@ -155,7 +155,7 @@ func runPurge(s *discordgo.Session) {
func ready(s *discordgo.Session, event *discordgo.Ready) {
// Set the playing status.
s.UpdateStatus(0, "DreamDaddy v1.2")
s.UpdateStatus(0, "DreamDaddy v1.3")
}
func guildMemberUpdate(s *discordgo.Session, m *discordgo.GuildMemberUpdate) {

48
site-api.go

@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
"github.com/gorilla/mux"
@ -128,6 +129,51 @@ func getPending(w http.ResponseWriter, r *http.Request) { @@ -128,6 +129,51 @@ func getPending(w http.ResponseWriter, r *http.Request) {
}
}
func getProbations(w http.ResponseWriter, r *http.Request) {
defer log.PanicSafe()
loggedIn, _ := detectUser(r, "getProbations")
if loggedIn {
pending, err := json.Marshal(config.Probations)
if err != nil {
log.LogErrorType(err)
notFoundPage(w, r)
}
fmt.Fprintf(w, string(pending))
} else {
notFoundPage(w, r)
}
}
func getVerifications(w http.ResponseWriter, r *http.Request) {
defer log.PanicSafe()
loggedIn, _ := detectUser(r, "getVerifications")
if !loggedIn {
notFoundPage(w, r)
return
}
var files []string
root := "./verifications"
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
})
if err != nil {
log.LogErrorType(err)
}
var v []Verification
for _, file := range files {
info := strings.Split(file, "-")
var ver Verification
ver.UserID = info[0]
ver.Username = info[1]
ver.Photo = info[2]
v = append(v, ver)
}
verifications, err := json.Marshal(v)
if err != nil {
log.LogErrorType(err)
}
fmt.Fprintf(w, string(verifications))
}
func runWeb() {
defer log.PanicSafe()
router := mux.NewRouter().StrictSlash(true)
@ -137,6 +183,8 @@ func runWeb() { @@ -137,6 +183,8 @@ func runWeb() {
router.HandleFunc("/login", loginPage)
router.HandleFunc("/api/login", tryLogin)
router.HandleFunc("/api/pending", getPending)
router.HandleFunc("/api/verifications", getVerifications)
router.HandleFunc("/api/probations", getProbations)
router.HandleFunc("/api/passreq", reqPass)
router.HandleFunc("/", greetUser)
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))

Loading…
Cancel
Save