Exemplo n.º 1
0
        public async Task <AuthenticationToken> ConnectAsync(string login, string password)
        {
            CheckNullParameter(login, "Login");

            CheckNullParameter(password, "Mot de passe");

            var user = await _credentialsRepository.GetUserAsync(login);

            if (user is null)
            {
                throw new NotFoundException <string>(login);
            }

            if (user.EstCompteBloque)
            {
                throw new AccessViolationException();
            }

            if (password != user.Password)
            {
                user.NbTentativesConnexions++;
                await _credentialsRepository.SaveUserAsync(user);

                throw new ArgumentException("Mot de passe erroné");
            }

            user.NbTentativesConnexions = 0;
            await _credentialsRepository.SaveUserAsync(user);

            return(new AuthenticationToken(Guid.NewGuid()));
        }