-
Notifications
You must be signed in to change notification settings - Fork 60
/
d_api_auth.go
45 lines (41 loc) · 1.02 KB
/
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
42
43
44
45
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)
case "openidlogin":
dAPIOpenIDLoginHandler(w, r, s)
case "certs":
dAPIOpenIDCertHandler(w, r)
default:
w.WriteHeader(http.StatusNotFound)
ReturnJSON(w, r, map[string]interface{}{
"status": "error",
"err_msg": "Unknown auth command: (" + r.URL.Path + ")",
})
}
}