protected void btnLogin_Click(object sender, EventArgs e) { //string customerCode = this.txtCustomerCode.Value.Trim(); string account = this.txtUsername.Value.Trim(); string pwd = this.txtPassword.Value.Trim(); //string authCode = txtValidateCode.Text.Trim(); //将用户登录名密码提交到服务器检验 //if (string.IsNullOrEmpty(customerCode) || customerCode == "公司编码") //{ // lblInfor.Text = "请输入公司编码!"; // txtCustomerCode.Focus(); // return; //} if (string.IsNullOrEmpty(account) || account == "用户名") { lblInfor.Text = "请输入用户名!"; txtUsername.Focus(); return; } if (string.IsNullOrEmpty(pwd)) { lblInfor.Text = "请输入密码!"; txtPassword.Focus(); return; } Hashtable ht = new Hashtable(); UserInfo login_user = null; var loggingSessionInfo = GetLjLoggingSession(); var service = new cUserService(loggingSessionInfo); try { int ret = 0; var userList = service.SearchUserList(account, "", "", "", 1, 0); if (userList != null && userList.UserInfoList != null && userList.UserInfoList.Count > 0) { login_user = userList.UserInfoList[0]; login_user.customer_id = "43753855ae814fc093c281441972f8f1"; if (login_user.User_Status == "-1") { ret = -2; } else if (login_user.User_Password != EncryptManager.Hash(pwd, HashProviderType.MD5)) { ret = -3; } else { ret = 1; } } else { ret = -1; } switch (ret) { case -1: lblInfor.Text = "用户不存在"; return; case -2: lblInfor.Text = "用户被停用"; return; case -3: lblInfor.Text = "密码不正确"; return; case -4: lblInfor.Text = "用户不在线"; return; case 1: //用户名和密码验证通过 break; default: lblInfor.Text = "用户名和密码不正确"; return; } } catch { lblInfor.Text = "用户名和密码不正确"; return; } // chkRemember if (chkRemember.Checked) { Response.Cookies["cpos_sso_remember"].Value = "1"; Response.Cookies["cpos_sso_remember"].Expires = DateTime.MaxValue; Response.Cookies["cpos_sso_user"].Value = account; Response.Cookies["cpos_sso_user"].Expires = DateTime.MaxValue; Response.Cookies["cpos_sso_pwd"].Value = pwd; Response.Cookies["cpos_sso_pwd"].Expires = DateTime.MaxValue; } else { Response.Cookies["cpos_sso_remember"].Value = ""; Response.Cookies["cpos_sso_user"].Value = ""; Response.Cookies["cpos_sso_pwd"].Value = ""; } //判断登录进来的用户是否存在,并且返回用户信息 LoggingSessionInfo loggingSession = new LoggingSessionInfo(); loggingSession.CurrentLoggingManager = new LoggingManager(); loggingSession.CurrentLoggingManager.Connection_String = loggingSessionInfo.Conn; loggingSession.CurrentLoggingManager.Customer_Id = loggingSessionInfo.CurrentUser.customer_id; loggingSession.CurrentUser = login_user; // 获取角色 string applicationId = PageBase.JITPage.GetApplicationId(); IList <UserRoleInfo> userRoleList = service.GetUserRoles(login_user.User_Id, applicationId); if (userRoleList != null && userRoleList.Count > 0) { loggingSession.CurrentUserRole = new UserRoleInfo(); loggingSession.CurrentUserRole.UserId = login_user.User_Id; loggingSession.CurrentUserRole.UserName = login_user.User_Name; loggingSession.CurrentUserRole.RoleId = userRoleList[0].RoleId; loggingSession.CurrentUserRole.RoleName = userRoleList[0].RoleName; loggingSession.ClientID = login_user.customer_id; loggingSession.CurrentLoggingManager.Customer_Id = login_user.customer_id; loggingSession.UserID = loggingSession.CurrentUser.User_Id; try { loggingSession.CurrentUserRole.UnitId = service.GetDefaultUnitByUserIdAndRoleId( loggingSession.CurrentUserRole.UserId, loggingSession.CurrentUserRole.RoleId); } catch (Exception ex) { PageLog.Current.Write(ex); Response.Write("找不到默认单位"); Response.End(); } //try //{ // loggingSession.CurrentUserRole.UnitName = unitService.GetUnitById( // loggingSessionInfo, loggingSession.CurrentUserRole.UnitId).ShortName; //} //catch (Exception ex) //{ // PageLog.Current.Write(ex); // Response.Write("找不到单位"); // Response.End(); //} } //this.Session["UserInfo"] = login_user; //this.Session["LoggingManager"] = myLoggingManager; //this.Session["loggingSessionInfo"] = loggingSession; //loggingSession.CurrentLoggingManager = myLoggingManager; new SessionManager().SetCurrentUserLoginInfo(loggingSession); //清空密码 login_user.User_Password = null; string goURL = "~/Default.aspx"; this.Response.Redirect(goURL); }
/// <summary> /// 通过ID获取用户角色信息 /// </summary> public string GetUserRoleInfoByUserIdData() { var responseData = new ResponseData(); LoggingSessionInfo loggingSessionInfo = null; if (CurrentUserInfo != null) { loggingSessionInfo = CurrentUserInfo; } else { if (string.IsNullOrEmpty(Request("CustomerID"))) { responseData.success = false; responseData.msg = "缺少商户标识"; return(responseData.ToString()); } else if (string.IsNullOrEmpty(Request("CustomerUserID"))) { responseData.success = false; responseData.msg = "缺少登陆员工的标识"; return(responseData.ToString()); } else if (string.IsNullOrEmpty(Request("CustomerUserID"))) { responseData.success = false; responseData.msg = "缺少登陆员工的标识"; return(responseData.ToString()); } else { loggingSessionInfo = Default.GetBSLoggingSession(Request("CustomerID"), Request("CustomerUserID")); } } var userService = new cUserService(loggingSessionInfo);//使用兼容模式 UserRoleInfo data = new UserRoleInfo(); string content = string.Empty; string key = string.Empty; if (Request("user_id") != null && Request("user_id") != string.Empty) { key = Request("user_id").ToString().Trim(); } data.UserRoleInfoList = userService.GetUserRoles(key); if (data.UserRoleInfoList == null) { data.UserRoleInfoList = new List <UserRoleInfo>(); } var jsonData = new JsonData(); jsonData.totalCount = data.UserRoleInfoList.Count.ToString(); jsonData.data = data.UserRoleInfoList; content = string.Format("{{\"totalCount\":{1},\"topics\":{0}}}", data.UserRoleInfoList.ToJSON(), data.UserRoleInfoList.Count); return(content); }
private void loadUser(string customer_id, string token) { //try //{ //获取登录管理平台的用户信息 var AuthWebService = new JIT.CPOS.BS.WebServices.AuthManagerWebServices.AuthServiceSoapClient(); AuthWebService.Endpoint.Address = new System.ServiceModel.EndpointAddress( ConfigurationManager.AppSettings["sso_url"].ToString() + "/AuthService.asmx"); // AuthWebService.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:42305/AuthService.asmx"); //AuthWebService.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:7335/AuthService.asmx"); if (token == null) { token = ""; } string str = AuthWebService.GetLoginUserInfo(token); if (string.IsNullOrEmpty(str)) { //this.lbErr.Text = "用户不存在,请与管理员联系"; //return; PageLog.Current.Write("SSO登录失败,AuthWebService.asmx返回空数据"); //Response.Write("登录失败,请重试!"); //Response.End(); var redirectUrl = ConfigurationManager.AppSettings["sso_url"].ToString() + "?errorinfo=" + "网络繁忙,请重新登录!"; //var redirectUrl = "http://localhost:7335/login.aspx"; Response.Redirect(redirectUrl, true); } var myLoggingManager = (JIT.CPOS.BS.Entity.LoggingManager)cXMLService.Deserialize( str, typeof(JIT.CPOS.BS.Entity.LoggingManager)); //判断登录进来的用户是否存在,并且返回用户信息 LoggingSessionInfo loggingSession = new LoggingSessionInfo(); loggingSession.CurrentLoggingManager = myLoggingManager; cUserService userService = new cUserService(loggingSession); UnitService unitService = new UnitService(loggingSession); if (!userService.IsExistUser(loggingSession)) { this.lbErr.Text = "用户不存在,请与管理员联系"; return; } var login_user = userService.GetUserById(loggingSession, myLoggingManager.User_Id); loggingSession.CurrentUser = login_user; // 获取角色 string applicationId = PageBase.JITPage.GetApplicationId(); IList <UserRoleInfo> userRoleList = userService.GetUserRoles(login_user.User_Id, applicationId); if (userRoleList != null && userRoleList.Count > 0) { loggingSession.CurrentUserRole = new UserRoleInfo(); loggingSession.CurrentUserRole.UserId = login_user.User_Id; loggingSession.CurrentUserRole.UserName = login_user.User_Name; loggingSession.CurrentUserRole.RoleId = userRoleList[0].RoleId; loggingSession.CurrentUserRole.RoleCode = userRoleList[0].RoleCode; loggingSession.CurrentUserRole.RoleName = userRoleList[0].RoleName; loggingSession.ClientID = login_user.customer_id; loggingSession.CurrentLoggingManager.Customer_Id = login_user.customer_id; loggingSession.UserID = loggingSession.CurrentUser.User_Id; try { loggingSession.CurrentUserRole.UnitId = userService.GetDefaultUnitByUserIdAndRoleId( loggingSession.CurrentUserRole.UserId, loggingSession.CurrentUserRole.RoleId); } catch (Exception ex) { PageLog.Current.Write(ex); Response.Write("找不到默认单位"); Response.End(); } try { var unitInfo = unitService.GetUnitById(loggingSession.CurrentUserRole.UnitId); loggingSession.CurrentUserRole.UnitName = unitInfo.Name; loggingSession.CurrentUserRole.UnitShortName = unitInfo.ShortName; } catch (Exception ex) { PageLog.Current.Write(ex); Response.Write("找不到单位"); Response.End(); } } else { //PageLog.Current.Write(ex); Response.Write("该用户没有权限登录管理平台"); Response.End(); } //this.Session["UserInfo"] = login_user; //this.Session["LoggingManager"] = myLoggingManager; //this.Session["loggingSessionInfo"] = loggingSession; //loggingSession.CurrentLoggingManager = myLoggingManager; new SessionManager().SetCurrentUserLoginInfo(loggingSession); //清空密码 login_user.User_Password = null; //string go_url = "~/login/SelectRoleUnit.aspx?p=0"; string go_url = "~/Default.aspx"; if (loggingSession.CurrentUserRole != null && loggingSession.CurrentUserRole.RoleId == "860E69754D3B490F8A5B401DF3F66E15") { string eventId = string.Empty; //switch (loggingSession.CurrentUserRole.UserId.Trim()) //{ // case "FA1BDA8937924D45AFA3123FE4DEE8FA": // eventId = "0326056B219340D5B234BFAD9AF02AF5"; // break; // case "4913B21CFD714C7986842B859EC1289B": // eventId = "793150439CF94190A70CF2EC229A951D"; // break; // case "BD8079F886BD492E90A335EBC1DE9676": // eventId = "F8A7E2E8807B49558F1A516F23C34473"; // break; // default: // eventId = "793150439CF94190A70CF2EC229A951D"; // break; //} LEventsBLL lEventsBLL = new LEventsBLL(loggingSession); var eventList = lEventsBLL.QueryByEntity(new LEventsEntity() { EventManagerUserId = loggingSession.CurrentUserRole.UserId }, null); if (eventList != null && eventList.Length > 0) { eventId = eventList[0].EventID; loggingSession.CurrentUserRole.RoleName = eventId; Response.Redirect("~/Module/MarketEvent/EventList/EventAnalysisList4.aspx", true); } } else { //loggingSession.CurrentUserRole.RoleName = "793150439CF94190A70CF2EC229A951D"; Response.Redirect(go_url, true); } //} //catch (Exception ex) //{ // PageLog.Current.Write(ex); // lbErr.Text = "登录失败"; //} }
/// <summary> /// 通过ID获取用户信息 /// </summary> public string GetUserInfoByIdData() { var responseData = new ResponseData(); LoggingSessionInfo loggingSessionInfo = null; if (CurrentUserInfo != null) { loggingSessionInfo = CurrentUserInfo; } else { if (string.IsNullOrEmpty(Request("CustomerID"))) { responseData.success = false; responseData.msg = "缺少商户标识"; return(responseData.ToString()); } else if (string.IsNullOrEmpty(Request("CustomerUserID"))) { responseData.success = false; responseData.msg = "缺少登陆员工的标识"; return(responseData.ToString()); } else if (string.IsNullOrEmpty(Request("CustomerUserID"))) { responseData.success = false; responseData.msg = "缺少登陆员工的标识"; return(responseData.ToString()); } else { loggingSessionInfo = Default.GetBSLoggingSession(Request("CustomerID"), Request("CustomerUserID")); } } var userService = new cUserService(loggingSessionInfo);//使用兼容模式 UserInfo data; string content = string.Empty; string key = string.Empty; if (Request("user_id") != null && Request("user_id") != string.Empty) { key = Request("user_id").ToString().Trim(); } data = userService.GetUserById(CurrentUserInfo, key); if (data != null) { data.userRoleInfoList = userService.GetUserRoles(key); } var jsonData = new JsonData(); jsonData.totalCount = "1"; jsonData.data = data; jsonData.success = true; jsonData.msg = ""; content = jsonData.ToJSON(); return(content); }
/// <summary> /// 获取BS用户登录信息 /// </summary> /// <param name="customerId"></param> /// <param name="userId"></param> /// <returns></returns> public static LoggingSessionInfo GetBSLoggingSession(string customerId, string userId) { if (userId == null || userId == string.Empty) { userId = "system"; } string conn = ""; string name = ""; CC_Connection connection = new RedisConnectionBLL().GetConnection(customerId);//从redis里获取商户数据库链接 RedisXML _RedisXML = new RedisXML(); //如果从缓存里获取不到信息,就从数据库读取,并种到缓存里 if (connection == null || string.IsNullOrEmpty(connection.ConnectionStr) || string.IsNullOrEmpty(connection.Customer_Name)) { //记录redis读取不成功,从数据库里读取数据的情况 _RedisXML.RedisReadDBCount("Connection", "商户数据库链接", 2); conn = GetCustomerConn(customerId); name = GetCustomerName(customerId); string code = GetCustomerCode(customerId); new RedisConnectionBLL().SetConnection(customerId, conn, name, code); } else { //记录redis读取日志 _RedisXML.RedisReadDBCount("Connection", "商户数据库链接", 1); conn = connection.ConnectionStr; name = connection.Customer_Name; } LoggingSessionInfo loggingSessionInfo = new LoggingSessionInfo(); //loggingSessionInfo = new CLoggingSessionService().GetLoggingSessionInfo(customerId, "7d4cda48970b4ed0aa697d8c2c2e4af3"); loggingSessionInfo.CurrentUser = new BS.Entity.User.UserInfo(); loggingSessionInfo.CurrentUser.User_Id = userId; loggingSessionInfo.CurrentUser.customer_id = customerId; loggingSessionInfo.UserID = loggingSessionInfo.CurrentUser.User_Id; loggingSessionInfo.ClientID = customerId; loggingSessionInfo.Conn = conn; loggingSessionInfo.CurrentLoggingManager = new LoggingManager(); loggingSessionInfo.CurrentLoggingManager.Connection_String = loggingSessionInfo.Conn; loggingSessionInfo.CurrentLoggingManager.User_Id = userId; loggingSessionInfo.CurrentLoggingManager.Customer_Id = customerId; loggingSessionInfo.CurrentLoggingManager.Customer_Name = name; loggingSessionInfo.CurrentLoggingManager.User_Name = ""; if (!string.IsNullOrEmpty(conn)) { //用户角色信息 cUserService userService = new cUserService(loggingSessionInfo); string applicationId = "649F8B8BDA9840D6A18130A5FF4CB9C8";//[T_Def_App] app IList <UserRoleInfo> userRoleList = userService.GetUserRoles(loggingSessionInfo.UserID, applicationId); if (userRoleList != null && userRoleList.Count > 0) { loggingSessionInfo.CurrentUserRole = new UserRoleInfo(); loggingSessionInfo.CurrentUserRole.UserId = loggingSessionInfo.UserID; //loggingSessionInfo.CurrentUserRole.UserName = login_user.User_Name; loggingSessionInfo.CurrentUserRole.RoleId = userRoleList[0].RoleId; loggingSessionInfo.CurrentUserRole.RoleCode = userRoleList[0].RoleCode; loggingSessionInfo.CurrentUserRole.RoleName = userRoleList[0].RoleName; loggingSessionInfo.CurrentUserRole.UnitId = userService.GetDefaultUnitByUserIdAndRoleId( loggingSessionInfo.CurrentUserRole.UserId, loggingSessionInfo.CurrentUserRole.RoleId); } loggingSessionInfo.ClientName = name; } return(loggingSessionInfo); }