generated from VLADIMIR/template
add refresh-password route
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package repos
|
||||
|
||||
type User struct {
|
||||
Username string
|
||||
Email string
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user