public LUSerLoginResult Login(LoginUserVM entityInst, string str_Language, string str_IpAdd, string str_HostName)
        {
            LUSerLoginResult ret = null;

            ret = _client.Login(entityInst, str_Language, str_IpAdd, str_HostName);
            return(ret);
        }
        public void DoLogin()
        {
            //Test WCF Function
            LoginUserMgtHelper luMgtHelper = new LoginUserMgtHelper(this.commonFixture.postOffice.LoginUserMgtSerPath);

            commonFixture.MockControllerInfo(loginController, "http://localhost:50653/AccessControl/Login/Index");

            loginController.TempData[StaticContent.LanguageKey] = this.commonFixture.LanguageKey;

            loginController.loginUserMgtHelper = new Lazy <LoginUserMgtHelper>(() => luMgtHelper);

            LoginUserVM entity_LUVM = new LoginUserVM();

            entity_LUVM.LoginName = "admin";
            entity_LUVM.LoginPwd  = "123456";

            LUSerLoginResult temp = luMgtHelper.Login(entity_LUVM, LanguageKey.en.ToString(), "", "");

            //Login Success Case
            loginController.Index(entity_LUVM);

            Assert.True(loginController.TempData.ContainsKey(Bootstrapper.UserClientSessionKey.ToString()));

            Assert.True(!loginController.TempData.ContainsKey(loginController.ActionMessageKey) || loginController.TempData[loginController.ActionMessageKey] == null);

            //Login Fail Case
            entity_LUVM = new LoginUserVM();
            ViewResult loginPageResult_Fail = (ViewResult)loginController.Index(entity_LUVM);

            Assert.True(loginPageResult_Fail.ViewData.ContainsKey("ActionMessage"));

            MsgInfo errorMsgInfo = (MsgInfo)loginPageResult_Fail.ViewData["ActionMessage"];

            Assert.True(errorMsgInfo.MsgType == MessageType.ValidationError);
        }
Example #3
0
        public void LoginAndGetToken()
        {
            string str_Token = "";

            LoginUserMgtHelper loginUserMgtHelper = new LoginUserMgtHelper(postOffice.LoginUserMgtSerPath);

            LoginUserVM entity_LUVM = new LoginUserVM();

            entity_LUVM.LoginName = "admin";
            entity_LUVM.LoginPwd  = "123456";

            LUSerLoginResult loginResult = loginUserMgtHelper.Login(entity_LUVM, LanguageKey.ToString(), "", "");

            if (loginResult != null)
            {
                str_Token = loginResult.Str_ServerToken;

                entity_BaseSession = loginResult.Entity_SessionWUserInfo;
            }
            StrToken = str_Token;
        }
