From 862627688dba2e79a0e37c5caf2dd5663a9fc08a Mon Sep 17 00:00:00 2001 From: slaventius Date: Thu, 9 Feb 2023 09:12:52 +0300 Subject: [PATCH] * --- internal/authDB.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/internal/authDB.go b/internal/authDB.go index efe2641..94788a7 100644 --- a/internal/authDB.go +++ b/internal/authDB.go @@ -30,6 +30,7 @@ type user struct { Login string Password string Confirmed bool + Time time.Time msg } @@ -85,28 +86,27 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe s.mu.Lock() defer s.mu.Unlock() - // // - // if _, ok := s.users[req.GetLogin()]; ok { - // return nil, errors.New("login already registered") - // } - // - s.id = s.id + 1 - unique := time.Now().Nanosecond() - code := strconv.Itoa(unique) + if val, ok := s.users[req.GetLogin()]; ok { + if time.Now().Before(val.Time) { + return nil, errors.New("login already registered") + } + } else { + s.id = s.id + 1 + } // user := &user{ ID: s.id, Login: req.GetLogin(), - Password: code, // TODO + Password: req.GetPassword(), Confirmed: false, + Time: time.Now().Add(time.Minute * 15), msg: msg{ - Code: code, + Code: strconv.Itoa(time.Now().Nanosecond()), Email: req.GetEmail(), }, } - s.users[req.Login] = user // TODO value, eru := json.Marshal(user.msg) @@ -123,6 +123,8 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe log.Print(err) return nil, err + } else { + s.users[req.Login] = user } //