Ejemplo n.º 1
0
        public void LoginAsync(string loginName, string password, Action <ResponseBase, Exception> callback)
        {
            VirtualRoot.SetRpcUser(new User.RpcUser(loginName, password));
            SignRequest request = new SignRequest()
            {
            };

            RpcRoot.PostAsync(NTMinerRegistry.GetControlCenterHost(), NTKeyword.ControlCenterPort, _controllerName, nameof(IControlCenterController.LoginControlCenter), request, request, callback);
        }
Ejemplo n.º 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.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));
                    }
                });
            });
        }