Example #4
0
        public ActionResult Index(LoginUserVM loginUserVM)
        {
            //Message Box Title -- When Error occured, Message Box would be showed.
            string str_MsgBoxTitle = MultilingualHelper.GetStringFromResource("LoginScreentTitle");

            ClearSelectionCriteriaFromViewData();

            #region [ Add data into language combo box ]
            if (TempData.Keys.Contains(StaticContent.LanguageKey))
            {
                LanguageKey temp = (LanguageKey)(TempData[StaticContent.LanguageKey]);

                initLanguageComboBox(temp.ToString());
            }
            else
            {
                initLanguageComboBox();
            }
            #endregion

            LUSerLoginResult entity_LUSerLoginResult = new LUSerLoginResult();
            //Define and Create channel factory in order to call the service
            entity_LUSerLoginResult = loginUserMgtHelper.Value.Login(loginUserVM, TempData[StaticContent.LanguageKey].ToString(), UserHostAddress, UserHostName);

            if (entity_LUSerLoginResult != null && entity_LUSerLoginResult.StrList_Error.Count == 0)
            {
                //Clear the cache.
                TempData[ActionMessageKey] = ViewBag.ActionMessage = null;

                //Save login user's authorized info to the cache.
                MVCSessionMgt.SaveServerSideSession(entity_LUSerLoginResult.Entity_SessionWUserInfo, StaticContent.SystemInfoInst.GetSessionTimeOutSeconds());

                //Save service authorized key and client side session key.
                ClientSessionInfo entity_ClientSessionInfo = new ClientSessionInfo();
                if (entity_LUSerLoginResult.Entity_SessionWUserInfo != null)
                {
                    entity_ClientSessionInfo.MVCSessionKey        = entity_LUSerLoginResult.Entity_SessionWUserInfo.SessionKey;
                    entity_ClientSessionInfo.ServiceAuthorizedKey = entity_LUSerLoginResult.Str_ServerToken;

                    Entity_ClientSessionInfo = entity_ClientSessionInfo;

                    TempData[Bootstrapper.UserClientSessionKey.ToString()]     =
                        ViewData[Bootstrapper.UserClientSessionKey.ToString()] = entity_ClientSessionInfo;
                }

                //Check the password is expire or not.
                if (entity_LUSerLoginResult.IsPWDExpire)
                {
                    return(Redirect("/AccessControl/Login/Reset"));
                }
                else
                {
                    return(Redirect("/Home/Index"));
                }
            }

            //Output error.
            MsgInfo errorMsgInfo = new MsgInfo();
            errorMsgInfo.MsgTitle = str_MsgBoxTitle;
            //Retrieve all error message.
            errorMsgInfo.MsgDesc       = string.Join("<br/>", entity_LUSerLoginResult.StrList_Error.ToArray());
            errorMsgInfo.MsgType       = MessageType.ValidationError;
            ViewBag.ActionMessage      = errorMsgInfo;
            TempData[ActionMessageKey] = errorMsgInfo;
            return(View(loginUserVM));
        }
