public async Task Consume(ConsumeContext <ActivateUser> context) { var message = context.Message; try { var user = await _userService.ActivateAsync(message.ActivationToken); var @event = new UserActivated { Id = user.Id, Username = user.Username }; await _bus.Publish(@event); } catch (Exception ex) { var domainException = ex as UserServiceException; var failedEvent = new ActivateUserFailed { Username = domainException?.Username, Id = domainException?.UserId, ActivationToken = message.ActivationToken }; await _bus.Publish(failedEvent); throw; } }
public async Task <IActionResult> Login(LoginViewModel login) { if (!ModelState.IsValid) { return(InvalidCredentials(login, false)); } var user = await unitOfWork.Users.SingleOrDefaultAsync(x => x.Email == login.Email.Trim()); if (user == null) { return(InvalidCredentials(login)); } if (!userService.VerifyPassword(user, login.Password)) { return(InvalidCredentials(login)); } if (!user.IsActive) { user = await userService.ActivateAsync(user); } await authService.SignInAsync(user); return(RedirectToAction("Index", "Home")); }
protected override async Task Handle(ActivateAccountCommand command, CancellationToken cancellationToken) { await _handler .Run(async() => { await _userService.ActivateAsync(command.Email, command.Token); await _userService.SaveChangesAsync(cancellationToken); }) .OnSuccess(async() => { var user = await _userService.GetByEmailAsync(command.Email); await _mediatRBus.PublishAsync( new AccountActivatedDomainEvent(command.Request.Id, command.Email, user.Id), cancellationToken); }) .OnCustomError(async customException => { await _mediatRBus.PublishAsync( new ActivateAccountRejectedDomainEvent(command.Request.Id, command.Email, customException.Code, customException.Message), cancellationToken); }) .OnError(async(exception, logger) => { logger.Error(exception, $"Error when activating account for user with email: {command.Email}.", exception); await _mediatRBus.PublishAsync( new ActivateAccountRejectedDomainEvent(command.Request.Id, command.Email, Codes.Error, exception.Message), cancellationToken); }) .ExecuteAsync(); }
public async Task <IActionResult> Activate([FromBody] UserInfoDto userInfoDto) { if (!User.IsInRole("Administrator")) { return(Forbid()); } var username = userInfoDto.Username; var existingUserInfoDto = await _service.GetUserByUsernameAsync(username); if (existingUserInfoDto == null) { return(NotFound()); } var client = User.Claims.First(x => x.Type == "aud").Value; var result = await _service.ActivateAsync(existingUserInfoDto, client); if (result != 1) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Activate(string userId) { _logger.LogInformation("Activate action of UserController."); await _userService.ActivateAsync(userId); return(RedirectToAction(RedirectPath.ShowAllAction, RedirectPath.UserController)); }
public async Task ActivateAsync() { // Arrange await PrepareTest(); // Act await _userService.ActivateAsync(UserId); // Assert var response = await _userRepository.GetByIdAsync(UserId); response.IsActive.Should().BeTrue(); }
public async Task <IActionResult> Activation([FromBody] Activate command) { if (!ModelState.IsValid) { return(BadRequest(new { errorMessage = "Value of activation key is invalid" })); } try { await _userService.ActivateAsync(command.ActivationKey); return(Ok(new { message = "Account was activated" })); } catch (Exception e) { return(NotFound(new { message = e.Message })); } }
public async Task <IActionResult> Activate(string id) { if (!ModelState.IsValid) { return(BadRequest()); } await _userService.ActivateAsync(new ManageUserCommand { Id = id }); return(Ok(ResponseDto.Default)); }
public async Task HandleAsync(ActivateAccount command) { await _handler .Run(async() => await _userService .ActivateAsync(command.Email, command.Token)) .OnSuccess(async() => { var user = await _userService.GetByEmailAsync(command.Email, Providers.Collectively); await _bus .PublishAsync(new AccountActivated(command.Request.Id, command.Email, user.Value.UserId)); }) .OnCustomError(async ex => await _bus .PublishAsync(new ActivateAccountRejected(command.Request.Id, command.Email, ex.Code, ex.Message))) .OnError(async(ex, logger) => { logger.Error(ex, "Error when activating account."); await _bus.PublishAsync(new ActivateAccountRejected(command.Request.Id, command.Email, OperationCodes.Error, "Error when activating account")); }) .ExecuteAsync(); }
public override async Task <ActionReplay> Activate(TokenModel request, ServerCallContext context) { var response = await _userService.ActivateAsync(request.Token); return(response.ToActionReplay()); }
public async Task <IActionResult> Activate(string activationToken) { var response = await _userService.ActivateAsync(activationToken); return(GenerateResult(response)); }