slaventius 2 years ago
parent 409813057e
commit bcf71ee104
  1. 26
      internal/transport/grpc/grpc.go

@ -3,7 +3,6 @@ package grpc
import (
"context"
"errors"
"log"
"strconv"
"sync"
api "test3k/authDB/pkg/api"
@ -42,23 +41,17 @@ func (s *AuthDBServer) Login(ctx context.Context, req *api.LoginRequest) (*api.L
//
user, ok := s.users[req.GetLogin()]
if !ok {
return &api.LoginResponse{
ID: 0,
}, errors.New("login unknown")
return nil, errors.New("login unknown")
}
//
if !user.Confirmed {
return &api.LoginResponse{
ID: 0,
}, errors.New("login unconfirmed")
return nil, errors.New("login unconfirmed")
}
//
if user.Password != req.Password {
return &api.LoginResponse{
ID: 0,
}, errors.New("password incorrect")
return nil, errors.New("password incorrect")
}
return &api.LoginResponse{
@ -71,26 +64,21 @@ func (s *AuthDBServer) Registration(ctx context.Context, req *api.RegistrationRe
defer s.mu.Unlock()
//
if val, ok := s.users[req.GetLogin()]; ok {
log.Printf("login %s already registered", val.Login)
return &api.RegistrationResponse{
Code: val.Code,
Email: val.Email,
}, errors.New("login already registered")
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 / 2)
code := strconv.Itoa(unique)
//
s.users[req.Login] = user{
ID: s.id,
Code: code,
Login: req.GetLogin(),
Password: strconv.Itoa(unique),
Password: code, // TODO
Email: req.GetEmail(),
Confirmed: false,
}

Loading…
Cancel
Save