public ActionResult Login(string userName, string userPassword) { IUserFacade userFacade = FacadeRepository.GetUserFacade(); SecurityUser securityUser = null; try { securityUser = userFacade.Authenticate(userName, userPassword); } catch (System.Threading.ThreadAbortException se) { ViewBag.Message = se.Message; } catch (SecurityException se) { ViewBag.Message = se.Message; } catch (Exception ex) { ViewBag.Message = ex.Message; } if (securityUser != null) { SecurityManager.CurrentUser = securityUser; Session[Constants.UserID] = securityUser.UserId; Session[Constants.RoleID] = securityUser.RoleId; Session[Constants.PermissionString] = securityUser.UserPermission; Session[Constants.Name] = securityUser.Name; UserName = securityUser.Name; if (Request.QueryString["ReturnUrl"] != null) { FormsAuthentication.RedirectFromLoginPage(userName, false); } else { FormsAuthentication.SetAuthCookie(userName, false); } if (!securityUser.MustChangePassword) { return(RedirectToAction("Index", "Home")); } else { Response.Redirect("User/ChangePassword.aspx?Id=" + securityUser.UserId + "&Pass="******"&Delete=True", false); } } else { ViewBag.WrongCredentials = "Username or password is incorrect."; } return(View()); }
public void ResetUserPassword(String userId) { ViewBag.Error = string.Empty; if (String.IsNullOrEmpty(userId)) { ViewBag.Error = "User ID is mandatory"; return; } //Attempt to get new password for user var newPassword = FacadeRepository.GetUserFacade().ResetPassword(new Total.DealerCom.Core.User { Id = userId }); if (newPassword != string.Empty) { //Attempting to email the new password to the user var email = FacadeRepository.GetUserFacade().SendUserPassword(newPassword, new Total.DealerCom.Core.User { Id = userId }); ViewBag.Status = "Password sent to email address: " + email; } else { throw new Exception("Password reset failed."); } }
public void LoginUser(string userName, string userPassword) { IUserFacade userFacade = FacadeRepository.GetUserFacade(); lblMessage.Text = string.Empty; SecurityUser securityUser = null; try { securityUser = userFacade.Authenticate(userName, userPassword); } catch (System.Threading.ThreadAbortException se) { lblMessage.Text = se.Message; } catch (SecurityException se) { lblMessage.Text = se.Message; } catch (Exception ex) { lblMessage.Text = ex.Message; } if (securityUser != null) { SecurityManager.CurrentUser = securityUser; Session[Constants.UserID] = securityUser.UserId; Session[Constants.RoleID] = securityUser.RoleId; Session[Constants.PermissionString] = securityUser.UserPermission; Session[Constants.Name] = securityUser.Name; if (Request.QueryString["ReturnUrl"] != null) { FormsAuthentication.RedirectFromLoginPage(userName, false); } else { FormsAuthentication.SetAuthCookie(userName, false); } if (!securityUser.MustChangePassword) { Response.Redirect("~/Welcome.aspx", false); Response.Redirect("~/WebForms/Admin/User/Search.aspx", false); } else { Response.Redirect("User/ChangePassword.aspx?Id=" + securityUser.UserId + "&Pass="******"&Delete=True", false); } } }
public void ChangePassword(String userIdreset, String oldPassword, String newPassword, String confirmPassword) { //Attempt to get new password for user ViewBag.Error = string.Empty; if (String.IsNullOrEmpty(userIdreset)) { ViewBag.Error = "User ID is mandatory"; return; } if (String.IsNullOrEmpty(oldPassword)) { ViewBag.Error = "Old Password is mandatory"; return; } if (String.IsNullOrEmpty(newPassword)) { ViewBag.Error = "New Password is mandatory"; return; } if (newPassword != confirmPassword) { ViewBag.Error = "New password not correctly confirmed."; return; } var dataRow = FacadeRepository.GetUserFacade().UpdatePassword(new Total.DealerCom.Core.User { Id = userIdreset, OldPassword = oldPassword, NewPassword = newPassword }); ViewBag.StatusMessage = dataRow == null ? "Password change failed." : "Password change successful."; userIdreset = string.Empty; confirmPassword = string.Empty; oldPassword = string.Empty; newPassword = string.Empty; }