Example #1
0
        /// <summary>
        /// 登录异常,回到登录页
        /// </summary>
        /// <param name="message"></param>
        private void OnLoginFailureNavigate(ExamScoreNavigateMessage message)
        {
            foreach (var subUCItem in _mainQsContent.Children)
            {
                var subUC = subUCItem as FrameworkElement;
                var subVM = subUC.DataContext as QsBaseViewModel;

                subVM.CleanUp();
            }

            DialogHost.CloseAllShow();

            LoginFailure();
        }
Example #2
0
        /// <summary>
        /// Web 代理(提供 Api 请求操作)。
        /// </summary>
        /// <typeparam name="T">Api 请求的参数对象类型。</typeparam>
        /// <param name="model">Api 请求的参数对象。</param>
        /// <param name="apiType">Api 请求的类型。</param>
        /// <param name="accessToken">访问令牌。</param>
        /// <returns>Api 响应对象。</returns>
        public RespCode WebProxy <T>(T model, ApiType apiType, string accessToken = null, string _Method = "Post")
        {
            var result = WebApiProxy.GetHtmlRespInfo(model, apiType, accessToken, _Method);

            // 验证错误码
            if (result?.retCode == 4001)
            {
                var windows     = Application.Current.Windows;
                var loginWondow = new Window();
                var mainWondow  = new Window();
                foreach (Window window in windows)
                {
                    if (window.Name == "ml")
                    {
                        loginWondow = window;
                    }

                    if (window.Name == "MetroWindowMain")
                    {
                        mainWondow = window;
                    }
                }

                GlobalUser.LoginWin = loginWondow;

                loginWondow.Show();
                loginWondow.Focus();

                DialogHost.CloseAllShow();

                mainWondow.Hide();
                //mainWondow.Close();

                GlobalUser.MainWin?.Hide();
                //GlobalUser.MainWin?.Close();
                GlobalUser.MainWin = null;

                GlobalUser.LoginExpired = true;
                GlobalUser.AutoLoggedIn = false;
                GlobalUser.USER         = null;
                LoginExpired(loginWondow);
                //return;
            }

            return(result);
        }
Example #3
0
        public void LoginFailure()
        {
            var windows     = Application.Current.Windows;
            var loginWondow = new Window();
            var mainWondow  = new Window();

            foreach (Window window in windows)
            {
                if (window.Name == "ml")
                {
                    loginWondow = window;
                }

                if (window.Name == "MetroWindowMain")
                {
                    mainWondow = window;
                }
            }

            mainWondow.Hide();
            //mainWondow.Close();
            GlobalUser.MainWin?.Hide();

            DialogHost.CloseAllShow();
            //GlobalUser.MainWin?.Close();
            mainWondow         = null;
            GlobalUser.MainWin = null;
            ClearMemory();
            GlobalUser.LoginWin             = loginWondow;
            GlobalUser.LoginWin.DataContext = new MainLoginVM(false);
            GlobalUser.LoginWin.Show();
            GlobalUser.LoginWin.Focus();

            GlobalUser.LoginExpired = true;
            GlobalUser.AutoLoggedIn = false;
            //GlobalUser.USER = null;
            LoginExpired(loginWondow);
        }
Example #4
0
        /// <summary>
        /// 注销
        /// </summary>
        protected void Loginout()
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                //var logoutResult = WebProxy(ApiType.UserLogout, GlobalUser.USER.AccessToken);//暂时 不用调用接口  移除token记录

                string userFolder   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalUser.DATAFOLDER);
                string userDataFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalUser.DATAFOLDER,
                                                   $"user.dat");
                GlobalUser.USER.Token       = "";
                UserDataModel userDataModel = new UserDataModel
                {
                    AccessToken = "",
                    UserName    = GlobalUser.USER.UserName,
                    Phone       = GlobalUser.USER.Mobile,
                    Avatar      = GlobalUser.USER.Avatar,
                    Password    = GlobalUser.USER.Password,
                    Data        = GlobalUser.USER,
                    ClassData   = GlobalUser.CLASSINFO,
                    UserZy      = GlobalUser.USER.UserZy,
                    StudyCard   = GlobalUser.STUDYCARD,
                    UnFirstOpen = GlobalUser.USER.UnFirstOpen,
                };
                GlobalUser.USER    = null;
                string userEncoded =
                    Base64Provider.AESEncrypt(userDataModel.ToJsonItem(), Base64Provider.KEY, Base64Provider.IV);
                try
                {
                    if (!Directory.Exists(userFolder))
                    {
                        Directory.CreateDirectory(userFolder);
                    }

                    if (!File.Exists(userDataFile))
                    {
                        var file = File.Create(userDataFile);
                        file.Close();
                        file.Dispose();
                    }

                    using (StreamWriter sw = new StreamWriter(userDataFile, false))
                    {
                        sw.Write(userEncoded);
                    }
                }
                catch (Exception e)
                {
                    Log4NetHelper.Error("写入用户信息异常:", e);
                }

                DialogHost.CloseAllShow();

                {
                    Log_Data log   = new Log_Data();
                    log.log_desc   = Log_Type.PC_Logout.ToString();
                    log.log_text   = $"注销:{GlobalUser.USER?.Mobile}";
                    log.log_device = JsonHelper.ToJson(GlobalUser.MACHINEINFO.GetDevice());
                    WebApiProxy.GetHtmlRespInfo(log, ApiType.SysLog, null, "Post");
                }

                GlobalUser.MainWin?.Hide();
                GlobalUser.MainWin = null;
                //GlobalUser.MainWin?.Close();

                ClearMemory();

                GlobalUser.AutoLoggedIn        = false;
                GlobalUser.MainWin             = new MainLogin();
                GlobalUser.MainWin.DataContext = new MainLoginVM(false);
                GlobalUser.MainWin.Show();
                GlobalUser.MainWin.Focus();

                //_metroWindow.Hide();
                //_metroWindow.Close();
                //_metroWindow = null;
            }));
        }