Esempio n. 1
0
        /// <summary>
        /// 设置在线用户
        /// </summary>
        public string SetLoginUsers(I6WebAppInfo appInfo)
        {
            string sql  = string.Empty;
            var    guid = Guid.NewGuid().ToString();

            switch (DbHelper.Vendor)
            {
            case DbVendor.Oracle:
            case DbVendor.Oracle10:
            case DbVendor.Oracle11:
            case DbVendor.Oracle9:
                sql = $@"INSERT INTO FG_LOGINHISTORY (CODE, LOGINID, LOGINNAME, UCODE, OCODE, ONAME, LOGINDT, ORGID, USERID, DEVICETYPE)
VALUES('{guid}', '{appInfo.LoginID}', '{appInfo.UserName}', '{appInfo.UCode.Replace("NG", "")}', '{appInfo.OCode}', '{appInfo.OrgName}', TO_DATE('{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")}', 'YYYY/MM/DD HH24:MI:SS '),{appInfo.OrgID},{appInfo.UserID},1)";
                break;

            case DbVendor.SQLServer:
            case DbVendor.SQLServer2000:
            case DbVendor.SQLServer2005:
            case DbVendor.SQLServer2008:
                sql = $@"INSERT INTO FG_LOGINHISTORY (CODE, LOGINID, LOGINNAME, UCODE, OCODE, ONAME, LOGINDT, ORGID, USERID, DEVICETYPE)
VALUES('{guid}', '{appInfo.LoginID}', '{appInfo.UserName}', '{appInfo.UCode.Replace("NG", "")}', '{appInfo.OCode}', '{appInfo.OrgName}', '{DateTime.Now}',{appInfo.OrgID},{appInfo.UserID},1)";
                break;
            }
            if (!string.IsNullOrEmpty(sql))
            {
                try
                {
                    DbHelper.Open();
                    DbHelper.BeginTran();
                    DbHelper.ExecuteNonQuery(sql);
                    DbHelper.CommitTran();
                }
                catch
                {
                    DbHelper.RollbackTran();
                }
                finally
                {
                    DbHelper.Close();
                }
            }
            return(guid);
        }
Esempio n. 2
0
        public static void MyClassInitialize(TestContext testContext)
        {
            HttpSimulator hs = new HttpSimulator("/", @"E:\Enterprise\Enterprise3\Enterprise3.Test\Enterprise3.NHORM.Test");

            hs.SimulateRequest();

            I6WebAppInfo appInfo = new I6WebAppInfo
            {
                UserType          = UserType.OrgUser,
                PubConnectString  = ConfigHelper.GetString("PubConnectString"),
                UserConnectString = ConfigHelper.GetString("UserConnectString"),
                LoginID           = "007",
                UserName          = "******",
                OCode             = "001",
                OrgName           = "001组织",
                UCode             = "NG0003" //Northwind
            };

            //MockHttpContext.Init();

            System.Web.HttpContext.Current.Session["NGWebAppInfo"] = appInfo;
            ConnectionInfoService.SetSessionConnectString(ConfigHelper.GetString("UserConnectString"));
        }
