public ActionResult ForgetPassword([FromBody] ForgetPasswordRequest request) { var control = userRepo.FirstOrDefaultBy(x => x.Username == request.Username && x.Email == request.Email); string Email = request.Email; var response = new BaseResponse <bool>(); if (control == null) { response.SetMessage("Sistemde kayıtlı böyle bir kullanıcı bulunamadı."); return(Ok(response)); } var forgotPassword = new ForgatPassword(); forgotPassword.UserID = control.Id; forgotPassword.Key = Cryptography.GenerateKey(32); forgatPasswordRepo.Add(forgotPassword); var Recipients = new Dictionary <string, string>(); Recipients.Add("recipient.Email", Email); Recipients.Add("recipient.FullName", control.FirstName + " " + control.LastName); Recipients.Add("recipient.IPAddress", accessor.HttpContext.Connection.RemoteIpAddress.ToString()); Recipients.Add("recipient.Date", DateTime.Now.ToString("dd MMM yyyy, dddd HH:mm")); Recipients.Add("recipient.Link", $"{accessor.HttpContext.Request.Scheme}://{accessor.HttpContext.Request.Host}/Login/RePassword?q=" + forgotPassword.Key); mailManager.Send("Şifrenizi Sıfırlayın", Email, "forgot-password-en.html", Recipients, null); response.Message = "Email Gönderildi"; return(Ok(response)); }
public virtual void OnException(ExceptionContext context) { var responseModel = new ApiResponseModel(); HttpStatusCode status = HttpStatusCode.InternalServerError; bool sendToAdmin = false; string message = context.Exception.Message; var exceptionType = context.Exception.GetType(); if (exceptionType == typeof(NotAuthorizedForApi)) { responseModel.Message = "The request isn't authorized to use the api."; status = HttpStatusCode.BadRequest; } else { responseModel.Message = DefaultResource.DefaultError; sendToAdmin = true; } if (_hostingEnvironment.IsProduction() && sendToAdmin) { var email = "*****@*****.**"; var mailContext = new ErrorMailContext { DateTime = DateTime.Now, ErrorType = exceptionType.Name, StackTrace = context.Exception.StackTrace }; var mailMessage = _mailCreator.CreateErrorMessage(mailContext, string.Empty, new List <string> { email }, new List <string> { "*****@*****.**" }); _mailManager.Send(mailMessage, new MailSettings { LocalDomain = "web-tel.ru", Login = email, Password = "******", Port = 587, SMTPServer = "smtp.yandex.ru" }); } var response = context.HttpContext.Response; response.StatusCode = (int)status; response.ContentType = "application/json"; var serializeSettings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; var jsonString = JsonConvert.SerializeObject(responseModel, Formatting.Indented, serializeSettings); response.WriteAsync(jsonString); }
public async Task <IActionResult> SignUp([FromBody] SignUpViewModel model) { var response = new ApiResponseModel(); if (ModelState.IsValid) { try { var user = new IdentityUser { Email = model.Email, UserName = model.Login }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, _appSettings.Value.DatabaseSettings.RoleSettings.UserRole); var message = _authMailCreator.CreateAccountConfirmationMail( new AccountConfirmationMailContext { SignUpViewModel = model, DateTime = DateTime.Now }, _appSettings.Value.MailSettings.Login, model.Email ); _mailManager.Send(message, _appSettings.Value.MailSettings); response.Message = AccountResource.SignUpSuccess; return(Ok(response)); } response.Message = _resourceManager.GetByString(result.Errors.First()?.Code); response.Data = new Dictionary <string, object> { { "errors", result.Errors } }; } catch (Exception e) { response.Message = _resourceManager.GetByException(e); } } else { response.Message = AccountResource.IncorrectDataIsInputed; } return(BadRequest(response)); }
public void Send(string to, string subject, string body, bool isHtml = false) { mailer?.Send(to, subject, body, isHtml); }