public async Task <UserDto> InsertUserAsync(UserDto userDto) { var newPassword = CreatePassword.CreateNewPassword(); await _context.AddAsync(new User() { FirstName = userDto.FirstName, LastName = userDto.LastName, Email = userDto.Email, RightId = userDto.RightId, PictureUrl = userDto.PictureUrl, Active = userDto.Active, CreatedAt = DateTime.Now, Password = CreatePassword.CreateHash(newPassword), Address = userDto.Address, UserFlag = 1 }); var checkInsert = await Complete(); if (!checkInsert) { return(null); } _logger.InsertDatabaseLog(new DataBaseLog() { Type = "Neuer User", Message = $"Neuer User {userDto.FirstName} {userDto.LastName} wurde hinzugefĆ¼gt", CreatedAt = DateTime.Now }); await _serviceRepository.SendNewUserMailAsync(userDto, newPassword); return(userDto); }
public async Task <bool> SendNewPasswordMailAsync(User user) { var newPassword = CreatePassword.CreateNewPassword(); var hashPassword = CreatePassword.CreateHash(newPassword); var content = EmailService.CreateNewPasswordText(newPassword); var message = new Message() { Content = content, Subject = "Neues Password", EmailTo = user.Email, EmailFrom = _emailConfiguration.From, }; var emailMessage = EmailService.CreateEmailMessage(message); var checkMailSend = await SendAsync(emailMessage); if (!checkMailSend) { return(false); } var userToUpdate = await _context.Users.FindAsync(user.Id); userToUpdate.Password = hashPassword; userToUpdate.UserFlag = 1; await _context.SaveChangesAsync(); return(true); }