Exemple #1
0
        public void RememberUser(string userName, string phone, string accessToken)
        {
            string        userFolder    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalUser.DATAFOLDER);
            string        userDataFile  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalUser.DATAFOLDER, $"user.dat");
            UserDataModel userDataModel = new UserDataModel
            {
                UserName    = userName,
                Phone       = phone,
                AccessToken = accessToken,
                Data        = GlobalUser.USER
            };

            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();
                }
                using (StreamWriter sw = new StreamWriter(userDataFile, false))
                {
                    sw.Write(userEncoded);
                }
            }
            catch (Exception e)
            {
                Log4NetHelper.Error(" MainViewModelBase.OpenUserInfoDialog写入用户信息异常:", e);
            }
        }
Exemple #2
0
        private void LogoutEventHandler(object sender, DialogClosingEventArgs eventArgs)
        {
            if ((bool)eventArgs.Parameter == false)
            {
                return;
            }

            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");

                UserDataModel userDataModel = new UserDataModel
                {
                    UserName    = GlobalUser.USER.UserName,
                    Phone       = GlobalUser.USER.Moblie,
                    AccessToken = "",
                    Data        = new UserInfo()
                };
                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();
                    }
                    using (StreamWriter sw = new StreamWriter(userDataFile, false))
                    {
                        sw.Write(userEncoded);
                    }
                }
                catch (Exception e)
                {
                    Log4NetHelper.Error("写入用户信息异常:", e);
                }

                var winLogin = new MainLogin();
                winLogin.Show();
                winLogin.Focus();

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

                //_metroWindow.Hide();
                //_metroWindow.Close();
                //_metroWindow = null;
            }));
        }
Exemple #3
0
        public void RememberUser()
        {
            string        userFolder    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalUser.DATAFOLDER);
            string        userDataFile  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GlobalUser.DATAFOLDER, $"user.dat");
            UserDataModel userDataModel = new UserDataModel
            {
                UserName    = GlobalUser.USER.UserName,
                Phone       = GlobalUser.USER.Mobile,
                Avatar      = GlobalUser.USER.Avatar,
                AccessToken = GlobalUser.USER.Token,
                Password    = GlobalUser.USER.Password,
                Data        = GlobalUser.USER,
                ClassData   = GlobalUser.CLASSINFO,
                UserZy      = GlobalUser.USER.UserZy,
                StudyCard   = GlobalUser.STUDYCARD,
                GradeData   = GlobalUser.GRADEINFO,
                UnFirstOpen = GlobalUser.USER.UnFirstOpen
            };

            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);
            }
        }
Exemple #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;
            }));
        }