Пример #1
0
        public async Task <RegisterCommandResult> Handle(RegisterCommand request, CancellationToken cancellationToken)
        {
            var user = request.ToUser();
            await userRepository.Add(user);

            var token  = authenticationTokenService.GenerateToken(user);
            var result = new RegisterCommandResult(user.Id, user.UserName, token);

            result.Created();
            return(result);
        }
        public async Task <AuthenticateCommandResult> Handle(AuthenticateCommand request, CancellationToken cancellationToken)
        {
            var user = await this.userRepository.GetByEmail(request.UserName);

            if (user == null || !request.Password.Equals(user.Password))
            {
                var result = new AuthenticateCommandResult();
                result.NotFound("Usuário e/ou senha inválidos.");
                return(result);
            }

            var token = authenticationTokenService.GenerateToken(user);

            return(new AuthenticateCommandResult(user.UserName, token));
        }