mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
Major refactorings.
Introduce summaries.
This commit is contained in:
@@ -17,19 +17,19 @@ type AuthenticateMiddleware struct {
|
||||
func (m *AuthenticateMiddleware) Handle(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
authHeader := strings.Split(r.Header.Get("Authorization"), " ")
|
||||
if len(authHeader) != 2 {
|
||||
w.WriteHeader(401)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
key, err := base64.StdEncoding.DecodeString(authHeader[1])
|
||||
if err != nil {
|
||||
w.WriteHeader(401)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := m.UserSrvc.GetUserByKey(strings.TrimSpace(string(key)))
|
||||
if err != nil {
|
||||
w.WriteHeader(401)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user