initial commit on github
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RegisterTokensRouter(r *mux.Router) {
|
||||
sub := r.PathPrefix("/tokens").Subrouter()
|
||||
|
||||
sub.HandleFunc("/auth", auth)
|
||||
sub.HandleFunc("/apps", resolveApps)
|
||||
sub.HandleFunc("/apps/{id:[0-9]+}", auth)
|
||||
}
|
||||
|
||||
func auth(w http.ResponseWriter, r *http.Request) {
|
||||
tokenCookie, err := r.Cookie("token")
|
||||
if err == http.ErrNoCookie || len(tokenCookie.Value) == 0 {
|
||||
Unauthorized.Ferror(w)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func resolveApps(w http.ResponseWriter, r *http.Request) {
|
||||
user, err := FetchCurrentUser(r)
|
||||
if err != nil {
|
||||
Error(w, err)
|
||||
return
|
||||
}
|
||||
if !hasPermission(user, "apps") {
|
||||
NoAccess.Ferror(w)
|
||||
return
|
||||
}
|
||||
apps, err := FetchApps()
|
||||
Response(w, err, apps)
|
||||
}
|
||||
Reference in New Issue
Block a user