public LoginModel Post(LoginModel user) { if (!string.IsNullOrEmpty(user.UserName) && !string.IsNullOrEmpty(user.Password)) { var service = new Sys_UserServices(); var model = new LoginModel(); var status = string.Empty; var userInfo = service.Login(user.UserName, user.Password,user.GoogleMail,user.GoogleProfileName,user.IsGoogleSign); if (userInfo != null) { var profileInfo = service.GetData<Hre_ProfileEntity>(userInfo.ProfileID, ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault(); model = new LoginModel { UserName = userInfo.UserLogin, Password = userInfo.Password, HasMasterDataGroup = userInfo.HasMasterDataGroup, FullName = profileInfo != null ? profileInfo.ProfileName : string.Empty, UserInfoName = userInfo.UserInfoName, IsActive = userInfo.IsActivate, ProfileID = userInfo.ProfileID, ID = userInfo.ID, IsRunScriptNew = userInfo.IsRunScriptNew, VesionLastName = userInfo.VesionLastName, }; if (userInfo.DateChangePasssword == null) model.IsFirstLogin = true; return model; } } return null; }
/// <summary> Validate login </summary> /// <param name="userName"></param> /// <param name="passwordEncrypt"></param> /// <param name="loginInfo"></param> /// <returns></returns> public bool LoginValidate(string userName, string passwordEncrypt, string googleMail, string googleProfileName, bool isGoogleSign, out LoginModel loginInfo) { var isSuccess = false; loginInfo = new LoginModel { UserName = userName, Password = passwordEncrypt, GoogleMail = googleMail, GoogleProfileName = googleProfileName, IsGoogleSign = isGoogleSign }; var service = new RestServiceClient<LoginModel>(UserLogin); service.SetCookies(this.Request.Cookies, _hrm_Sys_Service); var result = service.Post(_hrm_Sys_Service, "api/Login/", loginInfo); if (result != null) { if (result.IsActive) { isSuccess = true; } loginInfo = result; } return isSuccess; }
//son.vo - tạm thời comment lại do lỗi - 20150528 LoginModel RunScript(LoginModel model) { var service = new RestServiceClient<LoginModel>(UserLogin); service.SetCookies(this.Request.Cookies, _hrm_Sys_Service); var result = service.Put<LoginModel>(_hrm_Sys_Service, "api/Login/", model); return result; }
//[HttpPost] public ActionResult doTestPerformace(TestPerformanceModel model) { LoginModel _LoginModel = new LoginModel(); var userName = model.UserName; var password = model.PassWord; var passwordEncrypt = string.Empty; passwordEncrypt = EncryptUtil.MD5(password);//mã hoá giống bản 7 model.IsSusscess = true; if (LoginValidate(userName, passwordEncrypt, _LoginModel.GoogleMail, _LoginModel.GoogleProfileName, _LoginModel.IsGoogleSign, out _LoginModel)) { model.IsSusscess = true; } else { model.IsSusscess = false; } return Json(model); }
//[HttpPost] public ActionResult CheckLogin(LoginModel model) { //Xử lý user default //Goal(Xử lý login) //Steps : // Step1 : Lấy userName và pass , mã hoá Password (MD5) // Step2 : Login // Step3 : Nếu login thành cong => lưu session #region Tung.Ly : Xử lý login // Lấy UserName var userName = model.UserName; var password = model.Password; var passwordEncrypt = string.Empty; var isSucceed = false; var isRunScriptNew = false; var language = model.Language; //Mã hoá Pass passwordEncrypt = EncryptUtil.MD5(password);//mã hoá giống bản 7 // passwordEncrypt = DataHelper.Encrypt2MD5(password, "!@#"); //Set ngôn ngữ Session[SessionObjects.LanguageCode + userName] = language; VnResource.Helper.Utility.LanguageHelper.LanguageCode = language; //step 2 : login if (LoginValidate(userName, passwordEncrypt, model.GoogleMail, model.GoogleProfileName, model.IsGoogleSign, out model)) { //nếu login thành công TempData[SessionObjects.UserId] = model.ID; Session[SessionObjects.UserId] = model.ID; Session[SessionObjects.LoginUserName] = model.UserName; Session[SessionObjects.FullName] = model.FullName; Session[SessionObjects.UserInfoName] = model.UserInfoName; Session[SessionObjects.ProfileID] = model.ProfileID; Session[SessionObjects.HasMasterDataGroup] = model.HasMasterDataGroup; isSucceed = !model.IsRunScriptNew; isRunScriptNew = model.IsRunScriptNew; } #endregion if (!isSucceed && Common.UserNameSystem == model.UserName && Common.PasswordSystem == password) { Session[SessionObjects.UserId] = Common.UserNameSystem; Session[SessionObjects.LoginUserName] = Common.UserNameSystem; Session[SessionObjects.FullName] = Common.UserNameSystem; Session[SessionObjects.UserInfoName] = Common.UserNameSystem; Session[SessionObjects.ProfileID] = Common.ProfileID; if (model.IsRunScriptNew) model = RunScript(model);// goi ham chay script moi //Session[SessionObjects.UserId] = Common.PasswordSystem; if (model.IsRunScriptNew && model.Execption != null && model.Execption.Count > 0) return Json(new { succeed = true, IsRunScriptNew = model.IsRunScriptNew, Name = model.Name, Execption = model.Execption }); else return Json(new { succeed = true }); } return Json(new { succeed = isSucceed, hasMasterDataGroup = model.HasMasterDataGroup, IsRunScriptNew = isRunScriptNew }); }
public ActionResult Login(LoginModel model) { if (model != null) { if (string.IsNullOrEmpty(model.UserName)) { ModelState.AddModelError("", ConstantDisplay.Hrm_Portal_Login_Enter_Uername.TranslateString()); return View(model); } if (string.IsNullOrEmpty(model.Password)) { ModelState.AddModelError("", ConstantDisplay.Hrm_Portal_Login_Enter_Password.TranslateString()); return View(model); } var passwordEncrypt = EncryptUtil.MD5(model.Password); var loginInfo = new LoginModel { UserName = model.UserName, Password = passwordEncrypt }; var service = new RestServiceClient<LoginModel>(UserLogin); service.SetCookies(this.Request.Cookies, _hrm_Sys_Service); var result = service.Post(_hrm_Sys_Service, "api/Login/", loginInfo); if (result != null) { if (!result.IsActive) { ModelState.AddModelError("", ConstantDisplay.Hrm_Portal_Login_User_Not_Active.TranslateString()); return View(model); } if (string.IsNullOrEmpty(model.Language)) { model.Language = Constant.VN; } Session[SessionObjects.IsFirstLogin] = result.IsFirstLogin; Session[SessionObjects.UserId] = result.ID; Session[SessionObjects.LoginUserName] = model.UserName; //Session[SessionObjects.LoginUserName] = result.UserName; Session[SessionObjects.FullName] = result.FullName; //Session[SessionObjects.UserInfoName] = result.UserInfoName; Session[SessionObjects.ProfileID] = result.ProfileID; VnResource.Helper.Utility.LanguageHelper.LanguageCode = model.Language; Session[SessionObjects.LanguageCode + model.UserName] = model.Language; if (result.IsFirstLogin) { return RedirectToAction("ChangePasswordDefault"); } return RedirectToAction("Index"); } ModelState.AddModelError("", ConstantDisplay.Hrm_Portal_Login_User_Not_Found.TranslateString()); return View(model); } return View(); }
public LoginModel Put(LoginModel model) { //ErrorModel errors = new ErrorModel(); model.Name = new List<string>(); model.Execption = new List<string>(); var service = new Sys_SqlCommanderServices(); string strKey = "GO"; string strKeyName = "@"; string strVersion = ""; #region Cap nhat Script if (!string.IsNullOrEmpty(@Common.ScriptPath)) { var directScript = new DirectoryInfo(@Common.ScriptPath); var filesScript = directScript.GetFiles(); if (filesScript != null && filesScript.Count() > 0) { var files = filesScript.OrderByDescending(s => s.Name).ToList(); var fileInfo = files.Where(d => Path.GetFileNameWithoutExtension(d.Name) == model.VesionLastName).FirstOrDefault(); files = files.Skip(files.IndexOf(fileInfo)).ToList(); foreach (var file in files) { StreamReader stream = file.OpenText(); string scripts = stream.ReadToEnd(); stream.Close(); scripts = scripts.Replace("\t", " ").Replace("\n", " ").Replace("\r", " ").Replace(";",""); //scripts = scripts.Replace(@"\", " "); //for (int i = 0; i < scripts.Length; i++) //{ // if ((int)scripts[i] == 34) // { // //scripts = scripts.Replace(scripts[i], ' '); // scripts = scripts.Remove(i, 1); // scripts = scripts.Insert(i, " "); // } //} while (scripts.Contains(" ")) { scripts = scripts.Replace(" ", " "); } string[] arrScript; if (Common.UseDataBaseName == DATABASETYPE.ORACLE.ToString()) { strKey = "/ "; } else { strKey = "GO "; } scripts = scripts.Replace(strKey, " "); arrScript = scripts.Split(new string[] { "--End--" }, StringSplitOptions.RemoveEmptyEntries); List<string> lstScript = new List<string>(); foreach (var item in arrScript) { string strExecption = service.ExecuteStringCommand(item); if (!string.IsNullOrEmpty(strExecption)) { model.Execption.Add(strExecption); model.Name.Add(file.Name); } } strVersion = Path.GetFileNameWithoutExtension(file.Name); } } } #endregion #region Cap nhat Store if (!string.IsNullOrEmpty(@Common.StorePath)) { var directStore = new DirectoryInfo(@Common.StorePath); var lstfileStore = directStore.GetFiles(); if (lstfileStore.Count() > 0) { FileInfo fileStore = lstfileStore.FirstOrDefault(); StreamReader stream = fileStore.OpenText(); string scriptStore = stream.ReadToEnd(); stream.Close(); scriptStore = scriptStore.Replace("\t", " ").Replace("\n", " ").Replace("\r", " ").Replace(";", ""); while (scriptStore.Contains(" ")) { scriptStore = scriptStore.Replace(" ", " "); } string[] arrStore; if (Common.UseDataBaseName == DATABASETYPE.ORACLE.ToString()) { strKey = "/ "; strKeyName = "("; } else { strKey = "GO "; strKeyName = "@"; scriptStore = scriptStore.Replace("ALTER PROCEDURE", "CREATE PROCEDURE"); scriptStore = scriptStore.Replace("alter procedure", "CREATE PROCEDURE"); scriptStore = scriptStore.Replace("ALTER procedure", "CREATE PROCEDURE"); scriptStore = scriptStore.Replace("alter PROCEDURE", "CREATE PROCEDURE"); scriptStore = scriptStore.Replace("create PROCEDURE", "CREATE PROCEDURE"); scriptStore = scriptStore.Replace("ALTER FUNCTION", "CREATE FUNCTION"); scriptStore = scriptStore.Replace("alter function", "CREATE FUNCTION"); scriptStore = scriptStore.Replace("alter FUNCTION", "CREATE FUNCTION"); scriptStore = scriptStore.Replace("ALTER function", "CREATE FUNCTION"); scriptStore = scriptStore.Replace("create FUNCTION", "CREATE FUNCTION"); } scriptStore = scriptStore.Replace(strKey, " "); arrStore = scriptStore.Split(new string[] { "--End--" }, StringSplitOptions.RemoveEmptyEntries); //string strScriptRoot = scriptStore; foreach (var item in arrStore) { string strExecption = service.ExecuteStringCommand(item); if (!string.IsNullOrEmpty(strExecption)) { model.Execption.Add(strExecption); model.Name.Add(item.Substring(0, scriptStore.IndexOf(strKeyName))); } } //while (scriptStore.Contains(strKey)) //{ // string strScript = scriptStore.Substring(0, scriptStore.IndexOf(strKey)); // scriptStore = scriptStore.Substring(scriptStore.IndexOf(strKey) + strKey.Length); // string strExecption = service.ExecuteStringCommand(strScript); // if (!string.IsNullOrEmpty(strExecption)) // { // model.Execption.Add(strExecption); // model.Name.Add(strScript.Substring(0, scriptStore.IndexOf(strKeyName))); // } //} if (Common.UseDataBaseName == DATABASETYPE.SQLSERVER.ToString()) { scriptStore = scriptStore.Replace("CREATE PROCEDURE", "ALTER PROCEDURE"); scriptStore = scriptStore.Replace("CREATE FUNCTION", "ALTER FUNCTION"); //string strScript = strScriptRoot.Substring(0, strScriptRoot.IndexOf(strKey)); //strScriptRoot = strScriptRoot.Substring(strScriptRoot.IndexOf(strKey) + strKey.Length); arrStore = scriptStore.Split(new string[] { "--End--" }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in arrStore) { string strExecption = service.ExecuteStringCommand(item); if (!string.IsNullOrEmpty(strExecption)) { model.Execption.Add(strExecption); model.Name.Add(item.Substring(0, item.IndexOf(strKeyName))); } } } } } #endregion if (model.Name.Count == 0) { string strUpdateVersion = ""; strUpdateVersion = "INSERT INTO \"Sys_Version\"(ID, \"Name\", \"Value\", \"Note\", \"UserCreate\", \"DateCreate\") VALUES (sys_guid(), '" + strVersion + "', '" + strVersion + "', '', 'son.vo', sysdate) "; service.ExecuteStringCommand(strUpdateVersion); } return model; }