Ejemplo n.º 1
0
        public async Task <bool> SendConfirmationEmail(string confirmEmail, string userId, string confirmCode)
        {
            _logger.LogInformation("Sending confirmation email");

            if (string.IsNullOrWhiteSpace(confirmEmail))
            {
                _logger.LogWarning("Missing parameter {Parameter}, confirmation email not sent", nameof(confirmEmail));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(userId))
            {
                _logger.LogWarning("Missing parameter {Parameter}, confirmation email not sent", nameof(userId));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(confirmCode))
            {
                _logger.LogWarning("Missing parameter {Parameter}, confirmation email not sent", nameof(confirmCode));
                return(false);
            }

            try
            {
                // Confirm code needs to be url encoded for verification to work
                var encodedConfirmCode = UrlEncoder.Default.Encode(confirmCode);
                var model = new ConfirmationEmailModel()
                {
                    BaseUrl      = _url,
                    Title        = "CoreWiki Email Confirmation",
                    ReturnUrl    = $"{_url}Identity/Account/ConfirmEmail?userId={userId}&code={encodedConfirmCode}",
                    ConfirmEmail = confirmEmail
                };

                var messageBody = await _emailMessageFormatter.FormatEmailMessage(
                    TemplateProvider.ConfirmationEmailTemplate,
                    model);

                return(await _emailNotifier.SendEmailAsync(
                           confirmEmail,
                           "Please confirm your email address",
                           messageBody));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
#if DEBUG
                throw;
#else
                return(false);
#endif
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> NotifyAuthorNewComment(CoreOdinUser author, Article article, Comment comment)
        {
            if (!author.CanNotify)
            {
                return(false);
            }
            if (string.IsNullOrWhiteSpace(author.Email))
            {
                return(false);
            }

            var model = new
            {
                AuthorName         = author.UserName,
                Title              = "Odin Notification",
                CommentDisplayName = comment.DisplayName,
                ArticleTitle       = article.Topic,
                ArticleUrl         = GetUrlForArticle(article)
            };
            var messageBody = await _emailMessageFormatter.FormatEmailMessage("NewComment", model);

            return(await _emailNotifier.SendEmailAsync(author.Email, "Someone said something about your article", messageBody));
        }