Пример #1
0
        //登录操作
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            /*if ("true" == ConfigurationManager.AppSettings["Debug"])
             * {
             *  //Debug模式直接进系统 方便开发
             *  MainPage mainpage1 = new MainPage();
             *  this.Content = mainpage1;
             *  return;
             * }*/
            //获取用户名
            String name = this.User_Name.Text;
            //获取密码
            String password = this.User_Password.Password;

            UserConstant.USERNAME = name;
            UserConstant.PASSWORD = password;
            ///登录逻辑
            AuthService authService = new AuthService();
            string      loginResult = authService.Login(name, password);

            Console.WriteLine("loginResult:" + loginResult);

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
            {
                loginResult = LanguageUtils.ConvertLanguage("用户名或者密码不能为空", "User name or password cannot be empty");
            }
            //U盾监测,无误后登录
            if (loginResult.Equals("check_U"))
            {
                //admin不能记住密码  很危险
                //验证U盾后跳转
                //暂时不验证U盾
                MainPage mainpage = new MainPage();
                this.Content = mainpage;
                if (timerNotice != null)
                {
                    timerNotice.Stop();
                }
            }
            else if (loginResult.Equals("success"))
            {
                //普通用户,点击记住密码,登陆成功后,登录用户与密码加入缓存
                bool?checkRemind     = isRemind.IsChecked;
                bool?checkRemindName = isRemindName.IsChecked;
                if (checkRemind == true)
                {
                    //加密后存储在config中
                    name     = ConfigUtil.Encrypt(name);
                    password = ConfigUtil.Encrypt(password);
                    CommUtil.UpdateSettingString("isRemind", "true");
                    CommUtil.UpdateSettingString("isRemindName", "true");
                    CommUtil.UpdateSettingString("userName", name);
                    CommUtil.UpdateSettingString("password", password);
                }
                else if (checkRemindName == true)
                {
                    name = ConfigUtil.Encrypt(name);
                    CommUtil.UpdateSettingString("isRemind", "false");
                    CommUtil.UpdateSettingString("isRemindName", "true");
                    CommUtil.UpdateSettingString("userName", name);
                }
                else
                {
                    //都不选中就不记住,清空缓存的密码
                    CommUtil.UpdateSettingString("isRemind", "false");
                    CommUtil.UpdateSettingString("isRemindName", "false");
                    CommUtil.UpdateSettingString("userName", "");
                    CommUtil.UpdateSettingString("password", "");
                }

                //成功登陆,跳转
                MainPage mainpage = new MainPage();
                this.Content = mainpage;

                if (timerNotice != null)
                {
                    timerNotice.Stop();
                }
            }
            else
            {
                //问题登录  在登录提示框内显示信息
                bubble.IsOpen = true;
                //Error_Info.Content = loginResult;

                Error_Info.Content = LanguageUtils.ConvertLanguage(loginResult, "login exist question!");
            }
        }