Пример #1
0
        public void Login(LoginData data, out string token, out LoginStatus status)
        {
            Smmuser user= SqlMapHelper.DefaultSqlMap.QueryForObject<Smmuser>("SelectSmmuserByKey", data.UserNumber);
            if (user == null)
                status = LoginStatus.InvalidUser;
            else {

                if (MainDataModule.Decrypt(user.Password) == data.Password)
                    status = LoginStatus.OK;
                else
                    status = LoginStatus.InvalidPassword;
            }

            token = string.Empty;
            if (status == LoginStatus.OK) {
                token = Guid.NewGuid().ToString();
                UserStateSingleton.Instance.AddUser(new UserInfo(token, data.UserNumber));
            }
        }
Пример #2
0
        /// <summary>
        /// 执行登录
        /// </summary>
        private void DoLogin()
        {
            if (utxtuser.tbox.Text == string.Empty) {
                MsgBox.Show("工号没有输入");
                utxtuser.Focus();
                return;
            }

            ILoginAction loginAction = RemotingHelper.GetRemotingService<ILoginAction>();
            if (loginAction == null) {
                MsgBox.Show("ILoginAction没有被正确注册");
                return;
            }

            string token;
            string userNumber = utxtuser.tbox.Text.Trim();
            string password = utxtpwd.tbox.Text;
            LoginData data = new LoginData(userNumber, password);
            LoginStatus status;
            try {
                loginAction.Login(data, out token, out status);
            } catch (System.Net.Sockets.SocketException) {
                MsgBox.Show("无法连接服务器,请稍候重试");
                utxtpwd.tbox.Focus();
                return;
            }
            switch (status) {
                case LoginStatus.OK:
                    if (m_reLogin) {
                        // 原来的用户退出
                        if (!UserLogoutCommand.Exec(false)) {
                            MsgBox.Show("无法连接服务器,请稍候重试");
                            utxtpwd.tbox.Focus();
                            return;

                        }

                        //MIS.WriteApplicationLog("系统", "退出系统");
                    }
                    DialogResult = DialogResult.OK;
                    MIS.Token = token;
                    MIS.UserNumber = data.UserNumber;
                    //MIS.WriteApplicationLog("系统", "登录系统");

                    // 记录最近一次登录的用户的工号
                    Itop.Client.Option.Settings.SetLastLoginUserNumber(userNumber);

                    break;
                case LoginStatus.InvalidUser:
                    MsgBox.Show("工号输入错误");
                    utxtuser.tbox.Focus();
                    break;
                case LoginStatus.InvalidPassword:
                    if (m_error.ContainsKey(userNumber)) {
                        // 错误加一
                        m_error[userNumber]++;
                    } else {
                        // 第一次错误
                        m_error.Add(userNumber, 1);
                    }

                    if (m_error[userNumber] >= 3) {
                        if (!m_reLogin) {
                            MsgBox.Show("密码输入错误次数超过三次,无法登录系统");
                            CloseServer();
                            Application.Exit();
                        } else {
                            MsgBox.Show("密码输入错误次数超过三次,请稍候重试");
                            DialogResult = DialogResult.Cancel;
                        }
                    } else {
                        MsgBox.Show("密码输入错误,请重新输入密码");
                    }
                    utxtpwd.tbox.Text = "";
                    utxtpwd.tbox.Focus();
                    break;
                default:
                    break;
            }
        }