예제 #1
0
        public async Task <IActionResult> ConfirmUserEmail(Guid id, ConfirmUserEmailCommand input)
        {
            input.Id = id;
            await _mediator.Publish(input);

            return(Ok());
        }
예제 #2
0
 public async Task ConfirmUser_ThrowsInvalidUserException(string userId, string token)
 {
     // Arrange
     Mediator.Setup(m => m.Send(It.IsAny <GetUserByIdQuery>(), default(CancellationToken))).Returns(Task.FromResult((ApplicationUser)null));
     var query = new ConfirmUserEmailCommand(userId, token);
     // Act / Assert
     await Assert.ThrowsAsync <InvalidUserException>(() => Handler.Handle(query, CancellationToken.None));
 }
예제 #3
0
        public void ConfirmUserEmail_SuccessfullyConfirmsEmail(string userId, string token)
        {
            // Arrange
            var requestedUser = new ApplicationUser()
            {
                Id = userId
            };

            Mediator.Setup(m => m.Send(It.IsAny <GetUserByIdQuery>(), default(CancellationToken))).Returns(Task.FromResult(requestedUser));
            UserManager.Setup(u => u.ConfirmEmailAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>())).Returns(Task.FromResult(IdentityResult.Success));
            var query = new ConfirmUserEmailCommand(userId, token);
            // Act
            var result = Handler.Handle(query, CancellationToken.None).Result;

            // Assert
            Assert.True(result);
        }
예제 #4
0
        public async Task ConfirmEmail(ConfirmUserEmailCommand command)
        {
            command.Validate();

            if (AddNotifications(command))
            {
                return;
            }

            LedgerIdentityUser user = await GetByEmail(command.Email);

            if (NotifyNullUser(user))
            {
                return;
            }

            IdentityResult result = await _userManager.ConfirmEmailAsync(user, command.ConfirmationToken);

            if (!result.Succeeded)
            {
                AddNotifications(result);
            }
            else
            {
                Claim          activatedAccountClaim = new Claim("activated-account", "true");
                IdentityResult claimResult           = await _userManager.AddClaimAsync(user, activatedAccountClaim);

                if (!claimResult.Succeeded)
                {
                    AddNotifications(claimResult);
                }
                else
                {
                    await PublishLocal(new UserEmailConfirmedEvent(user.Email));
                }
            }
        }
예제 #5
0
        public async Task ConfirmEmailAsync(ConfirmUserEmailCommand command)
        {
            if (NotifyCommandErrors(command))
            {
                return;
            }

            NutrientIdentityUser user = await _userManager.FindByEmailAsync(command.Email);

            if (NotifyNullUser(user, command.Email))
            {
                return;
            }

            IdentityResult result = await _userManager.ConfirmEmailAsync(user, command.ConfirmationToken);

            if (!result.Succeeded)
            {
                NotifyIdentityErrors(result);
            }
            else
            {
                IdentityResult claimSuccess = await _userManager.AddClaimAsync(user, new Claim("ActiveProfile", "true"));

                if (claimSuccess.Succeeded)
                {
                    await PublishAsync(new UserConfirmedEmailIntegrationEvent(user.Id, user.Email));
                }
                else
                {
                    _logger.LogError("Falha ao adicionar claim de confirmação de e-mail para usuário {email}. Motivo: {errors}.", user.Email, claimSuccess.Errors);

                    AddNotification("Falha nas claims", "Ocorreu uma falha ao registrar ou atualizar as claims padrões desse usuário.");
                }
            }
        }
예제 #6
0
        public async Task <IActionResult> ConfirmEmail([FromBody] ConfirmUserEmailCommand command)
        {
            await _userApplicationService.ConfirmEmail(command);

            return(CreateResponse());
        }
예제 #7
0
        public async Task <IActionResult> ConfirmEmailAsync([FromBody] ConfirmUserEmailCommand command)
        {
            await _accountService.ConfirmEmailAsync(command);

            return(CreateResponse());
        }
예제 #8
0
 public async Task <IActionResult> PostConfirmEmailAsync([FromBody] ConfirmUserEmailCommand confirmUserEmailCommand) => Ok(new { result = await _mediator.Send(confirmUserEmailCommand) });