Пример #1
0
        public NewClientResponse AddNewClient(NewClientRequest request)
        {
            if (LoginExists(request.Login))
            {
                throw new Exception("User with login " + request.Login + " already exists");
            }

            var clientId       = GenerateNewClientId();
            var hashSalt       = HashSaltGenerator.GenerateSaltedHash(request.Password);
            var hashedPassword = hashSalt.Hash;
            var salt           = hashSalt.Salt;
            var accessToken    = TokensGenerator.GenerateAccessToken(clientId, _configuration);
            var refreshToken   = TokensGenerator.GenerateRefreshToken(clientId, accessToken);

            SaveClient(request, clientId, hashedPassword, salt);
            var refreshId = GetNewRefreshTokenId();
            var accessId  = GetNewAccessTokenId();

            SaveAccessToken(accessToken, clientId, accessId);
            SaveRefreshToken(refreshToken, clientId, refreshId);
            AssignTokensToClient(clientId, accessToken, refreshToken);

            return(new NewClientResponse
            {
                AccessToken = accessToken.Token,
                RefreshToken = refreshToken.Token
            });
        }
Пример #2
0
 private static List <Client> GenerateClients()
 {
     return(new List <Client>
     {
         new Client
         {
             IdClient = 1,
             FirstName = "Jon",
             LastName = "Doe",
             Email = "*****@*****.**",
             Phone = "66666666",
             Login = "******",
             Password = HashSaltGenerator.GenerateSaltedHash("aaaaaaaa").Hash
         },
         new Client
         {
             IdClient = 2,
             FirstName = "Michal",
             LastName = "Scott",
             Email = "*****@*****.**",
             Phone = "5720935",
             Login = "******",
             Password = HashSaltGenerator.GenerateSaltedHash("dunder_mifflin").Hash
         },
         new Client
         {
             IdClient = 3,
             FirstName = "Jack",
             LastName = "Daniels",
             Email = "*****@*****.**",
             Phone = "1234567878",
             Login = "******",
             Password = HashSaltGenerator.GenerateSaltedHash("jack").Hash
         }
     });
 }