forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d_api_auth.go
41 lines (37 loc) · 942 Bytes
/
d_api_auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package uadmin
import (
"net/http"
"strings"
)
func dAPIAuthHandler(w http.ResponseWriter, r *http.Request, s *Session) {
if DisableDAPIAuth {
w.WriteHeader(http.StatusForbidden)
ReturnJSON(w, r, map[string]interface{}{
"status": "error",
"err_msg": "dAPI auth is disabled",
})
return
}
// Trim leading path
r.URL.Path = strings.TrimPrefix(r.URL.Path, "auth")
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/")
r.URL.Path = strings.TrimSuffix(r.URL.Path, "/")
switch r.URL.Path {
case "login":
dAPILoginHandler(w, r, s)
case "logout":
dAPILogoutHandler(w, r, s)
case "signup":
dAPISignupHandler(w, r, s)
case "resetpassword":
dAPIResetPasswordHandler(w, r, s)
case "changepassword":
dAPIChangePasswordHandler(w, r, s)
default:
w.WriteHeader(http.StatusNotFound)
ReturnJSON(w, r, map[string]interface{}{
"status": "error",
"err_msg": "Unknown auth command: (" + r.URL.Path + ")",
})
}
}