slaventius 2 years ago
parent 49da806b33
commit 833033df5e
  1. 28
      internal/authDB.go
  2. 2
      internal/customer/amodel.go
  3. 11
      internal/customer/customer.go
  4. 14
      internal/customer/repository.go

@ -98,14 +98,16 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe
user, ok := s.repo.Customers[req.GetLogin()]
if !ok {
hash := s.getMD5Hash(req.GetPassword())
tmpUser, eru := s.repo.NewCustomer(req.GetLogin(), hash, req.GetEmail(), strconv.Itoa(time.Now().Nanosecond()))
if eru != nil {
s.logger.Error(eru)
user = s.repo.NewCustomer(req.GetLogin(), hash, req.GetEmail(), strconv.Itoa(time.Now().Nanosecond()))
return nil, eru
//
erk := user.Add()
if erk != nil {
return nil, erk
}
user = tmpUser
// Добавим в локальную копию
s.repo.Customers[req.GetLogin()] = user
} else if user.Confirmed || time.Now().Before(user.Time) {
return nil, errors.New("login already registered")
} else { // Обновим время регистрации
@ -113,7 +115,7 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe
}
// TODO
_, era := json.Marshal(user.MessageRegistration)
value, era := json.Marshal(user.MessageRegistration)
if era != nil {
return nil, era
}
@ -121,15 +123,13 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe
//
s.logger.Printf("publication code %s to %s ...", user.MessageRegistration.Code, user.MessageRegistration.Email)
// //
// err := s.kafkaWriter.WriteMessage([]byte(user.Login), value)
// if err != nil {
// s.logger.Error(err)
// Отправим уведомление о необходимости подтверждения
err := s.kafkaWriter.WriteMessage([]byte(user.Login), value)
if err != nil {
s.logger.Error(err)
// return nil, err
// } else {
s.repo.Customers[req.Login] = user
// }
return nil, err
}
//
s.logger.Printf("publication code %s to %s completed", user.MessageRegistration.Code, user.MessageRegistration.Email)

@ -34,7 +34,7 @@ type SimpleRow struct {
func NewSimpleRow(ctx context.Context, database driver.Database, collection driver.Collection) *SimpleRow {
now := time.Now()
nowStr := now.Format(StampTemplate)
key := strconv.Itoa(now.Nanosecond())
key := strconv.Itoa(now.Nanosecond() * -1)
return &SimpleRow{
Row: Row{

@ -16,6 +16,17 @@ type Customer struct {
Time time.Time
}
func (c *Customer) Add() error {
meta, err := c.collection.CreateDocument(c.ctx, c)
if err != nil {
return err
} else {
c.key = meta.Key
}
return nil
}
func (c *Customer) Update() error {
_, err := c.collection.UpdateDocument(c.ctx, c.key, c)

@ -35,8 +35,8 @@ func NewCustomerRepository(ctx context.Context, database *arango_db.DataBase) *C
}
// Новый покупатель
func (r *CustomerRepository) NewCustomer(login string, password string, email string, code string) (Customer, error) {
customer := Customer{
func (r *CustomerRepository) NewCustomer(login string, password string, email string, code string) Customer {
return Customer{
SimpleRow: *NewSimpleRow(r.ctx, r.database, r.collection),
Login: login,
Password: password,
@ -46,16 +46,6 @@ func (r *CustomerRepository) NewCustomer(login string, password string, email st
Code: code,
},
}
//
meta, err := r.collection.CreateDocument(r.ctx, customer)
if err != nil {
return customer, err
} else {
customer.key = meta.Key
}
return customer, nil
}
func (r *CustomerRepository) FetchAll() error {

Loading…
Cancel
Save