コード例 #1
0
        public async Task SendPasswordChangedNotification(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var options = _userAreaDefinitionRepository.GetOptionsByCode(user.UserAreaCode).Password;

            if (!options.SendNotificationOnUpdate)
            {
                return;
            }

            var userSummary         = _userSummaryMapper.Map(user);
            var context             = _userMailTemplateBuilderContextFactory.CreatePasswordChangedContext(userSummary);
            var mailTemplateBuilder = _userMailTemplateBuilderFactory.Create(user.UserAreaCode);
            var mailTemplate        = await mailTemplateBuilder.BuildPasswordChangedTemplateAsync(context);

            // Null template means don't send a notification
            if (mailTemplate == null)
            {
                return;
            }

            await _mailService.SendAsync(user.Email, mailTemplate);
        }
コード例 #2
0
        private async Task SendNotificationAsync(User user, string temporaryPassword, IExecutionContext executionContext)
        {
            var userSummary         = _userSummaryMapper.Map(user);
            var context             = _userMailTemplateBuilderContextFactory.CreatePasswordResetContext(userSummary, temporaryPassword);
            var mailTemplateBuilder = _userMailTemplateBuilderFactory.Create(user.UserAreaCode);
            var mailTemplate        = await mailTemplateBuilder.BuildPasswordResetTemplateAsync(context);

            // Null template means don't send a notification
            if (mailTemplate == null)
            {
                return;
            }

            await _mailService.SendAsync(user.Email, mailTemplate);
        }
        private async Task <string> SendNotificationAsync(
            AddAuthorizedTaskCommand addAuthorizedTaskCommand,
            UserSummary user
            )
        {
            var context             = _userMailTemplateBuilderContextFactory.CreateAccountRecoveryContext(user, addAuthorizedTaskCommand.OutputToken);
            var mailTemplateBuilder = _userMailTemplateBuilderFactory.Create(user.UserArea.UserAreaCode);
            var mailTemplate        = await mailTemplateBuilder.BuildAccountRecoveryTemplateAsync(context);

            // Null template means don't send a notification
            if (mailTemplate != null)
            {
                await _mailService.SendAsync(user.Email, mailTemplate);
            }

            return(context.Token);
        }
        private async Task SendNotificationAsync(AddUserCommand newUserCommand, IExecutionContext executionContext)
        {
            var query = new GetUserSummaryByIdQuery(newUserCommand.OutputUserId);
            var user  = await _queryExecutor.ExecuteAsync(query, executionContext);

            EntityNotFoundException.ThrowIfNull(user, newUserCommand.OutputUserId);

            // Send mail notification
            var context             = _userMailTemplateBuilderContextFactory.CreateNewUserWithTemporaryPasswordContext(user, newUserCommand.Password);
            var mailTemplateBuilder = _userMailTemplateBuilderFactory.Create(newUserCommand.UserAreaCode);
            var mailTemplate        = await mailTemplateBuilder.BuildNewUserWithTemporaryPasswordTemplateAsync(context);

            // Null template means don't send a notification
            if (mailTemplate == null)
            {
                return;
            }

            await _mailService.SendAsync(newUserCommand.Email, mailTemplate);
        }