fix: INVITE USER

This commit is contained in:
lianghuanjie
2025-01-06 19:45:03 +08:00
parent af258d2207
commit c540744176
12 changed files with 344 additions and 39 deletions

View File

@@ -16,17 +16,17 @@ func NewAdminSecretCheckMiddleware(conf model.NhSystemConfigModel) *AdminSecretC
func (m *AdminSecretCheckMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if key, err := m.conf.GetAdminSecret(r.Context()); err != nil {
key, err := m.conf.GetAdminSecret(r.Context())
if err != nil {
if !errors.Is(err, model.ErrNotFound) {
http.Error(w, "system error", http.StatusInternalServerError)
return
}
} else {
apiKey := r.Header.Get("x-admin-secret")
if apiKey != key {
http.Error(w, "Invalid API key", http.StatusUnauthorized)
return
}
}
apiKey := r.Header.Get("x-admin-secret")
if apiKey == "" || apiKey != key {
http.Error(w, "Invalid API key", http.StatusUnauthorized)
return
}
next(w, r)
}

View File

@@ -16,17 +16,17 @@ func NewApiKeyCheckMiddleware(conf model.NhSystemConfigModel) *ApiKeyCheckMiddle
func (m *ApiKeyCheckMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if key, err := m.conf.GetCarvApiKey(r.Context()); err != nil {
key, err := m.conf.GetCarvApiKey(r.Context())
if err != nil {
if !errors.Is(err, model.ErrNotFound) {
http.Error(w, "system error", http.StatusInternalServerError)
return
}
} else {
apiKey := r.Header.Get("x-api-key")
if apiKey != key {
http.Error(w, "Invalid API key", http.StatusUnauthorized)
return
}
}
apiKey := r.Header.Get("x-api-key")
if apiKey == "" || apiKey != key {
http.Error(w, "Invalid API key", http.StatusUnauthorized)
return
}
next(w, r)