slaventius 2 years ago
parent 833033df5e
commit de6b7dff0f
  1. 30
      internal/authDB.go

@ -70,18 +70,18 @@ func (s *AuthDBServer) Login(ctx context.Context, req *api.LoginRequest) (*api.L
defer s.mu.Unlock() defer s.mu.Unlock()
// //
user, ok := s.repo.Customers[req.GetLogin()] customer, ok := s.repo.Customers[req.GetLogin()]
if !ok { if !ok {
return nil, errors.New("login unknown") return nil, errors.New("login unknown")
} }
// //
if !user.Confirmed { if !customer.Confirmed {
return nil, errors.New("login unconfirmed") return nil, errors.New("login unconfirmed")
} }
// //
if user.Password != s.getMD5Hash(req.Password) { if customer.Password != s.getMD5Hash(req.Password) {
return nil, errors.New("password incorrect") return nil, errors.New("password incorrect")
} }
@ -95,36 +95,36 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe
defer s.mu.Unlock() defer s.mu.Unlock()
// //
user, ok := s.repo.Customers[req.GetLogin()] customer, ok := s.repo.Customers[req.GetLogin()]
if !ok { if !ok {
hash := s.getMD5Hash(req.GetPassword()) hash := s.getMD5Hash(req.GetPassword())
user = s.repo.NewCustomer(req.GetLogin(), hash, req.GetEmail(), strconv.Itoa(time.Now().Nanosecond())) customer = s.repo.NewCustomer(req.GetLogin(), hash, req.GetEmail(), strconv.Itoa(time.Now().Nanosecond()))
// //
erk := user.Add() erk := customer.Add()
if erk != nil { if erk != nil {
return nil, erk return nil, erk
} }
// Добавим в локальную копию // Добавим в локальную копию
s.repo.Customers[req.GetLogin()] = user s.repo.Customers[req.GetLogin()] = customer
} else if user.Confirmed || time.Now().Before(user.Time) { } else if customer.Confirmed || time.Now().Before(customer.Time) {
return nil, errors.New("login already registered") return nil, errors.New("login already registered")
} else { // Обновим время регистрации } else { // Обновим время регистрации
user.Refresh() customer.Refresh()
} }
// TODO // TODO
value, era := json.Marshal(user.MessageRegistration) value, era := json.Marshal(customer.MessageRegistration)
if era != nil { if era != nil {
return nil, era return nil, era
} }
// //
s.logger.Printf("publication code %s to %s ...", user.MessageRegistration.Code, user.MessageRegistration.Email) s.logger.Printf("publication code %s to %s ...", customer.MessageRegistration.Code, customer.MessageRegistration.Email)
// Отправим уведомление о необходимости подтверждения // Отправим уведомление о необходимости подтверждения
err := s.kafkaWriter.WriteMessage([]byte(user.Login), value) err := s.kafkaWriter.WriteMessage([]byte(customer.Login), value)
if err != nil { if err != nil {
s.logger.Error(err) s.logger.Error(err)
@ -132,11 +132,11 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe
} }
// //
s.logger.Printf("publication code %s to %s completed", user.MessageRegistration.Code, user.MessageRegistration.Email) s.logger.Printf("publication code %s to %s completed", customer.MessageRegistration.Code, customer.MessageRegistration.Email)
return &api.RegistrationResponse{ return &api.RegistrationResponse{
Code: user.MessageRegistration.Code, Code: customer.MessageRegistration.Code,
Email: user.MessageRegistration.Email, Email: customer.MessageRegistration.Email,
}, nil }, nil
} }

Loading…
Cancel
Save