Beispiel #1
0
        private async Task SendRecipientLinkEmail(UserLinkModel userLinkModel, IPrincipal principal, string recipient, CancellationToken cancellationToken)
        {
            // lookup user
            var recipientUser = await _userManager.FindByEmailAsync(recipient);

            if (recipientUser == null)
            {
                Logger.LogError("Recipient '{recipient}' not found, can't send email", recipient);
                return;
            }

            // create user link
            var createModel = new LinkTokenCreateModel
            {
                Expires  = DateTimeOffset.UtcNow.AddMonths(1),
                Url      = userLinkModel.LinkUrl,
                UserName = recipientUser.UserName,
                TenantId = _userClaimManager.GetTenantId(principal)
            };

            // create user token
            var token         = _userManager.GenerateNewAuthenticatorKey();
            var createCommand = new LinkTokenCreateCommand(principal, createModel, token);
            var linkToken     = await Mediator.Send(createCommand, cancellationToken).ConfigureAwait(false);

            var scheme = _urlHelper.ActionContext?.HttpContext?.Request?.Scheme ?? "http";

            // create link to send in email
            var emailLink = _urlHelper.Page(
                "/Account/Link",
                pageHandler: null,
                values: new { token },
                protocol: scheme);

            // create email model
            var email = new UserLinkEmail
            {
                RecipientName    = recipientUser.DisplayName,
                RecipientAddress = recipientUser.Email,
                ReplyToName      = userLinkModel.ReplyToName,
                ReplyToAddress   = userLinkModel.ReplyToAddress,
                Subject          = userLinkModel.Subject,
                TextBody         = userLinkModel.TextBody,
                HtmlBody         = userLinkModel.HtmlBody,
                LinkUrl          = emailLink,
                LinkText         = userLinkModel.LinkText
            };

            Logger.LogInformation("Sending user link email to '{recipient}'", recipient);

            await EmailTemplate.SendUserLinkEmail(email).ConfigureAwait(false);
        }
        private async Task CreateLinkToken(User user, string token, string returnUrl, IPrincipal principal)
        {
            var createModel = new LinkTokenCreateModel
            {
                Expires  = DateTimeOffset.UtcNow.Add(TimeSpan.FromDays(30)),
                Url      = returnUrl,
                UserName = user.UserName,
                TenantId = _userClaimManager.GetTenantId(principal),
            };

            var createCommand = new LinkTokenCreateCommand(principal, createModel, token);
            var linkToken     = await Mediator.Send(createCommand);
        }
Beispiel #3
0
        private async Task CreateLinkToken(Core.Data.Entities.User user, string token)
        {
            var createModel = new LinkTokenCreateModel
            {
                Expires  = DateTimeOffset.UtcNow.Add(_securityOptions.Value.PasswordlessTokenLifespan),
                Url      = ReturnUrl,
                UserName = user.UserName,
                TenantId = user.LastTenantId
            };

            var createCommand = new LinkTokenCreateCommand(User, createModel, token);
            var linkToken     = await _mediator.Send(createCommand);
        }