public JsonResult GetDetalle_Solicitud_Historial_de_Asignaciones_Usuario_Spartan_User(string query, string where) { try { if (String.IsNullOrEmpty(where)) { where = ""; } if (!_tokenManager.GenerateToken()) { return(Json(null, JsonRequestBehavior.AllowGet)); } _ISpartan_UserApiConsumer.SetAuthHeader(_tokenManager.Token); var elWhere = " (cast(Spartan_User.Id_User as nvarchar(max)) LIKE '%" + query.Trim() + "%' or cast(Spartan_User.Name as nvarchar(max)) LIKE '%" + query.Trim() + "%') " + where; elWhere = HttpUtility.UrlEncode(elWhere); var result = _ISpartan_UserApiConsumer.ListaSelAll(1, 20, elWhere, " Spartan_User.Name ASC ").Resource; foreach (var item in result.Spartan_Users) { var trans = CultureHelper.GetTraduction(Convert.ToString(item.Id_User), "Spartan_User", "Name"); item.Name = trans ?? item.Name; } return(Json(result.Spartan_Users.ToArray(), JsonRequestBehavior.AllowGet)); } catch (ServiceException ex) { return(Json(null, JsonRequestBehavior.AllowGet)); } }
public ActionResult Login(LoginViewModel model, string returnUrl = "") { Session["BlockUser"] = null; if (ModelState.ContainsKey("LanguageList")) { ModelState["LanguageList"].Errors.Clear(); } if (ModelState.IsValid) { string passwordEncripted = EncryptHelper.CalculateMD5Hash(model.Password); if (!_tokenManager.GenerateToken(model.UserName, passwordEncripted)) { ModelState.AddModelError("", Resources.LoginResources.InvalidUserPassword); if (SessionHelper.Relogin) { return(Json(Resources.LoginResources.InvalidUserPassword)); } } _ISpartan_SettingsApiConsumer.SetAuthHeader(_tokenManager.Token); var FailedAttemptDB = _ISpartan_SettingsApiConsumer.GetByKey("FailedAttempts", false).Resource; int FailedAttempts = Convert.ToInt32(FailedAttemptDB.Valor); model.MaxFailedAttempts = FailedAttempts; if (Session["UserName"] != null && Session["UserName"].ToString() != model.UserName) { model.FailedAttempts = 1; } Session["UserName"] = model.UserName; _IUseroApiConsumer.SetAuthHeader(_tokenManager.Token); Spartan_Security_Log oSecurityLog = new Spartan_Security_Log(); var UsersByName = _IUseroApiConsumer.ListaSelAll(0, 10, "Spartan_User.Username = '******'", "").Resource; if (UsersByName.RowCount == 0) { ModelState.AddModelError("", Resources.LoginResources.InvalidUserPassword); model.LanguageList = GetLanguage(); SessionHelper.Relogin = false; return(View(model)); } // Call Validate User API for user Exists in application Spartan_User_Core UserDetails = _IUseroApiConsumer.ValidateUser(1, 10, "Username = '******' COLLATE SQL_Latin1_General_CP1_CS_AS And Password = '******' COLLATE SQL_Latin1_General_CP1_CS_AS").Resource; if (UserDetails.Spartan_Users != null && UserDetails.Spartan_Users.Count() > 0) { if (UserDetails.Spartan_Users[0].Status == 1) { var spartan_user = new Core.Domain.Spartan_User.Spartan_User { Id_User = UserDetails.Spartan_Users[0].Id_User, Name = UserDetails.Spartan_Users[0].Name, Password = UserDetails.Spartan_Users[0].Password }; TTUsuario user = new TTUsuario { IdUsuario = Convert.ToInt16(UserDetails.Spartan_Users[0].Id_User), Nombre = Convert.ToString(UserDetails.Spartan_Users[0].Name), Clave_de_Acceso = UserDetails.Spartan_Users[0].Username, //Activo = UserDetails.Spartan_Users[0].Status }; SetSecurityLogging(ref oSecurityLog, (short)Event_Type.Login, UserDetails.Spartan_Users[0].Id_User, UserDetails.Spartan_Users[0].Role, (short)Result_Type.Granted); int SecurityLogId = _ISpartanSecurityApiConsumer.Insert(oSecurityLog).Resource; SetAuthentication(UserDetails); //_authenticationService.SignIn(user, model.RememberMe); //Adding user Core entity Data SessionHelper.UserEntity = UserDetails.Spartan_Users[0]; //Getting User Image _ISpartane_FileApiConsumer.SetAuthHeader(_tokenManager.Token); var userImage = _ISpartane_FileApiConsumer.GetByKey(Convert.ToInt32(UserDetails.Spartan_Users[0].Image)) .Resource; if (userImage != null && userImage.File != null) { SessionHelper.UserImage = userImage.File; } Response.Cookies["UserSettings"]["SecurityLogId"] = SecurityLogId.ToString(); Spartan_Session_Log oSessionLog = new Spartan_Session_Log(); SetSessionLogging(ref oSessionLog, (short)Event_Type.Login, (short)Event_Type.Login, SecurityLogId, UserDetails.Spartan_Users[0].Id_User, UserDetails.Spartan_Users[0].Role, (short)Result_Type.Granted); _ISpartanSessionApiConsumer.Insert(oSessionLog); //Saving Credentials SessionHelper.UserCredential = new Spartane_Credential { Password = EncryptHelper.CalculateMD5Hash(model.Password), UserName = model.UserName, }; // save role id in session SessionHelper.Role = UserDetails.Spartan_Users[0].Role; // save role object in session SessionHelper.Sprtan_Role = new RoleSpartanUserRole { Id = UserDetails.Spartan_Users[0].Role_Spartan_User_Role.Id, Description = UserDetails.Spartan_Users[0].Role_Spartan_User_Role.Description, Status = UserDetails.Spartan_Users[0].Role_Spartan_User_Role.Status, Status_Spartan_User_Role_Status = UserDetails.Spartan_Users[0].Role_Spartan_User_Role.Status_Spartan_User_Role_Status, User_Role_Id = UserDetails.Spartan_Users[0].Role_Spartan_User_Role.User_Role_Id, }; Session["USERID"] = user.IdUsuario; Session["USERROLEID"] = UserDetails.Spartan_Users[0].Role_Spartan_User_Role.User_Role_Id; Session.Timeout = Convert.ToInt32(ConfigurationManager.AppSettings["SessionTimeOut"]); Session["LANGUAGEID"] = (model.SelectedLanguage.HasValue) ? model.SelectedLanguage.Value : 1; SessionHelper.Relogin = false; return(RedirectToLocal("~/Frontal/Home/Index")); } else { SetSecurityLogging(ref oSecurityLog, (short)Event_Type.Login, null, null, (short)Result_Type.Denied); _ISpartanSecurityApiConsumer.Insert(oSecurityLog); ModelState.AddModelError("", Resources.LoginResources.DeactivateAccount); if (SessionHelper.Relogin) { return(Json(Resources.LoginResources.DeactivateAccount)); } } } else { SetSecurityLogging(ref oSecurityLog, (short)Event_Type.Login, null, null, (short)Result_Type.Denied); _ISpartanSecurityApiConsumer.Insert(oSecurityLog); ModelState.AddModelError("", Resources.LoginResources.InvalidUserPassword); if (model.FailedAttempts < model.MaxFailedAttempts) { model.FailedAttempts = model.FailedAttempts + 1; } else { if (UsersByName.RowCount == 1) { var UserByName = UsersByName.Spartan_Users.First(); UserByName.Status = 2; int status = _IUseroApiConsumer.Update(UserByName, null, null).Resource; model.FailedAttempts = 1; } Session["BlockUser"] = true; } if (SessionHelper.Relogin) { return(Json(Resources.LoginResources.InvalidUserPassword)); } } } model.LanguageList = GetLanguage(); // If we got this far, something failed, redisplay form return(View(model)); }