public async Task <ActionResult> CreateMailTransport()
        {
            var mailTransport = new MailNotificationTransport
            {
                UserId    = User.Identity.GetUserId(),
                IsEnabled = true,
                IsDeleted = false,
            };
            await notificationsRepo.AddNotificationTransport(mailTransport);

            return(RedirectToAction("Manage", "Account"));
        }
示例#2
0
        private async Task Send(MailNotificationTransport transport, List <NotificationDelivery> notificationDeliveries)
        {
            if (string.IsNullOrEmpty(transport.User.Email))
            {
                return;
            }

            if (notificationDeliveries.Count <= 0)
            {
                return;
            }

            var firstDelivery = notificationDeliveries[0];
            var subject       = firstDelivery.Notification.GetNotificationType().GetGroupName();

            var htmlBodies = new List <string>();
            var textBodies = new List <string>();

            foreach (var delivery in notificationDeliveries)
            {
                var notification = delivery.Notification;
                var course       = await courseManager.GetCourseAsync(notification.CourseId);

                var htmlMessage = notification.GetHtmlMessageForDelivery(transport, delivery, course, baseUrl);
                var textMessage = notification.GetTextMessageForDelivery(transport, delivery, course, baseUrl);
                var button      = notification.GetNotificationButton(transport, delivery, course, baseUrl);
                if (button != null)
                {
                    htmlMessage += $"<br/><br/><a href=\"{button.Link.EscapeHtml()}\">{button.Text.EscapeHtml()}</a>";
                    textMessage += $"\n\n{button.Text}: {button.Link}";
                }

                htmlBodies.Add(htmlMessage);
                textBodies.Add(textMessage);
            }

            await emailSender.SendEmailAsync(
                transport.User.Email,
                subject,
                string.Join("\n\n", textBodies),
                string.Join("<br/><br/>", htmlBodies),
                textContentAfterButton : GetEmailTextSignature(),
                htmlContentAfterButton : GetEmailHtmlSignature(firstDelivery)
                );
        }
        public ActionResult SuggestMailTransport()
        {
            if (!User.HasAccess(CourseRole.Instructor))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            var userId    = User.Identity.GetUserId();
            var transport = notificationsRepo.FindUsersNotificationTransport <MailNotificationTransport>(userId, includeDisabled: true);

            if (transport != null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            var user = usersRepo.FindUserById(userId);

            if (user == null)
            {
                return(new HttpNotFoundResult());
            }
            if (string.IsNullOrEmpty(user.Email) || !user.EmailConfirmed)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            var mailNotificationTransport = new MailNotificationTransport
            {
                UserId    = User.Identity.GetUserId(),
                IsEnabled = false,
            };

            AddNotificationTransport(mailNotificationTransport).Wait(5000);

            var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
            var signature = GetNotificationTransportEnablingSignature(mailNotificationTransport.Id, timestamp);

            return(PartialView(new SuggestMailTransportViewModel
            {
                Transport = mailNotificationTransport,
                TelegramBotName = telegramBotName,
                LinkTimestamp = timestamp,
                LinkSignature = signature,
            }));
        }
示例#4
0
        private async Task Send(MailNotificationTransport transport, NotificationDelivery notificationDelivery)
        {
            if (string.IsNullOrEmpty(transport.User.Email))
            {
                return;
            }

            var notification = notificationDelivery.Notification;
            var course       = await courseManager.GetCourseAsync(notification.CourseId);

            var notificationButton = notification.GetNotificationButton(transport, notificationDelivery, course, baseUrl);
            var htmlMessage        = notification.GetHtmlMessageForDelivery(transport, notificationDelivery, course, baseUrl);
            var textMessage        = notification.GetTextMessageForDelivery(transport, notificationDelivery, course, baseUrl);
            await emailSender.SendEmailAsync(
                transport.User.Email,
                notification.GetNotificationType().GetDisplayName(),
                textMessage,
                "<p>" + htmlMessage + "</p>",
                button : notificationButton != null?new EmailButton(notificationButton) : null,
                textContentAfterButton : GetEmailTextSignature(),
                htmlContentAfterButton : GetEmailHtmlSignature(notificationDelivery)
                );
        }
 public async Task AddNotificationTransport(MailNotificationTransport transport)
 {
     await notificationsRepo.AddNotificationTransport(transport).ConfigureAwait(false);
 }