Esempio n. 3
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="requestContext">请求上下文</param>
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            var isSso = System.Web.HttpContext.Current.Request.Params["issso"] == null ? "" : System.Web.HttpContext.Current.Request.Params["issso"].ToString();

            if (isSso == "1")
            {
                var logId   = System.Web.HttpContext.Current.Request.Params["logno"] == null ? "" : System.Web.HttpContext.Current.Request.Params["logno"].ToString();
                var logName = System.Web.HttpContext.Current.Request.Params["logname"] == null ? "" : System.Web.HttpContext.Current.Request.Params["logname"].ToString();
                var oCode   = System.Web.HttpContext.Current.Request.Params["ocode"] == null ? "" : System.Web.HttpContext.Current.Request.Params["ocode"].ToString();
                var uCode   = System.Web.HttpContext.Current.Request.Params["ucode"] == null ? "" : System.Web.HttpContext.Current.Request.Params["ucode"].ToString();

                //comment by ljy 2018.01.17 特变要求预览能跟正式发布单据一样操作
                //ViewBag.IsSso = "true";
                ViewBag.IsSso = "false";

                try
                {
                    //设置NG3的i6WebInfoBase对象
                    var dbbuilder = new DBConnectionStringBuilder();
                    var dbName    = string.Empty;

                    //没有传帐套号过来
                    if (string.IsNullOrWhiteSpace(uCode))
                    {
                        dbName = dbbuilder.DefaultDB;  //如NG0001
                        uCode  = dbName.Substring(2);  //如0001
                    }
                    else
                    {
                        dbName = "NG" + uCode;
                    }

                    var result   = string.Empty;
                    var pubConn  = dbbuilder.GetMainConnStringElement(0, out result, false);          //获取主数据库连接串 NGSoft
                    var userConn = dbbuilder.GetAccConnstringElement(0, dbName, pubConn, out result); //获取默认数据库连接串 NG0001

                    var i6AppInfo = new I6WebAppInfo()
                    {
                        UserType          = UserType.OrgUser,
                        PubConnectString  = pubConn,
                        UserConnectString = userConn,
                        LoginID           = logId,
                        UserName          = logName,
                        OCode             = oCode,
                        UCode             = uCode,
                        DbName            = dbName,
                        UserID            = Convert.ToInt64(DbHelper.GetString(userConn, string.Format("select phid from fg3_user where userno='{0}'", logId))),
                        OrgID             = Convert.ToInt64(DbHelper.GetString(userConn, string.Format("select phid from fg_orglist where ocode='{0}'", oCode)))
                    };

                    System.Web.HttpContext.Current.Session["NGWebAppInfo"] = i6AppInfo;
                    ConnectionInfoService.SetSessionConnectString(i6AppInfo.UserConnectString);
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message); //应该加入日志,设置i6WebAppInfo异常。
                }
            }

            base.Initialize(requestContext);

            //调老丰AFCommonController的InitialAF(),里面含WorkFlowHandling()
            string dbnameStr = NG3.AppInfoBase.DbName;

            if (string.IsNullOrWhiteSpace(dbnameStr))
            {
                dbnameStr = base.NGPreCompileHandling();
            }
            base.InitialAF(dbnameStr);
        }
Esempio n. 4
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="svrName">数据库服务器名</param>
        /// <param name="account">帐套</param>
        /// <param name="logid">登录id</param>
        /// <param name="pwd">密码</param>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public bool Login(string svrName, string account, string logid, string pwd, ref string msg)
        {
            string result;
            DBConnectionStringBuilder dbbuilder = new DBConnectionStringBuilder();
            string pubConn  = string.Empty;
            string userConn = string.Empty;

            if (string.IsNullOrWhiteSpace(svrName))
            {
                pubConn = dbbuilder.GetMainConnStringElement(0, out result, false);//取第一个(默认)服务器
            }
            else
            {
                pubConn = dbbuilder.GetMainConnStringElement(svrName, out result);
            }

            if (string.IsNullOrWhiteSpace(account))
            {
                userConn = dbbuilder.GetDefaultConnString();//取默认连接串
            }
            else
            {
                userConn = dbbuilder.GetAccConnstringElement(svrName, account, pubConn, out result);
            }

            I6WebAppInfo appInfo = new I6WebAppInfo();

            appInfo.UserType = UserType.OrgUser;

            #region 校验用户是否存在

            object obj = DbHelper.ExecuteScalar(userConn, string.Format("select count(logid) from secuser where logid='{0}'", logid));
            if (obj == null || obj == DBNull.Value || obj.ToString() == "0")
            {
                //检测系统管理员
                obj = DbHelper.ExecuteScalar(pubConn, string.Format("select count(cname) from ngrights where cname='{0}'", logid));
                if (obj == null || obj == DBNull.Value || obj.ToString() == "0")
                {
                    //this.SetErrMsg(ps, "不存在该用户!");
                    //return false;

                    msg = "不存在该用户!";
                    return(false);
                }
                else
                {
                    appInfo.UserType = SUP.Common.Base.UserType.System;
                }
            }
            #endregion

            #region 用户状态
            string sql = "select status from secuser where logid='" + logid + "'";
            string ret = DbHelper.GetString(userConn, sql);

            if (ret == "1")
            {
                msg = "用户已锁定,请联系系统管理员!";
                return(false);
            }
            #endregion

            #region 校验密码


            if (UserType.OrgUser == appInfo.UserType)
            {
                obj = DbHelper.ExecuteScalar(userConn, string.Format("select pwd from secuser where logid='{0}'", logid));
            }
            else
            {
                obj = DbHelper.ExecuteScalar(pubConn, string.Format("select cpwd from ngrights where cname='{0}'", logid));
            }

            if (string.IsNullOrEmpty(pwd))
            {
                if (obj != null && obj != DBNull.Value)
                {
                    if (obj.ToString().Length > 0)
                    {
                        msg = "密码不正确";
                        return(false);
                    }
                }
            }
            else
            {
                if (obj == null || obj == DBNull.Value)
                {
                    msg = "密码不正确";
                    return(false);
                }
                else
                {
                    string dbpwd = NG3.NGEncode.DecodePassword(obj.ToString(), 128);
                    if (dbpwd.Equals(pwd) == false)
                    {
                        msg = "密码不正确";
                        return(false);
                    }
                }
            }

            #endregion

            return(true);
        }
