Example #1
0
        public async Task AllowUserToLoginAsync(User user, bool allow)
        {
            var identityResult = await _userManager.SetLockoutEnabledAsync(user, !allow);

            if (!identityResult.Succeeded)
            {
                throw new LocalException(identityResult.Errors.First().Description);
            }

            IEvent @event;

            if (allow)
            {
                user = await FindByIdAsync(user.Id);

                @event = new UserUnlockedEvent {
                    User = user
                };
            }
            else
            {
                identityResult = await _userManager.SetLockoutEndDateAsync(user, DateTimeOffset.MaxValue);

                if (!identityResult.Succeeded)
                {
                    throw new LocalException(identityResult.Errors.First().Description);
                }

                user = await FindByIdAsync(user.Id);

                @event = new UserLockedEvent {
                    User = user
                };
            }
            await _domainEvents.RaiseAsync(@event);
        }
Example #2
0
 public async Task HandleAsync(UserUnlockedEvent args)
 {
     await SendNotificationAsync <Guid?, User, UserDto>(args, args.User, args.User.FullName);
 }