public ActionResult AddUser(Models.Account.User user) { bool isEmailError = false; try { user.Password = CreateTempPassword(8); user.NewPassword = user.Password; user.Guid = Guid.NewGuid(); // all users are Admins user.IsAdmin = true; if (_db.AddUser(user)) { isEmailError = true; Logger.Log(LogLevel.Info, "User has been created [email = " + user.Email + "], requested by " + User.Identity.Name); string urlAuthority = Request.Url.GetLeftPart(UriPartial.Authority); var smtp = new SmtpMail(); smtp.SendPasswordResetEmail(user, urlAuthority); isEmailError = false; return RedirectToAction("ManageUsers", "Admin"); } else { ModelState.AddModelError("Error", ResourceCache.Localize("duplicate_user_msg")); Logger.Log(LogLevel.Error, "Error in AddUser: duplicate user [email = " + user.Email + "], requested by " + User.Identity.Name); } } catch (Exception e) { if (isEmailError) { ModelState.AddModelError("Error", ResourceCache.Localize("email_error_msg")); } else { ModelState.AddModelError("Error", ResourceCache.Localize("error_msg")); } Logger.Log(LogLevel.Error, "Error in AddUser [email = " + user.Email + "], requested by " + User.Identity.Name + ": " + e.Message); } return View(user); }
public ActionResult _requestResetPassword(string userId) { string outcome = "success"; string message = string.Empty; long id = 0; long.TryParse(userId, out id); var model = _db.GetUser(id); model.NewPassword = CreateTempPassword(8); try { if (_db.ResetPassword(model)) { string urlAuthority = Request.Url.GetLeftPart(UriPartial.Authority); var smtp = new SmtpMail(); smtp.SendPasswordResetEmail(model, urlAuthority); TempData["Email"] = model.Email; Logger.Log(LogLevel.Info, "Password has been reset [user name = " + model.UserName + "], requested by " + User.Identity.Name); } else { outcome = "error"; Logger.Log(LogLevel.Error, "Reset Password failed [user name = " + model.UserName + "], requested by " + User.Identity.Name); } } catch (Exception e) { outcome = "error"; Logger.Log(LogLevel.Error, "Error in _requestResetPassword [user name = " + model.UserName + "], requested by " + User.Identity.Name + ": " + e.Message); } return Json(new { result = outcome, message = message }, JsonRequestBehavior.AllowGet); }
public ActionResult ResetPassword(Models.Account.User model) { model.NewPassword = CreateTempPassword(8); try { if (_db.ResetPassword(model)) { Logger.Log(LogLevel.Info, "Password has been reset [user name = " + model.UserName + "]"); string urlAuthority = Request.Url.GetLeftPart(UriPartial.Authority); var smtp = new SmtpMail(); smtp.SendPasswordResetEmail(model, urlAuthority); TempData["EmailSent"] = bool.TrueString; } else { TempData["EmailSent"] = bool.FalseString; Logger.Log(LogLevel.Error, "Password was not reset [user name = " + model.UserName + "]"); } return RedirectToAction("ResetPasswordConfirmation"); } catch (Exception e) { ModelState.AddModelError("Error", ResourceCache.Localize("ui_request_not_processed")); Logger.Log(LogLevel.Error, "Error in ResetPassword [user name = " + model.UserName + "]: " + e.Message); } return View(); }