public ActionResult <AccountsReadDto> CreateAccount(AccountsCreateDto accountCreateDto) { var userExists = _repository.GetAllAccounts().Any(p => p.Email == accountCreateDto.Email); if (userExists) { return(BadRequest(new { message = "Email is currently being used" })); } var modifiedData = new AccountsCreateDto { FirstName = accountCreateDto.FirstName.ToUpper(), PhotoFileName = accountCreateDto.PhotoFileName, AuthId = 2, Email = accountCreateDto.Email.ToLower(), LastName = accountCreateDto.LastName.ToUpper(), MiddleName = accountCreateDto.MiddleName.ToUpper(), Password = _userService.HashPassword("123"), ResetToken = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(DateTime.Now.ToString("yyyyMMddHHmmssfff"))) }; var accountModel = _mapper.Map <Account>(modifiedData); _repository.CreateAccount(accountModel); _repository.SaveChanges(); var accountsReadDto = _mapper.Map <AccountsReadDto>(accountModel); return(CreatedAtRoute(nameof(GetAccountsById), new { Id = accountsReadDto.Id }, accountsReadDto)); }
public IActionResult ForgotPassword(ForgotPassDto model) { var user = _accRepo.GetAccountByEmail(model.Email); //EmailConfig SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential("*****@*****.**", "abcdEcosystem123"); MailMessage msg = new MailMessage(); //Token config var Token = Guid.NewGuid().ToString(); var encodedToken = _authRepo.TokenConfig(Token); if (user != null) { //Adding table data to db var modifiedData = _authRepo.AddToken(Token, user); if (user == null) { return(NotFound()); } _mapper.Map(modifiedData, user); _accRepo.UpdateAccount(user); _accRepo.SaveChanges(); //Sending Email with query parameters string url = $"{_configuration["ClientAppUrl"]}/resetpassword?email={model.Email}&token={encodedToken}"; msg.To.Add(model.Email); msg.From = new MailAddress("UST Eco-Tigers <*****@*****.**>"); msg.Subject = "Password Reset Url"; msg.Body = url; client.Send(msg); return(Ok()); } return(BadRequest()); }