forked from Nixius/authelia
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func (a *App) handleResendReset(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(map[string]any{
|
|
"ok": true,
|
|
"message": "Use the sign-in button to continue with your social account.",
|
|
})
|
|
}
|
|
|
|
func respondResendError(w http.ResponseWriter, code int, msg string, retryAfter int) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(code)
|
|
body := map[string]any{"ok": false, "error": msg}
|
|
if retryAfter > 0 {
|
|
body["retry_after_seconds"] = retryAfter
|
|
}
|
|
json.NewEncoder(w).Encode(body)
|
|
}
|
|
|
|
func clientIP(r *http.Request) string {
|
|
if s := r.Header.Get("X-Forwarded-For"); s != "" {
|
|
if idx := strings.Index(s, ","); idx > 0 {
|
|
return strings.TrimSpace(s[:idx])
|
|
}
|
|
return strings.TrimSpace(s)
|
|
}
|
|
if s := r.Header.Get("X-Real-IP"); s != "" {
|
|
return s
|
|
}
|
|
if host, _, err := net.SplitHostPort(r.RemoteAddr); err == nil {
|
|
return host
|
|
}
|
|
return r.RemoteAddr
|
|
}
|