feat: secure service connections and login

This commit is contained in:
2026-11-06 21:14:49 +03:00
parent cb51354889
commit 48918e8b19
59 changed files with 1980 additions and 316 deletions
+14 -1
View File
@@ -10,7 +10,7 @@ import (
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
"gitea.privcloud.tech/dizi/mtusi2026lab6/internal/model"
"gitea.privcloud.tech/dizi/mtusi2026lab7/internal/model"
)
type Store struct {
@@ -100,6 +100,19 @@ func (s *Store) UserByUsername(ctx context.Context, username string) (model.User
return credentials, nil
}
func (s *Store) UpdatePasswordHash(ctx context.Context, userID, previousHash, passwordHash string) (bool, error) {
const query = `
UPDATE users
SET password_hash = $1
WHERE id = $2 AND password_hash = $3`
result, err := s.pool.Exec(ctx, query, passwordHash, userID, previousHash)
if err != nil {
return false, fmt.Errorf("update password hash: %w", err)
}
return result.RowsAffected() == 1, nil
}
func (s *Store) CreateChat(
ctx context.Context,
title string,