Beispiel #1
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.main = ((OSKernel.Presentation.Login.LoginWindow)(target));
                return;

            case 2:
                this.btn_back = ((System.Windows.Controls.Button)(target));

            #line 40 "..\..\LoginWindow.xaml"
                this.btn_back.Click += new System.Windows.RoutedEventHandler(this.btn_back_Click);

            #line default
            #line hidden
                return;

            case 3:
                this.btn_extend = ((System.Windows.Controls.Button)(target));

            #line 69 "..\..\LoginWindow.xaml"
                this.btn_extend.Click += new System.Windows.RoutedEventHandler(this.btn_extend_Click);

            #line default
            #line hidden
                return;

            case 4:
                this.btn_close = ((System.Windows.Controls.Button)(target));
                return;

            case 5:
                this.grid_base = ((System.Windows.Controls.Grid)(target));
                return;

            case 6:
                this.txt_email = ((System.Windows.Controls.TextBox)(target));
                return;

            case 7:
                this.pb_password = ((System.Windows.Controls.PasswordBox)(target));
                return;

            case 8:
                this.grid_set = ((System.Windows.Controls.Grid)(target));
                return;
            }
            this._contentLoaded = true;
        }
Beispiel #2
0
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="obj">登录窗口</param>
        void loginCommand(object obj)
        {
            Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            string loginUrl     = cfa.AppSettings.Settings["xy:login.address"].Value;
            string loginPort    = cfa.AppSettings.Settings["xy:login.port"].Value;
            string loginVersion = cfa.AppSettings.Settings["xy:login.version"].Value;
            string loginPath    = $"{loginUrl}:{loginPort}";

            WebAPI.Instance.SetLoginFactory(loginPath, loginVersion);

            LoginWindow win      = obj as LoginWindow;
            string      password = win.pb_password.Password;

            if (string.IsNullOrEmpty(password))
            {
                this.ShowDialog("提示信息", "密码为空!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                return;
            }

            if (string.IsNullOrEmpty(this.UserName))
            {
                this.ShowDialog("提示信息", "用户名不能为空!", CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                return;
            }

            if (this.IsRemember)
            {
                // 记录用户名
                usernameFile.CombineCurrentDirectory().SerializeObjectToJson(this.UserName);
            }

            if (this.IsRememberPassWord)
            {
                // 记录密码
                "password.info".CombineCurrentDirectory().SerializeObjectToJson(password);
            }

            base.ShowLoading = true;

            Task.Run(() =>
            {
                var userInfo = new LoginInfo()
                {
                    user_name = this.UserName,
                    password  = password
                };

                return(WebAPI.Instance.Login(userInfo));
            }).ContinueWith(r =>
            {
                this.ShowLoading = false;

                if (r.Result.Item1)
                {
                    CacheManager.Instance.LoginUser = new Models.User()
                    {
                        ID          = r.Result.Item2.user_id,
                        UserName    = r.Result.Item2.user_name,
                        AccessToken = r.Result.Item2.access_token,
                        MixKey      = r.Result.Item2.mix_key,
                        PassWord    = password
                    };

                    string key = $"{CacheManager.Instance.LoginUser.UserName}.key";

                    // 检查IP地址
                    if (System.IO.File.Exists(lastAdress.CombineCurrentDirectory()))
                    {
                        string check_url  = cfa.AppSettings.Settings["xy:address"].Value;
                        string check_port = cfa.AppSettings.Settings["xy:port"].Value;
                        string check_path = $"{check_url}:{check_port}";

                        var lassAdress = lastAdress.CombineCurrentDirectory().DeSerializeObjectFromJson <string>();

                        if (!lassAdress.Equals(check_path))
                        {
                            System.IO.File.Delete(key.CombineCurrentDirectory());
                        }
                    }

                    // 检查本地是否有(密钥和公钥)
                    if (System.IO.File.Exists(key.CombineCurrentDirectory()))
                    {
                        // 0-公钥,1-私钥
                        List <string> keys = key.CombineCurrentDirectory().DeSerializeObjectFromJson <List <string> >();
                        CacheManager.Instance.LoginUser.PublickKey = keys[0];
                        CacheManager.Instance.LoginUser.PrivateKey = keys[1];
                    }
                    else
                    {
                        // 1.生成密钥
                        List <string> keys = new List <string>();

                        keys = RSAUtil.GenerateSuiteKeys()?.ToList();

                        CacheManager.Instance.LoginUser.PublickKey = keys[0];
                        CacheManager.Instance.LoginUser.PrivateKey = keys[1];

                        key.CombineCurrentDirectory().SerializeObjectToJson(keys);

                        var keyInfo = new KeyBodyInfo()
                        {
                            public_key  = keys[0],
                            secret_type = (int)SecretTypeEnum.RSA2
                        };

                        // 2.绑定密钥
                        var secret = WebAPI.Instance.SetSecret(keyInfo, CacheManager.Instance.LoginUser.AccessToken);
                        if (!secret.Item1)
                        {
                            DispatcherHelper.CheckBeginInvokeOnUI(() =>
                            {
                                var dialog = this.ShowDialog("提示信息", secret.Item2, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                            });
                            return;
                        }
                    }

                    #region 设置排课连接

                    string url     = cfa.AppSettings.Settings["xy:address"].Value;
                    string port    = cfa.AppSettings.Settings["xy:port"].Value;
                    string version = cfa.AppSettings.Settings["xy:version"].Value;
                    string path    = $"{url}:{port}";

                    WebAPI.Instance.SetFactory(path, version, CacheManager.Instance.LoginUser.ID);

                    lastAdress.CombineCurrentDirectory().SerializeObjectToJson(path);

                    #endregion

                    var isAnnual = WebAPI.Instance.GetAnnual();
                    if (isAnnual.Item1)
                    {
                        CacheManager.Instance.LoginUser.IsAnnual = isAnnual.Item2;
                    }

                    //Messenger.Default.Send<string>("refresh");

                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        win.DialogResult = true;
                    });
                }
                else
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        this.ShowDialog("提示信息", r.Result.Item3, CustomControl.Enums.DialogSettingType.OnlyOkButton, CustomControl.Enums.DialogType.Warning);
                    });
                }
            });
        }