public async Task <ActionResult <NotificationUnreadModel> > Get(CancellationToken cancellationToken)
        {
            var tenantId = _userClaimManager.GetTenantId(User) ?? Guid.Empty;
            var userName = User.Identity.Name;

            var command = new NotificationUnreadQuery(User, userName, tenantId);
            var result  = await Mediator.Send(command, cancellationToken);

            return(Ok(result));
        }
示例#2
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);
        }
示例#4
0
 private Guid?GetTenantId(LinkTokenCreateCommand request)
 {
     return(request.Model.TenantId ??
            _userClaimManager.GetTenantId(request.Principal));
 }