public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { // ChangePassword will throw an exception rather // than return false in certain failure scenarios. bool changePasswordSucceeded; try { var account = new AccountManagement(); changePasswordSucceeded = account.ChangePasswordForUser(User.Identity.Name, model.OldPassword, model.NewPassword); } catch (Exception) { changePasswordSucceeded = false; } if (changePasswordSucceeded) { return RedirectToAction("ChangePasswordSuccess"); } else { ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); } } // If we got this far, something failed, redisplay form return View(model); }
protected override void OnActionExecuting(ActionExecutingContext ctx) { base.OnActionExecuting(ctx); _cartService.StartCart(ctx.HttpContext); var account = new AccountManagement(); ViewBag.UserRole = account.IsInRole(User.Identity.Name, "Customer") ? "Customer" : "none"; }
public ActionResult LogOff() { var account = new AccountManagement(); account.SignOff(); return RedirectToAction("Index", "Home"); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; var account = new AccountManagement(); var customer = new Customer { Username = model.UserName, Password = model.Password, Email = model.Email, Enabled = true, FirstName = model.FirstName, LastName = model.LastName, Role = "Customer" }; account.CreateUser(customer, out createStatus); if (createStatus == MembershipCreateStatus.Success) { //migrate cart if exists _cartService.StartCart(this.HttpContext).MigrateCart(model.UserName); FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { var account = new AccountManagement(); if (account.ValidateUser(model.UserName, model.Password)) { //migrate cart if exists _cartService.StartCart(this.HttpContext).MigrateCart(model.UserName); account.Authorize(model.UserName,model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); }