|
|
|
@ -7,6 +7,7 @@ import ( |
|
|
|
|
"encoding/json" |
|
|
|
|
"errors" |
|
|
|
|
"log" |
|
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
"net" |
|
|
|
|
"strconv" |
|
|
|
@ -23,6 +24,7 @@ import ( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type AuthDBServer struct { |
|
|
|
|
mu sync.Mutex |
|
|
|
|
ctx context.Context |
|
|
|
|
kafkaWriter *kafka.KafkaWriter |
|
|
|
|
logger *logger.Logger |
|
|
|
@ -45,6 +47,7 @@ func NewServer(ctx context.Context, config *config.Config) *AuthDBServer { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return &AuthDBServer{ |
|
|
|
|
mu: sync.Mutex{}, |
|
|
|
|
ctx: ctx, |
|
|
|
|
repo: repo, |
|
|
|
|
kafkaWriter: kafka.NewWriter(ctx, logger, apiKafka.TopicRegistrations, net.JoinHostPort(config.Kafka.Host, strconv.Itoa(config.Kafka.Port))), |
|
|
|
@ -63,6 +66,10 @@ func (s *AuthDBServer) GracefulStop() error { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *AuthDBServer) Login(ctx context.Context, req *api.LoginRequest) (*api.LoginResponse, error) { |
|
|
|
|
s.mu.Lock() |
|
|
|
|
defer s.mu.Unlock() |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
user, ok := s.repo.Customers[req.GetLogin()] |
|
|
|
|
if !ok { |
|
|
|
|
return nil, errors.New("login unknown") |
|
|
|
@ -84,6 +91,10 @@ func (s *AuthDBServer) Login(ctx context.Context, req *api.LoginRequest) (*api.L |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRequest) (*api.RegistrationResponse, error) { |
|
|
|
|
s.mu.Lock() |
|
|
|
|
defer s.mu.Unlock() |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
user, ok := s.repo.Customers[req.GetLogin()] |
|
|
|
|
if !ok { |
|
|
|
|
hash := s.getMD5Hash(req.GetPassword()) |
|
|
|
@ -130,6 +141,10 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *AuthDBServer) Confirmation(ctx context.Context, req *api.ConfirmationRequest) (*api.ConfirmationResponse, error) { |
|
|
|
|
s.mu.Lock() |
|
|
|
|
defer s.mu.Unlock() |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
for _, x := range s.repo.Customers { |
|
|
|
|
if x.Code == req.GetCode() { |
|
|
|
|
if x.Confirmed { |
|
|
|
|