Example #5
0
        public LUSerLoginResult Login(LoginUserVM entityInst, string str_Language, string str_IpAdd, string str_HostName)
        {
            try
            {
                LUSerLoginResult returnResult = new LUSerLoginResult();

                SysParmRespository entityRepository = new SysParmRespository();

                StaticContent.SystemInfoInst = entityRepository.RetrieveSystemInfo();

                LanguageKey languageKey_Input = LanguageKey.en;

                Enum.TryParse <LanguageKey>(str_Language, out languageKey_Input);

                // Login Name cannot be empty
                if (string.IsNullOrWhiteSpace(entityInst.LoginName))
                {
                    string str_E001 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E001");
                    str_E001 = string.Format(str_E001, MultilingualHelper.GetStringFromResource(languageKey_Input, "LoginName"));
                    returnResult.StrList_Error.Add(str_E001);
                }

                // Login Password cannot be empty
                if (string.IsNullOrWhiteSpace(entityInst.LoginPwd))
                {
                    string str_E001 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E001");
                    str_E001 = string.Format(str_E001, MultilingualHelper.GetStringFromResource(languageKey_Input, "LoginPwd"));
                    returnResult.StrList_Error.Add(str_E001);
                }

                if (!string.IsNullOrWhiteSpace(entityInst.LoginName) && !string.IsNullOrWhiteSpace(entityInst.LoginPwd))
                {
                    string str_E008 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E008");
                    str_E008 = string.Format(str_E008, MultilingualHelper.GetStringFromResource(languageKey_Input, "LoginName"), MultilingualHelper.GetStringFromResource(languageKey_Input, "LoginPwd"));

                    string str_E009 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E009");

                    string str_E018 = MultilingualHelper.GetStringFromResource(languageKey_Input, "E018");

                    CoolPrivilegeControlContext dbContext      = CoolPrivilegeControlContext.CreateContext();
                    LoginUserRespository        loginUserRespo = new LoginUserRespository(dbContext, null);

                    LoginUserVM entityVM_exist = loginUserRespo.GetLoginUserInfo(entityInst.LoginName);
                    if (entityVM_exist != null)
                    {
                        PwdPolicy pwdPolicy = new PwdPolicy();

                        if (!entityVM_exist.Status.HasValue || entityVM_exist.Status.Value == 2)
                        {
                            returnResult.StrList_Error.Add(str_E018);
                        }
                        else if (entityVM_exist.Status.HasValue && entityVM_exist.Status.Value == 3)
                        {
                            returnResult.StrList_Error.Add(str_E018);
                        }
                        else
                        {
                            if (entityVM_exist.LoginPwd == pwdPolicy.GetMD5(entityInst.LoginPwd))
                            {
                                DateTime?dt_LastPwdMDT = entityVM_exist.LastPwdMDT;
                                entityVM_exist.FailCount   = 0;
                                entityVM_exist.Status      = 1;
                                entityVM_exist.LastLoginDT = DateTime.Now;
                                entityInst.LastPwdMDT      = entityVM_exist.LastPwdMDT;
                                List <string> strList_UpdateLastLoginDt_Error = new List <string>();
                                loginUserRespo.UpdateLastLoginDt(entityVM_exist, languageKey_Input, ref strList_UpdateLastLoginDt_Error);
                                if (strList_UpdateLastLoginDt_Error.Count > 0)
                                {
                                    foreach (var item in strList_UpdateLastLoginDt_Error)
                                    {
                                        returnResult.StrList_Error.Add(item);
                                    }
                                }
                                else
                                {
                                    AuthorizedHistoryRespository authorityHistoryRespos = new AuthorizedHistoryRespository(dbContext, entityVM_exist.ID);

                                    string str_SaveAuthorizedHistory_Error = "";

                                    //Create Login History
                                    authorityHistoryRespos.Create(new AuthorizedHistoryVM(), languageKey_Input, out str_SaveAuthorizedHistory_Error);

                                    if (!string.IsNullOrWhiteSpace(str_SaveAuthorizedHistory_Error))
                                    {
                                        returnResult.StrList_Error.Add(str_SaveAuthorizedHistory_Error);
                                    }
                                    else
                                    {
                                        string      sessionKey         = Guid.NewGuid().ToString();
                                        BaseSession entity_BaseSession = new BaseSession();
                                        entity_BaseSession.ID              = entityVM_exist.ID;
                                        entity_BaseSession.SessionKey      = sessionKey;
                                        entity_BaseSession.IpAddress       = str_IpAdd;
                                        entity_BaseSession.LastOperationDt = DateTime.Now;

                                        WCFAuthInfoVM entity_WCFAuthInfoVM = new WCFAuthInfoVM(str_IpAdd, str_HostName, "", "", "", "", "");

                                        WCFSesssionPolicy wcfPolicy = new WCFSesssionPolicy();

                                        wcfPolicy.StoreWCFSession(entity_WCFAuthInfoVM, entity_BaseSession);

                                        #region [ Set Client Authorized Info ]
                                        SessionWUserInfo entity_SessionWUserInfo = loginUserRespo.GetLoginUserAccRight(entity_BaseSession.ID);

                                        if (entity_SessionWUserInfo != null)
                                        {
                                            entity_SessionWUserInfo.SessionKey      = Guid.NewGuid().ToString();
                                            entity_SessionWUserInfo.IpAddress       = entity_WCFAuthInfoVM.IpAddress;
                                            entity_SessionWUserInfo.LastOperationDt = DateTime.Now;
                                        }
                                        #endregion

                                        returnResult.Entity_SessionWUserInfo = entity_SessionWUserInfo;

                                        if (entityVM_exist.LastPwdMDT.HasValue)
                                        {
                                            returnResult.IsPWDExpire = entityVM_exist.LastPwdMDT.Value.AddDays(((SystemInfoVM)StaticContent.SystemInfoInst).Password_ExpireDays) <= DateTime.Now.Date;
                                        }

                                        returnResult.Str_ServerToken = entity_WCFAuthInfoVM.WCFAuthorizedKey;
                                    }
                                }
                            }
                            else
                            {
                                List <string> strList_UpdateFailCount_Error = new List <string>();
                                loginUserRespo.UpdateFailCount(entityVM_exist, languageKey_Input, ref strList_UpdateFailCount_Error);

                                returnResult.StrList_Error.Add(str_E008);

                                if (strList_UpdateFailCount_Error.Count > 0)
                                {
                                    foreach (var item in strList_UpdateFailCount_Error)
                                    {
                                        returnResult.StrList_Error.Add(item);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        returnResult.StrList_Error.Add(str_E008);
                    }
                }
                return(returnResult);
            }
            catch (Exception ex)
            {
                throw new FaultException <WCFErrorContract>(new WCFErrorContract(ex), ex.Message);
            }
        }