add refresh-password route

This commit is contained in:
2026-06-30 21:06:51 +07:00
parent 4d9b73cb34
commit d22ad7cb09
9 changed files with 366 additions and 28 deletions
+6
View File
@@ -0,0 +1,6 @@
package repos
type User struct {
Username string
Email string
}
+29 -2
View File
@@ -7,6 +7,10 @@ import (
"github.com/jackc/pgx/v5/pgxpool"
)
var (
ErrUserNotFound = errors.New("Пользователь не найден")
)
type UsersRepo struct {
pool *pgxpool.Pool
}
@@ -21,7 +25,7 @@ func (s *UsersRepo) AddUser(
ctx context.Context,
username string,
email string,
passwoedHash string,
passwordHash string,
role string,
) error {
tag, err := s.pool.Exec(
@@ -34,7 +38,7 @@ func (s *UsersRepo) AddUser(
)`,
username,
email,
passwoedHash,
passwordHash,
role,
username,
@@ -48,3 +52,26 @@ func (s *UsersRepo) AddUser(
}
return nil
}
func (s *UsersRepo) UpdateUserPassword(
ctx context.Context,
email string,
passwordHash string,
) error {
tag, err := s.pool.Exec(
ctx,
`UPDATE users
SET password_hash = $1
WHERE email = $2`,
passwordHash,
email,
)
if err != nil {
return err
}
if tag.RowsAffected() == 0 {
return ErrUserNotFound
}
return nil
}