summaryrefslogtreecommitdiff
path: root/handlers/auth_login.go
diff options
context:
space:
mode:
authorhaturatu <taro@eyes4you.org>2026-04-22 04:46:24 +0900
committerhaturatu <taro@eyes4you.org>2026-04-22 04:46:24 +0900
commit4b0271272e983fdb85d4b816cbd91f34d91a7884 (patch)
treead92ba661f0f9e8b16d93f333ebf43ffd331a892 /handlers/auth_login.go
parentd18b4f9d615d8942ff604a53be92da2c8e853635 (diff)
feat(backend): pocketbase authHEADmain
Diffstat (limited to 'handlers/auth_login.go')
-rw-r--r--handlers/auth_login.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/handlers/auth_login.go b/handlers/auth_login.go
index 33a3482..b0a288a 100644
--- a/handlers/auth_login.go
+++ b/handlers/auth_login.go
@@ -50,8 +50,8 @@ func authenticateUser(username, password, ip string) (*types.User, error) {
}
}
- // Step 2: If the account is active, validate credentials.
- if !models.CheckPasswordHash(password, user.PasswordHash) {
+ // Step 2: If the account is active, validate credentials against PocketBase.
+ if _, err := models.AuthenticateWithPassword(username, password); err != nil {
// Record the failure
if err := models.RecordLoginFailure(user.ID); err != nil {
logging.AppLog.Error("Failed to record login failure", "error", err, "user_id", user.ID, "ip", ip)
@@ -62,7 +62,7 @@ func authenticateUser(username, password, ip string) (*types.User, error) {
maxAttempts := config.Paths.MaxLoginAttempts
// Lock the account if max attempts are exceeded
- if maxAttempts > 0 && updatedUser.FailedLogins >= maxAttempts {
+ if updatedUser != nil && maxAttempts > 0 && updatedUser.FailedLogins >= maxAttempts {
if err := models.SetUserActiveStatus(user.ID, false); err != nil {
logging.AppLog.Error("Failed to lock account", "error", err, "user_id", user.ID, "ip", ip)
}
@@ -77,6 +77,9 @@ func authenticateUser(username, password, ip string) (*types.User, error) {
if err := models.RecordLoginSuccess(user.ID); err != nil {
logging.AppLog.Error("Failed to record login success", "error", err, "user_id", user.ID, "ip", ip)
}
+ if refreshedUser, refreshErr := models.GetUserByID(user.ID); refreshErr == nil && refreshedUser != nil {
+ user = refreshedUser
+ }
logging.SecurityLog.Info("AUTH SUCCESS", "username", user.Username, "ip", ip)
return user, nil
@@ -148,7 +151,7 @@ func LoginHandler(w http.ResponseWriter, r *http.Request) {
// --- Create Session Cookie ---
duration := time.Duration(config.Paths.TokenDurationHours) * time.Hour
- token, err := models.CreateAuthToken(user.ID, duration)
+ token, err := models.CreateAuthToken(user, duration)
if err != nil {
logging.AppLog.Error("Failed to create auth token", "error", err, "username", user.Username, "ip", ip)
renderLoginWithError(w, r, "Could not create session.")