public ActionResult UserLogin(LoginDTO model) { if (ModelState.IsValid) { UserAccountStatus loginStatus = UserAccountStatus.NotSet; using (var client = new HttpClient()) { client.BaseAddress = new Uri(value); var validateUserTask = client.GetAsync("User/ValidateUser?username="******"&password="******"Password", "Incorrect username or password, please try again."); break; case UserAccountStatus.LockedOut: ModelState.AddModelError("Password", "Your account has been locked out because of too many failed login attempts. Please contact the administrator to have your account unlocked."); break; case UserAccountStatus.Inactive: ModelState.AddModelError("Password", "Your account is currently inactive, please contact your administrator for any further questions regarding this account."); break; case UserAccountStatus.InactiveEmployer: ModelState.AddModelError("Password", "Your employer account is currently inactive, please contact your administrator for any further questions regarding this account."); break; case UserAccountStatus.AccountNotFound: ModelState.AddModelError("UserName", "Incorrect username or password, please try again."); break; case UserAccountStatus.Success: { result = null; var userinfo = client.GetAsync("User/GetUserByEmail?email=" + model.UserName); userinfo.Wait(); result = userinfo.Result; if (result.IsSuccessStatusCode) { var readUserDTOTask = result.Content.ReadAsAsync <UserSecurityToken>(); readUserDTOTask.Wait(); UserSecurityToken userSecurityToken = readUserDTOTask.Result; Session["CurrentUser"] = userSecurityToken; if (Session["MasterData"] == null) { Session["MasterData"] = new AdminController().ReadMasterData(MasterDataType.None); } // if (Session["SupplierList"] == null) // Session["SupplierList"] = new AdminController().GetSupplierList(); if (userSecurityToken != null) { if (userSecurityToken.Role.Guid == RoleType.Admin.Guid) { return(RedirectToAction("Index", "Admin")); } } } break; } } } } } else { } return(View(model)); }
public ActionResult ChangePassword(ForgotPasswordModel password) { try { if (Session["CurrentUser"] != null) { UserSecurityToken currentUser = (UserSecurityToken)Session["CurrentUser"]; password.UserName = currentUser.Email; if (ModelState.ContainsKey("UserName")) { ModelState.Remove("UserName"); } if (ModelState.ContainsKey("Password")) { ModelState.Remove("Password"); } if (ModelState.ContainsKey("UserID")) { ModelState.Remove("UserID"); } if (ModelState.IsValid) { bool success = false; using (var client = new HttpClient()) { client.BaseAddress = new Uri(value); var responseTask1 = client.GetAsync(string.Format("User/ChangePassword?userName={0}¤tPassword={1}&newPassword={2}&confirmPassword={3}", password.UserName, password.OldPassword, password.NewPassword, password.NewPasswordConfirm)); responseTask1.Wait(); var result = responseTask1.Result; if (result.IsSuccessStatusCode) { var changepasswordTask = result.Content.ReadAsAsync <bool>(); changepasswordTask.Wait(); success = changepasswordTask.Result; if (success) { switch (currentUser.Role.Name) { case "Admin": return(RedirectToAction("Index", "Admin")); } } } ModelState.AddModelError("NewPassword", "Password was not changed. Please try again."); return(View(password)); } } return(View(password)); } return(RedirectToAction("UserLogin", "Account")); } catch { ModelState.AddModelError("NewPassword", "New password must be at least 8 characters long. Please try again."); return(View(password)); } }