Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-02-18 15:44:51 +03:00
parent 13f8801379
commit d2bd0684c1
2 changed files with 116 additions and 19 deletions

View File

@@ -29,7 +29,7 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
r.Method,
r.URL.Path,
)
http.Error(w, "unauthorized: token missing or invalid", http.StatusUnauthorized)
http.Error(w, "yetkisiz: token eksik veya geçersiz", http.StatusUnauthorized)
return
}
@@ -39,14 +39,14 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, "invalid payload", http.StatusBadRequest)
http.Error(w, "geçersiz istek gövdesi", http.StatusBadRequest)
return
}
req.CurrentPassword = strings.TrimSpace(req.CurrentPassword)
req.NewPassword = strings.TrimSpace(req.NewPassword)
if req.CurrentPassword == "" || req.NewPassword == "" {
http.Error(w, "password fields required", http.StatusUnprocessableEntity)
http.Error(w, "şifre alanları zorunludur", http.StatusUnprocessableEntity)
return
}
@@ -61,7 +61,7 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
claims.ID,
mkErr,
)
http.Error(w, "user lookup failed", http.StatusInternalServerError)
http.Error(w, "kullanıcı sorgulama hatası", http.StatusInternalServerError)
return
}
@@ -79,20 +79,30 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
claims.ID,
claims.Username,
)
http.Error(w, "mevcut sifre hatali", http.StatusUnauthorized)
http.Error(w, "mevcut şifre hatalı", http.StatusUnauthorized)
return
}
} else {
var err error
legacyUser, err = legacyRepo.GetLegacyUserForLogin(claims.Username)
if err != nil || legacyUser == nil || !legacyUser.IsActive || int64(legacyUser.ID) != claims.ID {
if err != nil || legacyUser == nil || !legacyUser.IsActive {
log.Printf(
"FIRST_PASSWORD_CHANGE 401 reason=legacy_user_not_found user_id=%d username=%s err=%v",
claims.ID,
claims.Username,
err,
)
http.Error(w, "unauthorized: user not found", http.StatusUnauthorized)
http.Error(w, "yetkisiz: kullanıcı bulunamadı", http.StatusUnauthorized)
return
}
if !hasMkUser && int64(legacyUser.ID) != claims.ID {
log.Printf(
"FIRST_PASSWORD_CHANGE 401 reason=legacy_id_mismatch user_id=%d legacy_id=%d username=%s",
claims.ID,
legacyUser.ID,
claims.Username,
)
http.Error(w, "yetkisiz: kullanıcı bulunamadı", http.StatusUnauthorized)
return
}
@@ -102,7 +112,7 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
claims.ID,
claims.Username,
)
http.Error(w, "mevcut sifre hatali", http.StatusUnauthorized)
http.Error(w, "mevcut şifre hatalı", http.StatusUnauthorized)
return
}
}
@@ -117,13 +127,13 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
bcrypt.DefaultCost,
)
if err != nil {
http.Error(w, "password hash error", http.StatusInternalServerError)
http.Error(w, "şifre hash hatası", http.StatusInternalServerError)
return
}
tx, err := db.Begin()
if err != nil {
http.Error(w, "transaction error", http.StatusInternalServerError)
http.Error(w, "işlem başlatılamadı", http.StatusInternalServerError)
return
}
defer tx.Rollback()
@@ -146,7 +156,7 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
claims.ID,
err,
)
http.Error(w, "password update failed", http.StatusInternalServerError)
http.Error(w, "şifre güncellenemedi", http.StatusInternalServerError)
return
}
@@ -156,21 +166,31 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
"FIRST_PASSWORD_CHANGE 500 reason=password_update_no_rows user_id=%d",
claims.ID,
)
http.Error(w, "password update failed", http.StatusInternalServerError)
http.Error(w, "şifre güncellenemedi", http.StatusInternalServerError)
return
}
} else {
if legacyUser == nil {
// Defensive fallback, should not happen.
legacyUser, err = legacyRepo.GetLegacyUserForLogin(claims.Username)
if err != nil || legacyUser == nil || int64(legacyUser.ID) != claims.ID {
if err != nil || legacyUser == nil {
log.Printf(
"FIRST_PASSWORD_CHANGE 500 reason=legacy_reload_failed user_id=%d username=%s err=%v",
claims.ID,
claims.Username,
err,
)
http.Error(w, "legacy user reload failed", http.StatusInternalServerError)
http.Error(w, "legacy kullanıcı yeniden yüklenemedi", http.StatusInternalServerError)
return
}
if !hasMkUser && int64(legacyUser.ID) != claims.ID {
log.Printf(
"FIRST_PASSWORD_CHANGE 500 reason=legacy_reload_id_mismatch user_id=%d legacy_id=%d username=%s",
claims.ID,
legacyUser.ID,
claims.Username,
)
http.Error(w, "legacy kullanıcı yeniden yüklenemedi", http.StatusInternalServerError)
return
}
}
@@ -222,7 +242,7 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
claims.Username,
err,
)
http.Error(w, "legacy migration failed", http.StatusInternalServerError)
http.Error(w, "legacy geçişi başarısız", http.StatusInternalServerError)
return
}
@@ -235,7 +255,7 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
claims.ID,
err,
)
http.Error(w, "commit failed", http.StatusInternalServerError)
http.Error(w, "işlem tamamlanamadı", http.StatusInternalServerError)
return
}
@@ -262,7 +282,7 @@ func FirstPasswordChangeHandler(db *sql.DB) http.HandlerFunc {
false,
)
if err != nil {
http.Error(w, "token generation failed", http.StatusInternalServerError)
http.Error(w, "token üretilemedi", http.StatusInternalServerError)
return
}