add user management functionality with OTP verification and consent handling, DI introduced
This commit is contained in:
45
internal/api/auth/repo/auth_repo.go
Normal file
45
internal/api/auth/repo/auth_repo.go
Normal file
@ -0,0 +1,45 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.logidex.ru/fakz9/logidex-id/internal/api/auth/domain"
|
||||
"github.com/redis/rueidis"
|
||||
)
|
||||
|
||||
type authRepo struct {
|
||||
redisClient rueidis.Client
|
||||
}
|
||||
|
||||
func (a authRepo) GetOtpRequest(ctx context.Context, uuid string) (*string, error) {
|
||||
redisClient := a.redisClient
|
||||
|
||||
resp, err := redisClient.Do(ctx, redisClient.B().Get().Key("otp:"+uuid).Build()).ToString()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp == "" {
|
||||
// create error
|
||||
return nil, &domain.ErrOtpNotFound{Uuid: uuid}
|
||||
}
|
||||
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (a authRepo) SaveOtpRequest(ctx context.Context, uuid string, code string) error {
|
||||
redisClient := a.redisClient
|
||||
|
||||
err := redisClient.Do(ctx, redisClient.B().Set().Key("otp:"+uuid).Value(code).Ex(120*time.Second).Build()).Error()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func NewAuthRepo(redisClient rueidis.Client) domain.AuthRepository {
|
||||
return &authRepo{redisClient: redisClient}
|
||||
}
|
||||
Reference in New Issue
Block a user