コード例 #1
0
ファイル: AccountController.cs プロジェクト: sichiwa/EPS
        public ActionResult Login(LoginInfo model)
        {
            //初始化系統參數
            Configer.Init();

            AD             AD           = new AD();
            VA             VA           = new VA();
            LoginProcessor LP           = new LoginProcessor();
            bool           UseCertLogin = false;
            string         LDAPName     = Configer.LDAPName;
            //string VAVerifyURL = WebConfigurationManager.AppSettings["VAVerifyURL"];
            //string ConnStr = Configer.C_DBConnstring;
            Boolean ContinueLogin = true;

            //Log記錄用
            SYSTEMLOG SL = new SYSTEMLOG();

            SL.UId           = model.UserID;
            SL.Controller    = "Account";
            SL.Action        = "Login";
            SL.StartDateTime = DateTime.Now;
            SL.TotalCount    = 1;

            string        MailServer     = Configer.MailServer;
            int           MailServerPort = Configer.MailServerPort;
            string        MailSender     = Configer.MailSender;
            List <string> MailReceiver   = Configer.MailReceiver;

            //string SendResult = string.Empty;

            if (ModelState.IsValid)
            {
                if (LDAPName == "")
                {
                    //缺少系統參數,需記錄錯誤
                    SL.EndDateTime  = DateTime.Now;
                    SL.SuccessCount = 0;
                    SL.FailCount    = 1;
                    SL.Msg          = "登入作業失敗,錯誤訊息:[缺少系統參數LDAPName]";
                    SL.Result       = false;
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                    ContinueLogin = false;
                }
                if (ContinueLogin)
                {
                    AD.UserName  = model.UserID;
                    AD.Pwd       = model.Pwd;
                    AD.validType = AD.ValidType.Domain;
                    AD.LDAPName  = LDAPName;

                    //VA.SignData = model.SignData;
                    //VA.Plaintext = model.Plaintext;
                    //VA.txnCode = "TxnCode";
                    //VA.VAVerifyURL = VAVerifyURL;
                    //VA.Tolerate = 120;

                    DateTime LoginStartTime = DateTime.Now;
                    SF.logandshowInfo("登入開始@" + LoginStartTime.ToString(Configer.SystemDateTimeFormat), log_Info);
                    bool     LoginResult  = LP.DoLogin(UseCertLogin, AD, VA);
                    DateTime LoginEndTime = DateTime.Now;
                    SF.logandshowInfo("登入結束@" + LoginEndTime.ToString(Configer.SystemDateTimeFormat), log_Info);
                    string LoginSpanTime = OtherProcesser.TimeDiff(LoginStartTime, LoginEndTime, "Milliseconds");
                    SF.logandshowInfo("本次登入共花費@" + LoginSpanTime + "毫秒", log_Info);

                    if (LoginResult == true)
                    {
                        //登入成功,需紀錄
                        SL.EndDateTime  = DateTime.Now;
                        SL.SuccessCount = 1;
                        SL.FailCount    = 0;
                        SL.Msg          = "登入成功";
                        SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                        Session["UseCertLogin"] = UseCertLogin;
                        //Session["UseCertLogin"] = true;
                        Session["UserID"] = model.UserID;
                        //Session["UserID"] = "TAS191";
                        int UserRole = SF.getUserRole(model.UserID);
                        Session["UserRole"] = UserRole;

                        //主管導向覆核頁面
                        if (UserRole > 3)
                        {
                            return(RedirectToAction("Index", "Review"));
                        }
                        else
                        {
                            //導向檢查頁面
                            return(RedirectToAction("Index", "Process"));
                        }
                    }
                    else
                    {
                        //string a=VA.ResultStr;

                        //登入失敗,需記錄錯誤
                        SL.EndDateTime = DateTime.Now;
                        SL.FailCount   = 1;
                        if (UseCertLogin)
                        {
                            SL.Msg = "登入失敗,錯誤訊息:[AD或VA驗證失敗]";
                        }
                        else
                        {
                            SL.Msg = "登入失敗,錯誤訊息:[AD驗證失敗]";
                        }
                        SL.Result = false;
                        SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                        TempData["LoginMsg"] = SL.Msg;

                        return(RedirectToAction("Login", "Account"));
                    }
                }
                else
                {
                    TempData["LoginMsg"] = "登入失敗,錯誤訊息:[系統登入參數遺失]";
                    return(RedirectToAction("Login", "Account"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: sichiwa/EPS
        public ActionResult Login(LoginInfo model)
        {
            //初始化系統參數
            Configer.Init();

            AD AD = new AD();
            VA VA = new VA();
            LoginProcessor LP = new LoginProcessor();
            bool UseCertLogin = false;
            string LDAPName = Configer.LDAPName;
            //string VAVerifyURL = WebConfigurationManager.AppSettings["VAVerifyURL"];
            //string ConnStr = Configer.C_DBConnstring;
            Boolean ContinueLogin = true;

            //Log記錄用
            SYSTEMLOG SL = new SYSTEMLOG();
            SL.UId = model.UserID;
            SL.Controller = "Account";
            SL.Action = "Login";
            SL.StartDateTime = DateTime.Now;
            SL.TotalCount = 1;

            string MailServer = Configer.MailServer;
            int MailServerPort = Configer.MailServerPort;
            string MailSender = Configer.MailSender;
            List<string> MailReceiver = Configer.MailReceiver;
            //string SendResult = string.Empty;

            if (ModelState.IsValid)
            {
                if (LDAPName == "")
                {
                    //缺少系統參數,需記錄錯誤
                    SL.EndDateTime = DateTime.Now;
                    SL.SuccessCount = 0;
                    SL.FailCount = 1;
                    SL.Msg = "登入作業失敗,錯誤訊息:[缺少系統參數LDAPName]";
                    SL.Result = false;
                    SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                    ContinueLogin = false;
                }
                if (ContinueLogin)
                {
                    AD.UserName = model.UserID;
                    AD.Pwd = model.Pwd;
                    AD.validType = AD.ValidType.Domain;
                    AD.LDAPName = LDAPName;

                    //VA.SignData = model.SignData;
                    //VA.Plaintext = model.Plaintext;
                    //VA.txnCode = "TxnCode";
                    //VA.VAVerifyURL = VAVerifyURL;
                    //VA.Tolerate = 120;

                    DateTime LoginStartTime = DateTime.Now;
                    SF.logandshowInfo("登入開始@" + LoginStartTime.ToString(Configer.SystemDateTimeFormat), log_Info);
                    bool LoginResult = LP.DoLogin(UseCertLogin, AD, VA);
                    DateTime LoginEndTime = DateTime.Now;
                    SF.logandshowInfo("登入結束@" + LoginEndTime.ToString(Configer.SystemDateTimeFormat), log_Info);
                    string LoginSpanTime = OtherProcesser.TimeDiff(LoginStartTime, LoginEndTime, "Milliseconds");
                    SF.logandshowInfo("本次登入共花費@" + LoginSpanTime + "毫秒", log_Info);

                    if (LoginResult == true)
                    {
                        //登入成功,需紀錄
                        SL.EndDateTime = DateTime.Now;
                        SL.SuccessCount = 1;
                        SL.FailCount = 0;
                        SL.Msg = "登入成功";
                        SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                        Session["UseCertLogin"] = UseCertLogin;
                        //Session["UseCertLogin"] = true;
                        Session["UserID"] = model.UserID;
                        //Session["UserID"] = "TAS191";
                        int UserRole= SF.getUserRole(model.UserID);
                        Session["UserRole"] = UserRole;

                        //主管導向覆核頁面
                        if (UserRole > 3)
                        {
                            return RedirectToAction("Index", "Review");
                        }
                        else
                        {
                            //導向檢查頁面
                            return RedirectToAction("Index", "Process");
                        }
                    }
                    else
                    {
                        //string a=VA.ResultStr;

                        //登入失敗,需記錄錯誤
                        SL.EndDateTime = DateTime.Now;
                        SL.FailCount = 1;
                        if (UseCertLogin)
                        {
                            SL.Msg = "登入失敗,錯誤訊息:[AD或VA驗證失敗]";
                        }
                        else
                        {
                            SL.Msg = "登入失敗,錯誤訊息:[AD驗證失敗]";
                        }
                        SL.Result = false;
                        SF.log2DB(SL, MailServer, MailServerPort, MailSender, MailReceiver);
                        TempData["LoginMsg"] = SL.Msg;

                        return RedirectToAction("Login", "Account");
                    }
                }
                else
                {
                    TempData["LoginMsg"] = "登入失敗,錯誤訊息:[系統登入參數遺失]";
                    return RedirectToAction("Login", "Account");
                }
            }
            else
            {
                return RedirectToAction("Login", "Account");
            }
        }