chore: more work on the app
This commit is contained in:
@@ -471,11 +471,19 @@ func (x Handle) createContext(handler *Handle, mode AnswerType, r *http.Request)
|
||||
Prefix: r.URL.Path,
|
||||
})
|
||||
|
||||
for _, r := range r.Cookies() {
|
||||
if r.Name == "auth" {
|
||||
token = &r.Value
|
||||
}
|
||||
}
|
||||
if mode != JSON {
|
||||
for _, r := range r.Cookies() {
|
||||
if r.Name == "auth" {
|
||||
token = &r.Value
|
||||
}
|
||||
}
|
||||
} else {
|
||||
t := r.Header.Get("token")
|
||||
if t != "" {
|
||||
token = &t
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO check that the token is still valid
|
||||
|
||||
@@ -512,14 +520,19 @@ func Redirect(path string, mode AnswerType, w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
func Logoff(mode AnswerType, w http.ResponseWriter, r *http.Request) {
|
||||
// Delete cookie
|
||||
cookie := &http.Cookie{
|
||||
Name: "auth",
|
||||
Value: "",
|
||||
Expires: time.Unix(0, 0),
|
||||
}
|
||||
http.SetCookie(w, cookie)
|
||||
Redirect("/login", mode, w, r)
|
||||
if (mode == JSON) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write([]byte("\"Not Authorized\""))
|
||||
} else {
|
||||
// Delete cookie
|
||||
cookie := &http.Cookie{
|
||||
Name: "auth",
|
||||
Value: "",
|
||||
Expires: time.Unix(0, 0),
|
||||
}
|
||||
http.SetCookie(w, cookie)
|
||||
Redirect("/login", mode, w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func notAuth(mode AnswerType, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user