|
|
|
@ -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")))) |
|
|
|
|