fix: login session IP parsing and username lookup
This commit is contained in:
@@ -3,12 +3,15 @@ package handler
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/panelhosting/panel/internal/auth"
|
||||
"github.com/panelhosting/panel/internal/authsvc"
|
||||
"github.com/panelhosting/panel/internal/config"
|
||||
"github.com/panelhosting/panel/internal/httputil"
|
||||
"github.com/panelhosting/panel/internal/middleware"
|
||||
)
|
||||
|
||||
@@ -34,9 +37,9 @@ func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
result, err := h.svc.Login(r.Context(), authsvc.LoginInput{
|
||||
Username: req.Username,
|
||||
Username: strings.TrimSpace(req.Username),
|
||||
Password: req.Password,
|
||||
IP: r.RemoteAddr,
|
||||
IP: httputil.ClientIP(r),
|
||||
UserAgent: r.UserAgent(),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -44,6 +47,7 @@ func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusUnauthorized, "invalid credentials")
|
||||
return
|
||||
}
|
||||
log.Printf("login error: %v", err)
|
||||
writeError(w, http.StatusInternalServerError, "login failed")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user