Ejemplo n.º 1
0
        public async Task <IActionResult> Logout()
        {
            var command = new LogoutUserCommand();
            await _mediatr.SendAsync(command);

            return(Redirect("~/"));
        }
Ejemplo n.º 2
0
        public async Task ShouldCallHandle()
        {
            LogoutUserCommandHandler logoutUserCommandHandler = new LogoutUserCommandHandler(tokenManager.Object);
            LogoutUserCommand        logoutUserCommand        = new LogoutUserCommand();

            var result = await logoutUserCommandHandler.Handle(logoutUserCommand, new CancellationToken());

            result.Should().Be(Unit.Value);
        }
Ejemplo n.º 3
0
 public async Task Logout(LogoutUserCommand command, CancellationToken cancellationToken = default)
 {
     try
     {
         await _userCommandHandler.ExecuteAsync(command, cancellationToken);
     }
     catch (Exception ex)
     { throw ex; }
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Logout([FromBody] LogoutUserCommand command)
        {
            var result = await Mediator.Send(command);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result.Errors));
        }
Ejemplo n.º 5
0
        public void Execute_UserProcessor_IsCalled()
        {
            var  userProcessor = Substitute.For <IUserProcessor>();
            Guid userId        = Guid.NewGuid();
            var  logger        = Substitute.For <ILogger>();
            var  command       = new LogoutUserCommand {
                UserProcessor = userProcessor, Logger = logger, UserId = userId
            };

            command.Execute();

            userProcessor.Received().LogOut(userId);
        }
Ejemplo n.º 6
0
        public async Task ExecuteAsync(LogoutUserCommand command, CancellationToken cancellationToken = default)
        {
            try
            {
                ValidateCommand(command);

                var user = await _userRepository.GetOneAsync(u => u.Company == command.Company && u.CPF == command.CPF);

                if (user == null)
                {
                    throw new ArgumentNullException(nameof(user));
                }

                user.Logout();

                _userRepository.Update(user);
                await _userRepository.SaveChangesAsync(cancellationToken);
            }
            catch (Exception ex)
            { throw ex; }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Logout(CancellationToken cancellationToken = default)
        {
            var response = new LogoutResponse();

            try
            {
                // get company and email data from jwt
                var company = _httpContext.HttpContext.User.Claims.First(c => c.Type == "company")?.Value;
                var email   = _httpContext.HttpContext.User.Claims.First(c => c.Type == "username")?.Value;
                var command = new LogoutUserCommand(company, email);

                await _userAppService.Logout(command, cancellationToken);

                return(NoContent());
            }
            catch (Exception ex)
            {
                response.StatusCode = 500;
                response.Messages.Add(ResponseMessage.Create(ex, ""));
                return(StatusCode(500, response));
            }
        }
Ejemplo n.º 8
0
        public string DispatchCommand(string[] commandParameters)
        {
            PictureService pictureService = new PictureService();
            AlbumService   albumService   = new AlbumService();
            UserService    userService    = new UserService();
            TownService    townService    = new TownService();
            TagService     tagService     = new TagService();

            string commandName = commandParameters[0];

            commandParameters = commandParameters.Skip(1).ToArray();
            string result = string.Empty;

            switch (commandName)
            {
            case "RegisterUser":
                RegisterUserCommand registerUser = new RegisterUserCommand(userService);
                result = registerUser.Execute(commandParameters);
                break;

            case "AddTown":
                AddTownCommand addTown = new AddTownCommand(townService);
                result = addTown.Execute(commandParameters);
                break;

            case "ModifyUser":
                ModifyUserCommand modifyUser = new ModifyUserCommand(userService, townService);
                result = modifyUser.Execute(commandParameters);
                break;

            case "DeleteUser":
                DeleteUserCommand deleteUser = new DeleteUserCommand(userService);
                result = deleteUser.Execute(commandParameters);
                break;

            case "AddTag":
                AddTagCommand addTag = new AddTagCommand(tagService);
                result = addTag.Execute(commandParameters);
                break;

            case "CreateAlbum":
                CreateAlbumCommand createAlbum = new CreateAlbumCommand(albumService, userService, tagService);
                result = createAlbum.Execute(commandParameters);
                break;

            case "AddTagTo":
                AddTagToCommand addTagTo = new AddTagToCommand(albumService, tagService);
                result = addTagTo.Execute(commandParameters);
                break;

            case "MakeFriends":
                MakeFriendsCommand makeFriends = new MakeFriendsCommand(userService);
                result = makeFriends.Execute(commandParameters);
                break;

            case "ListFriends":
                ListFriendsCommand listFriends = new ListFriendsCommand(userService);
                result = listFriends.Execute(commandParameters);
                break;

            case "ShareAlbum":
                ShareAlbumCommand shareAlbum = new ShareAlbumCommand(albumService, userService);
                result = shareAlbum.Execute(commandParameters);
                break;

            case "UploadPicture":
                UploadPictureCommand uploadPicture = new UploadPictureCommand(albumService, pictureService);
                result = uploadPicture.Execute(commandParameters);
                break;

            case "Exit":
                ExitCommand exit = new ExitCommand();
                exit.Execute();
                break;

            case "Login":
                LoginUserCommand loginUser = new LoginUserCommand();
                result = loginUser.Execute(commandParameters);
                break;

            case "Logout":
                LogoutUserCommand logoutUser = new LogoutUserCommand();
                result = logoutUser.Execute(commandParameters);
                break;

            default:
                result = $"Command {commandName} not valid!";
                break;
            }

            return(result);
        }
 public async Task <ActionResult <Unit> > Logout(LogoutUserCommand command)
 {
     return(await Mediator.Send(command));
 }
        public async Task <ActionResult> Logout(LogoutUserCommand command)
        {
            await Mediator.Send(command);

            return(Ok());
        }
        public void ShouldLogoutUser([Frozen] Mock <IAccessTokenConfiguration> accessTokenConfigurationMock, [Frozen] Mock <TextWriter> writer, LogoutUserCommand logoutCommand)
        {
            logoutCommand.Execute(new string[0]);

            writer.Verify(x => x.WriteLine("Successfully logged out."));
            accessTokenConfigurationMock.Verify(x => x.DeleteAccessToken(), Times.Once());
        }
 public async Task HandleAsync(LogoutUserCommand command)
 {
     NPublisher.PublishIt <LogoutMessage>();
 }