public async Task <ActionResult <NotificationDto> > SendSms(
            SmsNotificationDto dto,
            CancellationToken cancellationToken)
        {
            SmsNotification smsNotification;
            var             eventFilter = await GetEventParticipantFilterAsync(dto, cancellationToken);

            if (eventFilter != null)
            {
                smsNotification = await _notificationManagementService
                                  .CreateSmsNotificationForEventAsync(
                    dto.Message,
                    eventFilter.EventId.Value,
                    eventFilter.ProductId,
                    eventFilter.RegistrationStatuses,
                    eventFilter.RegistrationTypes);
            }
            else
            {
                smsNotification = await _notificationManagementService
                                  .CreateSmsNotificationAsync(
                    dto.Message,
                    dto.Recipients);
            }

            // send notification right away, not queueing it or something.
            // TODO: use queue for messages

            await _notificationDeliveryService
            .SendNotificationAsync(smsNotification, cancellationToken);

            return(Ok(new NotificationDto(smsNotification)));
        }
Example #2
0
        private async Task NotifyUserWithSms(ApplicationUser user)
        {
            var token = await _userManager.GenerateTwoFactorTokenAsync(user, TokenOptions.DefaultPhoneProvider);

            _logger.LogInformation("Generate one time password: {Token} for user with id: {UserId}", token, user.Id);
            var notificationDto = new SmsNotificationDto
            {
                PhoneNumbers = new List <string> {
                    user.PhoneNumber
                },
                NotificationType = NotificationType.RmAuthOtp,
                Content          = $"One time password: {token}"
            };
            await _smsUserNotifier.NotifyAsync(notificationDto);
        }
        public Task ApproveUserRegistrationByIdAsync(string id)
        {
            var user = _uow.UserRepository.GetById(id);

            user.AccountStatus = AccountStatus.Approved;
            _uow.Save();

            var notification = new SmsNotificationDto
            {
                Content          = "Your registration was successful",
                NotificationType = NotificationType.RmRegistrationApproved,
                PhoneNumbers     = new[] { user.PhoneNumber }
            };

            return(_smsUserNotifier.NotifyAsync(notification));
        }
        // GET: /Manage/VerifyPhoneNumber
        public async Task <ActionResult> VerifyPhoneNumber(string phoneNumber)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user   = await _userManager.FindByIdAsync(userId);

            var code = await _userManager.GenerateChangePhoneNumberTokenAsync(user, phoneNumber);

            _logger.LogInformation("Generate one time password: {Code} for user with id: {UserId}", code, user.Id);
            if (_smsUserNotifier != null)
            {
                var userNotificationDto = new SmsNotificationDto()
                {
                    PhoneNumbers = new List <string> {
                        phoneNumber
                    },
                    Content = "Your security code is: " + code
                };
                await _smsUserNotifier.NotifyAsync(userNotificationDto);
            }
            return(phoneNumber == null?View("Error") : View(new VerifyPhoneNumberViewModel {
                PhoneNumber = phoneNumber
            }));
        }