public static bool IsAuthenticated(string strUser, string strPassword) { ADUsersController ADUserCtrl = new ADUsersController(); ADUsersInfo UserInfo = (ADUsersInfo)ADUserCtrl.GetObjectByName(strUser); return(UserInfo != null && UserInfo.ADPassword.Equals(new Crypto().Encrypt(strPassword))); }
//static void timer_Tick ( object sender , EventArgs e ) //{ // ShowAlerts(); //} public static Dictionary <Guid, GEAlertsInfo> GetAlertConfigs(Guid iUserID) { if (AlertList != null) { return(AlertList); } AlertList = new Dictionary <Guid, GEAlertsInfo>(); AlertQueryList = new Dictionary <Guid, string>(); ADUsersInfo user = new ADUsersController().GetObjectByID(iUserID) as ADUsersInfo; if (user != null && user.FK_ADUserGroupID.HasValue) { ADUserGroupsInfo group = new ADUserGroupsController().GetObjectByID(user.FK_ADUserGroupID.Value) as ADUserGroupsInfo; if (group != null) { String strQuery = String.Format(@"SELECT A.* FROM GEAlerts A JOIN GEAlertUsers B ON A.GEAlertID = B.FK_GEAlertID AND (B.FK_ADUserGroupID ='{0}' OR B.FK_ADUserID ='{1}') ORDER BY B.FK_ADUserID DESC", user.FK_ADUserGroupID.Value, user.ADUserID); foreach (GEAlertsInfo alertInfo in new GEAlertsController().GetListByQuery(strQuery).Cast <GEAlertsInfo>().ToList()) { if (AlertList.ContainsKey(alertInfo.GEAlertID) == false) { AlertList.Add(alertInfo.GEAlertID, alertInfo); } } } } return(AlertList); }
public static List <Guid> GetHomepages(Guid iUserID) { List <Guid> lstViewIDs = new List <Guid>(); ADUsersInfo user = new ADUsersController().GetObjectByID(iUserID) as ADUsersInfo; if (user != null && user.FK_ADUserGroupID.HasValue) { ADUserGroupsInfo group = new ADUserGroupsController().GetObjectByID(user.FK_ADUserGroupID.Value) as ADUserGroupsInfo; if (group != null) { String strQuery = String.Format(@"SELECT A.FK_STViewID FROM GEPermissionViews A JOIN ADUserPermissions B ON A.IsHomePage ='TRUE' AND B.FK_GEPermissionID = A.FK_GEPermissionID AND (B.FK_ADUserGroupID ='{0}' OR B.FK_ADUserID ='{1}') ORDER BY B.FK_ADUserID DESC", user.FK_ADUserGroupID.Value, user.ADUserID); DataSet ds = new GEPermissionViewsController().GetDataSet(strQuery); if (ds != null && ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { if (dr[0] != DBNull.Value && !lstViewIDs.Contains(ABCHelper.DataConverter.ConvertToGuid(dr[0].ToString()))) { lstViewIDs.Add(ABCHelper.DataConverter.ConvertToGuid(dr[0].ToString())); } } } } } return(lstViewIDs); }
private bool IsValid() { string username = Convert.ToString(fld_txtUsername.EditValue); if (string.IsNullOrEmpty(username)) { MessageBox.Show("Tên đăng nhập không được bỏ trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ADUsersController objUsersController = new ADUsersController(); ADUsersInfo existingUser = (ADUsersInfo)objUsersController.GetObjectByName(username); if (existingUser != null && existingUser.ADUserID != ADUsers.ADUserID) { MessageBox.Show("Tên đăng nhập đã được sử dụng. Vui lòng chọn tên đăng nhập khác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (ADUsers.ADUserID == 0) { if (String.IsNullOrEmpty(ADUsers.ADPassword)) { MessageBox.Show("Mật khẩu không đc để trống", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } //if (!string.IsNullOrEmpty(objUsersInfo.ADPassword) && objUsersInfo.ADPassword != fld_txtConfirmPassword.Text) //{ // MessageBox.Show(UserManagementLocalizedResources.PasswordNotMatchMessage, "Thông báo" MessageBoxButtons.OK, MessageBoxIcon.Error); // return false; //} return(false); }
public static bool IsAuthenticated(string username, string password, out string strMessage) { strMessage = string.Empty; ADUsersController adUsersController = new ADUsersController(); ADUsersInfo objUsersInfo = (ADUsersInfo)adUsersController.GetObjectByName(username); if (objUsersInfo == null) { return(false); } if (!objUsersInfo.ADUserActiveCheck) { strMessage = "Tài khoản của bạn đã bị khóa. Vui lòng thử lại sau!"; return(false); } if (!objUsersInfo.ADPassword.Equals(VinaUtil.EncryptMD5Hash(password))) { strMessage = "Tài khoản hoặc mật khẩu không chính xác. Vui lòng thử lại!"; return(false); } VinaApp.CurrentUserName = objUsersInfo.ADUserName; VinaApp.CurrentUserInfo = objUsersInfo; return(true); }
public void InvalidateUserList() { UserManagementEntities entity = (UserManagementEntities)CurrentModuleEntity; ADUsersController objUsersController = new ADUsersController(); DataSet ds = objUsersController.GetAllObjects(); entity.ADUserList.Invalidate(ds); }
public static void SaveUserStyle(String strLookAndFeelStyle, String strLookAndFeelStyleSkin) { if (VinaApp.CurrentUserInfo != null) { ADUsersController objUsersController = new ADUsersController(); VinaApp.CurrentUserInfo.ADUserStyle = strLookAndFeelStyle; VinaApp.CurrentUserInfo.ADUserStyleSkin = strLookAndFeelStyleSkin; objUsersController.UpdateObject(VinaApp.CurrentUserInfo); } }
public static bool CheckTablePermission(Guid iUserID, String strTableName, TablePermission permission) { bool result = false; String strKey = iUserID.ToString() + strTableName + permission.ToString(); if (TablePermissionList.TryGetValue(strKey, out result)) { return(result); } ADUsersInfo user = new ADUsersController().GetObjectByID(iUserID) as ADUsersInfo; if (user != null && user.FK_ADUserGroupID.HasValue) { ADUserGroupsInfo group = new ADUserGroupsController().GetObjectByID(user.FK_ADUserGroupID.Value) as ADUserGroupsInfo; if (group != null) { result = (user.No == "sysadmin"); String strQuery = String.Format(@"SELECT A.* FROM GEPermissionTables A JOIN ADUserPermissions B ON A.TableName ='{0}' AND B.FK_GEPermissionID = A.FK_GEPermissionID AND (B.FK_ADUserGroupID ='{1}' OR B.FK_ADUserID ='{2}') ORDER BY B.FK_ADUserID DESC", strTableName, user.FK_ADUserGroupID.Value, user.ADUserID); foreach (GEPermissionTablesInfo tablePermission in new GEPermissionTablesController().GetList(strQuery).Cast <GEPermissionTablesInfo>().ToList()) { switch (permission) { case TablePermission.AllowView: result = (result || tablePermission.AllowView); break; case TablePermission.AllowNew: result = (result || tablePermission.AllowNew); break; case TablePermission.AllowEdit: result = (result || tablePermission.AllowEdit); break; case TablePermission.AllowDelete: result = (result || tablePermission.AllowDelete); break; } } } } if (SystemProvider.SystemConfig.IsRelease) { TablePermissionList.Add(strKey, result); } return(result); }
public void AddUser() { UserManagementEntities entity = (UserManagementEntities)CurrentModuleEntity; ADUsersInfo objUsersInfo = new ADUsersInfo(); guiManageUser guiUser = new guiManageUser(objUsersInfo); //guiUser.BringToFront(); //guiUser.loca if (guiUser.ShowDialog() != DialogResult.OK) { return; } objUsersInfo = guiUser.ADUsers; ADUsersController objUsersController = new ADUsersController(); objUsersController.CreateObject(objUsersInfo); InvalidateUserList(); }
private static void SetCurrentUserLogin(System.DateTime dt) { if (CurrenUserInfo != null) { ADUsersController ADUserCtrl = new ADUsersController(); SetSession("IsLoggingOff", false); CurrentCompanyInfo = (CSCompanysInfo) new CSCompanysController().GetFirstObject(); CurrenUserGroupInfo = (ADUserGroupsInfo) new ADUserGroupsController().GetObjectByID(ADUserCtrl.GetUserGroupOfUser(CurrenUserInfo.ADUserName)); GMCWebApp.CurrentLanguage = CurrenUserInfo.ADUserCurLang; GMCWebApp.InitDictionary(); SetSession("CurrentUser", CurrenUserInfo.ADUserName); SetSession("WorkingDate", dt); SetSession("WorkingPeriod", dt.Month); SetSession("WorkingYear", dt.Year); //SetCookie("RecentUser", CurrenUserInfo.ADUserName); SetCookie("Server", Convert.ToString(GetSession("CurrentServer"))); //SetValueConfigSettings("RecentUser", CurrenUserInfo.ADUserName); SetValueConfigSettings("Server", Convert.ToString(GetSession("CurrentServer"))); } }
public ActionResult GridViewPartialView(int iFieldID, string sType, string sDocType, string sStatus) { // DXCOMMENT: Pass a data model for GridView in the PartialView method's second parameter HomeModels home = new HomeModels(); Dictionary <STFieldsInfo, List <BusinessObject> > dic = home.GetFieldInfo(iFieldID); ViewData["sType"] = sType; ViewData["control"] = dic; if (sType == "Inbox") { DataTable dtInbox = MailUtil.GetListInboxItemByUserNameAndDocType(Convert.ToString(AuthConfig.GetSession("CurrentUser")), Convert.ToString(sDocType), sStatus); ViewData["data"] = dtInbox; } else { int iUserID = new ADUsersController().GetObjectIDByName(Convert.ToString(AuthConfig.GetSession("CurrentUser"))); DataSet dsOutbox = new ADOutboxItemsController().GetAllOutboxItemsByUser(iUserID); ViewData["data"] = dsOutbox; } return(PartialView("GridViewAjaxPartialView", null)); }
public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { Crypto crypto = new Crypto(); string strPass = crypto.Encrypt(model.NewPassword); string strConfirm = crypto.Encrypt(model.ConfirmPassword); if (strPass != strConfirm) { ModelState.AddModelError("ChangePasswordFaild", "The Password provided is incorrect."); } else { ADUsersInfo userInfo = new ADUsersController().GetObjectByName(Convert.ToString(AuthConfig.GetSession("UserName"))) as ADUsersInfo; userInfo.ADPassword = strConfirm; new ADUsersController().UpdateObject(userInfo, false, "ADPassword"); return(Redirect("Login")); } } ViewBag.Title = Properties.Settings.Default.WebTitle; return(View(model)); }
public void DeleteUser() { UserManagementEntities entity = (UserManagementEntities)CurrentModuleEntity; ADUsersInfo objUsersInfo = entity.ADUserList[entity.ADUserList.CurrentIndex]; if (objUsersInfo == null) { return; } DialogResult rs = MessageBox.Show("Bạn có chắn chắn muốn xóa người dùng này không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rs != DialogResult.Yes) { return; } ADUsersController objUsersController = new ADUsersController(); objUsersController.DeleteObject(objUsersInfo.ADUserID); InvalidateUserList(); }
public void EditUser() { UserManagementEntities entity = (UserManagementEntities)CurrentModuleEntity; ADUsersInfo objUsersInfo = entity.ADUserList[entity.ADUserList.CurrentIndex]; if (objUsersInfo == null) { return; } guiManageUser guiUser = new guiManageUser(objUsersInfo); if (guiUser.ShowDialog() != DialogResult.OK) { return; } objUsersInfo = guiUser.ADUsers; ADUsersController objUsersController = new ADUsersController(); objUsersController.UpdateObject(objUsersInfo); InvalidateUserList(); }
public static bool ChangePassword(String strDatabase, String strUserNo, String strOldPassword, String strNewPassword) { if (!ConnectDatabase(strDatabase)) { return(false); } Security.Cryptography crypto = new Security.Cryptography(); String strOldEncryptedPass = crypto.Encrypt(strOldPassword); ADUsersInfo user = new ADUsersController().GetObjectByNo(strUserNo) as ADUsersInfo; if (user == null || strOldEncryptedPass != user.Password) { ABCHelper.ABCMessageBox.Show(LoginForm, "Thông tin người dùng, mật khẩu không đúng", "Đổi mật khẩu", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } user.Password = crypto.Encrypt(strNewPassword); BusinessObjectController.RunQuery(String.Format(@"UPDATE ADUsers SET Password='******' ,UpdateTime=GETDATE() WHERE ADUserID = '{1}'", user.Password, user.ADUserID)); ABCHelper.ABCMessageBox.Show(LoginForm, "Đổi mật khẩu thành công", "Đổi mật khẩu", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }
public static void Login(LoginType loginType, String strDatabase, String strUserNo, String strPassword) { if (!ConnectDatabase(strDatabase)) { return; } String strEncryptedPass = new Security.Cryptography().Encrypt(strPassword); ADUsersInfo user = new ADUsersController().GetObject(String.Format(@"SELECT * FROM ADUsers WHERE No='{0}' AND ABCStatus ='Alive' AND Active =1 ", strUserNo)) as ADUsersInfo; if (user == null || strEncryptedPass != user.Password) { ABCHelper.ABCMessageBox.Show(LoginForm, "Thông tin người dùng, mật khẩu không đúng", "Đăng nhập", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (LoginForm != null) { LoginForm.Close(); LoginForm.Dispose(); } Application.DoEvents(); ABCScreen.SplashUtils.ShowSplash(loginType); ABCControls.UICaching.InitCachingPresentControls(); #region Section CurrentUser = user; if (CurrentUser.FK_ADUserGroupID.HasValue) { CurrentUserGroup = new ADUserGroupsController().GetObjectByID(CurrentUser.FK_ADUserGroupID.Value) as ADUserGroupsInfo; } ABCUserProvider.CurrentUserName = CurrentUser.No; if (CurrentUser.FK_HREmployeeID.HasValue) { try { ABCUserProvider.CurrentEmployee = new HREmployeesController().GetObjectByID(CurrentUser.FK_HREmployeeID.Value) as HREmployeesInfo; if (ABCUserProvider.CurrentEmployee != null) { ABCUserProvider.CurrentEmployeeName = ABCUserProvider.CurrentEmployee.Name; if (ABCUserProvider.CurrentEmployee.FK_GECompanyUnitID.HasValue) { ABCUserProvider.CurrentCompanyUnit = new GECompanyUnitsController().GetObjectByID(ABCUserProvider.CurrentEmployee.FK_GECompanyUnitID.Value) as GECompanyUnitsInfo; } } }catch (Exception ex) { } } StartOnlineTimer(); if (loginType == LoginType.ERP) { ABCApp.ABCAppHelper.Instance.StartSection(); } else if (loginType == LoginType.Studio) { ABCStudio.ABCStudioHelper.Instance.StartSection(); } ABCScreen.SplashUtils.CloseSplash(); #endregion }
public static bool CheckVoucherPermission(Guid iUserID, Guid voucherTypeID, VoucherPermission permission) { bool result = true; String strKey = iUserID.ToString() + voucherTypeID.ToString() + permission.ToString(); if (VoucherPermissionList.TryGetValue(strKey, out result)) { return(result); } ADUsersInfo user = new ADUsersController().GetObjectByID(iUserID) as ADUsersInfo; if (user != null && user.FK_ADUserGroupID.HasValue) { ADUserGroupsInfo group = new ADUserGroupsController().GetObjectByID(user.FK_ADUserGroupID.Value) as ADUserGroupsInfo; if (group != null) { result = (user.No == "sysadmin"); String strQuery = String.Format(@"SELECT A.* FROM GEPermissionVouchers A JOIN ADUserPermissions B ON A.FK_GEVoucherID ='{0}' AND B.FK_GEPermissionID = A.FK_GEPermissionID AND (B.FK_ADUserGroupID ='{1}' OR B.FK_ADUserID ='{2}') ORDER BY B.FK_ADUserID DESC", voucherTypeID, user.FK_ADUserGroupID.Value, user.ADUserID); foreach (GEPermissionVouchersInfo voucherPermission in new GEPermissionVouchersController().GetList(strQuery).Cast <GEPermissionVouchersInfo>().ToList()) { switch (permission) { case VoucherPermission.AllowView: result = (result || voucherPermission.AllowView); break; case VoucherPermission.AllowNew: result = (result || voucherPermission.AllowNew); break; case VoucherPermission.AllowEdit: result = (result || voucherPermission.AllowEdit); break; case VoucherPermission.AllowDelete: result = (result || voucherPermission.AllowDelete); break; case VoucherPermission.AllowApproval: result = (result || voucherPermission.AllowApproval); break; case VoucherPermission.AllowLock: result = (result || voucherPermission.AllowLock); break; case VoucherPermission.AllowPost: result = (result || voucherPermission.AllowPost); break; case VoucherPermission.AllowPrint: result = (result || (voucherPermission.AllowPrint && !String.IsNullOrWhiteSpace(voucherPermission.ReportName))); break; } } } } if (SystemProvider.SystemConfig.IsRelease) { VoucherPermissionList.Add(strKey, result); } return(result); }
public static HREmployeesInfo GetEmployeeByUserName(string strUserName) { int iUserID = new ADUsersController().GetObjectIDByName(strUserName); return((HREmployeesInfo) new HREmployeesController().GetFirstObjectByForeignColumn("FK_ADUserID", iUserID)); }
public static string LogIn(string strSrv, string strUser, string strPassword, System.DateTime dt) { ConnectionAuth(strSrv); if (!SqlDatabaseHelper.TestConnection()) { return("Không kết nối được CSDL! Vui lòng liên hệ người quản trị!"); } ADUsersController ADUserCtrl = new ADUsersController(); CurrenUserInfo = (ADUsersInfo)ADUserCtrl.GetObjectByName(strUser); ADUserConfigsInfo UserCfgInfo = new ADUserConfigsController().GetFirstObject() as ADUserConfigsInfo; GMCWebApp.GetLocalMachineInfo(); if (CurrenUserInfo != null && CurrenUserInfo.ADUserIsLockedCheck) { return("Tài khoản đăng nhập này đã bị khóa! Vui lòng liên hệ người quản trị!"); } else if (IsUserLoggedIn(strUser)) { GEUserAuditsInfo UserAudisInfo = new GEUserAuditsController().GetGEUserAuditsByADUserName(strUser); return(string.Format("Người dùng này đã đăng nhập trên máy {0} với địa chỉ IP {1}!", UserAudisInfo.GEUserAuditPCName, UserAudisInfo.GEUserAuditIP)); } else if (IsAuthenticated(strUser, strPassword)) { if (!new ADUserGroupsController().IsExist(CurrenUserInfo.ADUserGroupID)) { return(string.Format("Nhóm người dùng của tài khoản {0} không tồn tại trên hệ thống!", strUser)); } else { SetCurrentUserLogin(dt); SaveUserAuditLogin("Login"); if (UserCfgInfo != null && UserCfgInfo.ADUserConfigPassDayExpires > 0) { if (new ADUserPassHistorysController().IsOldPassExpired(CurrenUserInfo.ADUserID, UserCfgInfo.ADUserConfigPassDayExpires)) { return("Mật khẩu đã hết hạn! Vui lòng đổi mật khẩu mới!"); } } } } else { int iCountLoginFail = new GEUserAuditsController().GetCountLoginFail(strUser, "WebHome", dt); iCountLoginFail++; if (UserCfgInfo != null && (iCountLoginFail >= UserCfgInfo.ADUserConfigMaxLogonCount) && UserCfgInfo.ADUserConfigMaxLogonCount > 0) { SaveUserAuditLogin("LoginFailLock", 0, strUser); if (CurrenUserInfo != null) { CurrenUserInfo.ADUserIsLockedCheck = true; CurrenUserInfo.ADUserLockedInfo = Environment.MachineName + ", " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); ADUserCtrl.UpdateObject(CurrenUserInfo, true, "ADUserIsLockedCheck", "ADUserLockedInfo"); } return(string.Format("Vượt quá số lần đăng nhập sai cho phép! Tài khoản đăng nhập {0} đã bị khóa", strUser)); } SaveUserAuditLogin("LoginFail", 0, strUser); string strError = "Tên đăng nhập/ Mật khẩu không hợp lệ!"; if (UserCfgInfo != null && UserCfgInfo.ADUserConfigMaxLogonCount > 0) { strError += string.Format(" Còn lại {0} lần thử", UserCfgInfo.ADUserConfigMaxLogonCount - iCountLoginFail); } return(strError); } ADConfigValueUtility.InitGlobalConfigValueTables(); return(""); }