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()
//
user, ok := s.repo.Customers[req.GetLogin()]
customer, ok := s.repo.Customers[req.GetLogin()]
if !ok {
return nil, errors.New("login unknown")
}
//
if !user.Confirmed {
if !customer.Confirmed {
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")
}
@ -95,36 +95,36 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe
defer s.mu.Unlock()
//
user, ok := s.repo.Customers[req.GetLogin()]
customer, ok := s.repo.Customers[req.GetLogin()]
if !ok {
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 {
return nil, erk
}
// Добавим в локальную копию
s.repo.Customers[req.GetLogin()] = user
} else if user.Confirmed || time.Now().Before(user.Time) {
s.repo.Customers[req.GetLogin()] = customer
} else if customer.Confirmed || time.Now().Before(customer.Time) {
return nil, errors.New("login already registered")
} else { // Обновим время регистрации
user.Refresh()
customer.Refresh()
}
// TODO
value, era := json.Marshal(user.MessageRegistration)
value, era := json.Marshal(customer.MessageRegistration)
if era != nil {
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 {
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{
Code: user.MessageRegistration.Code,
Email: user.MessageRegistration.Email,
Code: customer.MessageRegistration.Code,
Email: customer.MessageRegistration.Email,
}, nil
}

Loading…
Cancel
Save