Exemple #1
0
        private void BtnLogin_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Vm.ServerHost))
            {
                Vm.ShowMessage("服务器地址不能为空");
                return;
            }
            string passwordSha1 = HashUtil.Sha1(Vm.Password);

            NTMinerRegistry.SetControlCenterHost(Vm.ServerHost);
            var list = NTMinerRegistry.GetControlCenterHosts();

            if (!list.Contains(Vm.ServerHost))
            {
                list.Insert(0, Vm.ServerHost);
            }
            NTMinerRegistry.SetControlCenterHosts(list);
            // 内网免登录
            if (Net.IpUtil.IsInnerIp(Vm.ServerHost))
            {
                VirtualRoot.SetRpcUser(new User.RpcUser("localhost", "localhost"));
                this.Close();
                // 回调可能弹窗,弹窗可能有父窗口,父窗口是顶层窗口,如果在this.Close()之前回调
                // 则会导致弹窗的父窗口是本窗口,而本窗口随后立即关闭导致作为子窗口的弹窗也会被关闭。
                _onLoginSuccess?.Invoke();
                return;
            }
            RpcRoot.Server.ControlCenterService.LoginAsync(Vm.LoginName, passwordSha1, (response, exception) => {
                UIThread.Execute(() => () => {
                    if (response == null)
                    {
                        Vm.ShowMessage("服务器忙");
                        return;
                    }
                    if (response.IsSuccess())
                    {
                        this.Close();
                        // 回调可能弹窗,弹窗可能有父窗口,父窗口是顶层窗口,如果在this.Close()之前回调
                        // 则会导致弹窗的父窗口是本窗口,而本窗口随后立即关闭导致作为子窗口的弹窗也会被关闭。
                        _onLoginSuccess?.Invoke();
                    }
                    else if (Vm.LoginName == "admin" && response.StateCode == 404)
                    {
                        Vm.IsPasswordAgainVisible = Visibility.Visible;
                        Vm.ShowMessage(response.ReadMessage(exception));
                        this.PbPasswordAgain.Focus();
                    }
                    else
                    {
                        Vm.IsPasswordAgainVisible = Visibility.Collapsed;
                        Vm.ShowMessage(response.ReadMessage(exception));
                    }
                });
            });
        }
Exemple #2
0
        private void BtnLogin_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Vm.ServerHost))
            {
                Vm.ShowMessage("服务器地址不能为空");
                return;
            }
            string passwordSha1 = HashUtil.Sha1(Vm.Password);

            NTMinerRegistry.SetControlCenterHost(Vm.ServerHost);
            var list = NTMinerRegistry.GetControlCenterHosts();

            if (!list.Contains(Vm.ServerHost))
            {
                list.Insert(0, Vm.ServerHost);
            }
            NTMinerRegistry.SetControlCenterHosts(list);
            if (Net.Util.IsInnerIp(Vm.ServerHost))
            {
                SingleUser.LoginName = "localhost";
                SingleUser.SetPasswordSha1("localhost");
                this.Close();
                return;
            }
            Server.ControlCenterService.LoginAsync(Vm.LoginName, passwordSha1, (response, exception) => {
                UIThread.Execute(() => {
                    if (response == null)
                    {
                        Vm.ShowMessage("服务器忙");
                        return;
                    }
                    if (response.IsSuccess())
                    {
                        SingleUser.LoginName = Vm.LoginName;
                        SingleUser.SetPasswordSha1(passwordSha1);
                        this.Close();
                    }
                    else if (Vm.LoginName == "admin" && response.StateCode == 404)
                    {
                        Vm.IsPasswordAgainVisible = Visibility.Visible;
                        Vm.ShowMessage(response.Description);
                        this.PbPasswordAgain.Focus();
                    }
                    else
                    {
                        Vm.IsPasswordAgainVisible = Visibility.Collapsed;
                        Vm.ShowMessage(response.Description);
                    }
                });
            });
        }