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);
        }
Exemple #2
0
        public async Task <UserSummary> ExecuteAsync(GetUserSummaryByIdQuery query, IExecutionContext executionContext)
        {
            var dbResult = await Query(query).SingleOrDefaultAsync();

            var user = _userSummaryMapper.Map(dbResult);

            ValidatePermission(query, executionContext, user);

            return(user);
        }
        private async Task <UserSummary> GetUserAsync(InitiateUserAccountRecoveryViaEmailCommand command)
        {
            var username = _userDataFormatter.UniquifyUsername(command.UserAreaCode, command.Username);
            var dbUser   = await _dbContext
                           .Users
                           .Include(u => u.Role)
                           .FilterByUserArea(command.UserAreaCode)
                           .FilterCanSignIn()
                           .SingleOrDefaultAsync(u => u.Username == username);

            var user = _userSummaryMapper.Map(dbUser);

            return(user);
        }
        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);
        }
        public async Task <UserSummary> ExecuteAsync(GetUserSummaryByIdQuery query, IExecutionContext executionContext)
        {
            var dbResult = await _dbContext
                           .Users
                           .AsNoTracking()
                           .IncludeForSummary()
                           .FilterById(query.UserId)
                           .SingleOrDefaultAsync();

            var user = _userSummaryMapper.Map(dbResult);

            ValidatePermission(query, executionContext, user);

            return(user);
        }
        private async Task <UserSummary> GetUserAndVerifyAsync(InitiateUserAccountVerificationViaEmailCommand command)
        {
            var dbUser = await _dbContext
                         .Users
                         .AsNoTracking()
                         .IncludeForSummary()
                         .FilterCanSignIn()
                         .FilterById(command.UserId)
                         .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(dbUser, command.UserId);

            if (dbUser.AccountVerifiedDate.HasValue)
            {
                UserValidationErrors.AccountVerification.Initiation.AlreadyVerified.Throw();
            }

            var user = _userSummaryMapper.Map(dbUser);

            return(user);
        }