Esempio n. 5
0
 public string SetLoginUsers(I6WebAppInfo appInfo)
 {
     return(dac.SetLoginUsers(appInfo));
 }
Esempio n. 6
0
 public string WebCheck(out string msg, out bool loginflag, string svrName, string account, string logid, string pwd, I6WebAppInfo appInfo, string isOnlineCheck)
 {
     return(rule.WebCheck(out msg, out loginflag, svrName, account, logid, pwd, appInfo, isOnlineCheck));
 }
Esempio n. 7
0
        public void Check(ref string msg, ref bool loginflag, string svrName, string account, string logid, string pwd)
        {
            string result;
            DBConnectionStringBuilder dbbuilder = new DBConnectionStringBuilder();
            string pubConn  = string.Empty;
            string userConn = string.Empty;


            if (string.IsNullOrWhiteSpace(svrName))
            {
                pubConn = dbbuilder.GetMainConnStringElement(0, out result, false);//取第一个(默认)服务器
            }
            else
            {
                pubConn = dbbuilder.GetMainConnStringElement(svrName, out result);
            }

            if (string.IsNullOrWhiteSpace(account))
            {
                userConn = dbbuilder.GetDefaultConnString();//取默认连接串
            }
            else
            {
                userConn = dbbuilder.GetAccConnstringElement(svrName, account, pubConn, out result);
            }

            I6WebAppInfo appInfo = new I6WebAppInfo();

            appInfo.UserType = UserType.OrgUser;


            #region 用户状态

            string sql = "select status from secuser where logid='" + logid + "'";
            string ret = DbHelper.GetString(userConn, sql);

            if (ret == "1")
            {
                msg       = "用户[" + logid + "]已锁定,请联系系统管理员!";
                loginflag = false;
                return;
            }

            int sysErrortimes     = this.dac.GetSysErrTimes(userConn);//系统定义出错次数
            int currentErrorTimes = this.dac.GetErrTimes(logid, userConn);

            if (currentErrorTimes == sysErrortimes)
            {
                this.dac.SetUserStateOff(logid, userConn);//锁定用户
                msg       = "用户[" + logid + "]已锁定,请联系系统管理员!";
                loginflag = false;
                return;
            }

            #endregion

            string username = string.Empty;
            //校验用户
            object obj = DbHelper.ExecuteScalar(userConn, string.Format("select count(logid) from secuser where logid='{0}'", logid));
            if (obj == null || obj == DBNull.Value || obj.ToString() == "0")
            {
                //检测系统管理员
                obj = DbHelper.ExecuteScalar(pubConn, string.Format("select count(cname) from ngrights where cname='{0}'", logid));
                if (obj == null || obj == DBNull.Value || obj.ToString() == "0")
                {
                    //this.SetErrMsg(ps, "不存在该用户!");
                    //return false;

                    msg       = "用户名或密码错误!";//"不存在该用户!";
                    loginflag = false;
                    this.dac.AddErrTimes(logid, userConn);
                    return;
                }
                else
                {
                    appInfo.UserType = SUP.Common.Base.UserType.System;
                }
                username = logid;
            }
            else
            {
                string usernameSql = string.Format("select u_name from secuser where logid='{0}'", logid);
                username = DbHelper.GetString(userConn, usernameSql);
            }


            #region 校验密码


            if (UserType.OrgUser == appInfo.UserType)
            {
                obj = DbHelper.ExecuteScalar(userConn, string.Format("select pwd from secuser where logid='{0}'", logid));
            }
            else
            {
                obj = DbHelper.ExecuteScalar(pubConn, string.Format("select cpwd from ngrights where cname='{0}'", logid));
            }

            if (string.IsNullOrEmpty(pwd))
            {
                if (obj != null && obj != DBNull.Value)
                {
                    if (obj.ToString().Length > 0)
                    {
                        msg       = "用户名或密码错误!";//"密码不正确";
                        loginflag = false;
                        this.dac.AddErrTimes(logid, userConn);
                        return;
                    }
                }
            }
            else
            {
                if (obj == null || obj == DBNull.Value)
                {
                    msg       = "用户名或密码错误!"; //"密码不正确";
                    loginflag = false;
                    this.dac.AddErrTimes(logid, userConn);
                    return;
                }
                else
                {
                    string dbpwd = NG3.NGEncode.DecodePassword(obj.ToString(), 128);
                    if (dbpwd.Equals(pwd) == false)
                    {
                        msg       = "用户名或密码错误!";//"密码不正确";
                        loginflag = false;
                        this.dac.AddErrTimes(logid, userConn);
                        return;
                    }
                }
            }

            #endregion

            //错误次数清零
            this.dac.ClearErr(logid, userConn);

            //普通用户,获取组织
            string ocode = string.Empty;
            if (UserType.System != appInfo.UserType)
            {
                ocode = DbHelper.ExecuteScalar(userConn, string.Format("select lastloginorg from secuser where logid='{0}'", logid)).ToString();

                if (string.IsNullOrWhiteSpace(ocode))
                {
                    sql = "select ocode from fg_orglist";
                    DataTable dt = DbHelper.GetDataTable(userConn, sql);

                    if (dt.Rows.Count > 0)
                    {
                        ocode = dt.Rows[0]["ocode"].ToString();//取第一个组织作为默认组织
                    }
                }
            }

            #region 在线用户

            //string message = this.CheckUserOnline(logid, account, string.Empty);
            string message = this.CheckTheSameSessionUser(logid);
            if (!string.IsNullOrEmpty(message))
            {
                msg       = message;
                loginflag = false;
                return;
            }

            #endregion

            appInfo.PubConnectString  = pubConn;
            appInfo.UserConnectString = userConn;
            appInfo.LoginID           = logid;
            appInfo.UserName          = username;
            appInfo.OCode             = ocode;
            appInfo.UCode             = account;
            appInfo.UserID            = Convert.ToInt64(DbHelper.GetString(userConn, string.Format("select phid from fg3_user where userno='{0}'", logid)));
            appInfo.OrgID             = Convert.ToInt64(DbHelper.GetString(userConn, string.Format("select phid from fg_orglist where ocode='{0}'", ocode)));

            System.Web.HttpContext.Current.Session[UPAppInfoNameInSession] = appInfo;
            NG3.Data.Service.ConnectionInfoService.SetSessionConnectString(appInfo.UserConnectString);//初始化2.0的dbhelper
        }
Esempio n. 8
0
        /// <summary>
        /// 校验用户
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="loginflag"></param>
        /// <param name="svrName"></param>
        /// <param name="database"></param>
        /// <param name="logid"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public string WebCheck(out string msg, out bool loginflag, string svrName, string database, string logid, string pwd, I6WebAppInfo appInfo, string isOnlineCheck)
        {
            msg = string.Empty;
            string pubConn   = string.Empty;
            string userConn  = string.Empty;
            var    dbbuilder = LoginDac.GetAcountDBConnectString(svrName, database, out pubConn, out userConn);

            appInfo.UserType = UserType.OrgUser;

            #region 用户状态

            string sql = "select status from fg3_user where userno = '" + logid + "'";
            string ret = DbHelper.GetString(userConn, sql);

            if (ret == "3")
            {
                msg       = "用户[" + logid + "]已锁定,请联系系统管理员!";
                loginflag = false;
                return(string.Empty);
            }

            int sysErrortimes     = dac.GetSysErrTimes(userConn);//系统定义出错次数
            int currentErrorTimes = dac.GetErrTimes(logid, userConn);

            if (currentErrorTimes == sysErrortimes)
            {
                dac.SetUserStateOff(logid, userConn);//锁定用户
                msg       = "用户[" + logid + "]已锁定,请联系系统管理员!";
                loginflag = false;
                return(string.Empty);
            }

            #endregion

            #region 校验用户

            string username = string.Empty;
            object obj      = DbHelper.ExecuteScalar(userConn, string.Format("select count(userno) from fg3_user where userno = '{0}'", logid));
            if (obj == null || obj == DBNull.Value || obj.ToString() == "0")
            {
                //检测系统管理员
                obj = DbHelper.ExecuteScalar(pubConn, string.Format("select count(cname) from ngrights where cname = '{0}'", logid));
                if (obj == null || obj == DBNull.Value || obj.ToString() == "0")
                {
                    msg       = "不存在该用户!";
                    loginflag = false;
                    return(string.Empty);
                }
                else
                {
                    appInfo.UserType = UserType.System;
                }
                username = logid;
            }
            else
            {
                string usernameSql = string.Format("select username from fg3_user where userno = '{0}'", logid);
                username = DbHelper.GetString(userConn, usernameSql);
            }

            #endregion

            #region 校验密码

            if (UserType.OrgUser == appInfo.UserType)
            {
                obj = DbHelper.ExecuteScalar(userConn, string.Format("select pwd from fg3_user where userno = '{0}'", logid));
            }
            else
            {
                obj = DbHelper.ExecuteScalar(pubConn, string.Format("select cpwd from ngrights where cname = '{0}'", logid));
            }

            if (string.IsNullOrEmpty(pwd))
            {
                if (obj != null && obj != DBNull.Value)
                {
                    if (obj.ToString().Length > 0)
                    {
                        msg       = "密码不正确!";
                        loginflag = false;
                        return(string.Empty);
                    }
                }
            }
            else
            {
                if (obj == null || obj == DBNull.Value)
                {
                    msg       = "密码不正确!";
                    loginflag = false;
                    return(string.Empty);
                }
                else
                {
                    string dbpwd = NG3.NGEncode.DecodePassword(obj.ToString(), 128);
                    if (dbpwd.Equals(pwd) == false)
                    {
                        msg       = "密码不正确!";
                        loginflag = false;
                        return(string.Empty);
                    }
                }
            }

            //错误次数清零
            dac.ClearErr(logid, userConn);

            #endregion

            #region 系统维护通知

            if (appInfo.UserType != UserType.System)
            {
                DataTable dt = PubCommonDac.Instance.GetSysMaintainCall(pubConn);
                if (dt.Rows.Count > 0)
                {
                    string   userID      = PubCommonDac.Instance.GetUserId(userConn, logid);
                    string   allowlogin  = dt.Rows[0]["allowlogin"].ToString();
                    string[] allowlogins = allowlogin.Split(';');
                    bool     flag        = true;
                    string   ucode       = !string.IsNullOrWhiteSpace(database) ? database : new DBConnectionStringBuilder().DefaultDB.Replace("NG", "");
                    for (int i = 0; i < allowlogins.Length - 1; i++)
                    {
                        if (ucode == allowlogins[i].Split('|')[0] && userID == allowlogins[i].Split('|')[1])
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        msg       = "系统维护中,预计维护结束时间为" + dt.Rows[0]["preenddate"] + "。" + dt.Rows[0]["runinfo"];
                        loginflag = false;
                        return(string.Empty);
                    }
                }
            }

            #endregion

            #region 普通用户,获取组织
            string ocode    = string.Empty;
            string oname    = string.Empty;
            var    loginorg = string.Empty;
            if (UserType.System != appInfo.UserType)
            {
                var strLoginOrg = DbHelper.ExecuteScalar(userConn, string.Format("select lastloginorg from fg3_user where userno = '{0}'", logid));
                loginorg = strLoginOrg == null ? string.Empty : strLoginOrg.ToString();
            }
            if (!string.IsNullOrWhiteSpace(loginorg) && loginorg != "0")
            {
                sql = $"select ocode,oname from fg_orglist where phid = {loginorg}";
                DataTable dt = DbHelper.GetDataTable(userConn, sql);

                if (dt.Rows.Count > 0)
                {
                    ocode = dt.Rows[0]["ocode"].ToString();//取第一个组织作为默认组织
                    oname = dt.Rows[0]["oname"].ToString();
                }
            }
            else
            {
                msg = appInfo.UserType == UserType.System ? "" : "UserNoHaveOrg";//找不到用户最后一次的登录
            }
            #endregion

            #region 在线用户

            string message = CheckTheSameSessionUser(logid);
            if (!string.IsNullOrEmpty(message))
            {
                msg       = message;
                loginflag = false;
                return(string.Empty);
            }

            string uCode = !string.IsNullOrWhiteSpace(database) ? database : dbbuilder.DefaultDB;
            if (isOnlineCheck != "1")
            {
                message = CheckUserOnline(logid, uCode.Replace("NG", ""), string.Empty);
                if (!string.IsNullOrEmpty(message))
                {
                    msg       = message;
                    loginflag = false;
                    return(string.Empty);
                }
            }

            #endregion

            appInfo.PubConnectString  = pubConn;
            appInfo.UserConnectString = userConn;
            appInfo.LoginID           = logid;
            appInfo.UserName          = username;
            appInfo.OCode             = ocode;
            appInfo.OrgName           = oname;
            appInfo.UCode             = uCode;
            appInfo.UserID            = appInfo.UserType == UserType.System ? 0 : Convert.ToInt64(DbHelper.GetString(userConn, string.Format("select phid from fg3_user where userno = '{0}'", logid)));
            long orgid = 0;
            long.TryParse(loginorg, out orgid);
            appInfo.OrgID = orgid;
            loginflag     = true;
            return(userConn);
        }