private void login() { userName = CommonUtils.getContentFromEditText(user_name); userPassword = CommonUtils.getContentFromEditText(user_pw); if (userName.equals("")) { ToastTool.showText(LoginAtivity.this, "请输入用户名"); return; } if (userPassword.equals("")) { ToastTool.showText(LoginAtivity.this, "请输入密码"); return; } if (!MatchTool.match(MatchTool.PWD, userPassword)) { ToastTool.showText(LoginAtivity.this, "请输入6-16位只包含汉字、字母、数字和特殊字符的密码"); return; } LogTool.i("登陆请求:"); Bundle param = new Bundle(); param.putString("user", userName); param.putString("pwd", userPassword); reqData("/data/chklogin.json", param); String name = SharedPreferenceUtil.getUserInfo("user_name", this); // 清楚本地图片 if (!name.equals(userName)) { LogTool.i("新用户登录"); utils.deleteBtmap(); } }
@Override protected void parserData(JSONObject response) { LogTool.i("登陆应答 :"); LogTool.i(response.toString()); android.util.Log.d("xcq", "登录返回数据: " + response.toString()); // String str = utils.readFile(); try { // response = new JSONObject(str); JSONObject obj = response.getJSONObject("result"); String code = obj.getString("code"); if (RESPONSE_CODE.FAIL_CODE.equals(code)) { ToastTool.showText(LoginAtivity.this, obj.getString("msg")); return; } SharedPreferenceUtil.saveUserInfo("user_name", userName, getApplicationContext()); SharedPreferenceUtil.saveUserInfo("user_password", userPassword, getApplicationContext()); JSONObject rsObj = obj.getJSONObject("rs"); SysVar.getInstance(this).saveUserInfo(rsObj); Intent intent = new Intent(LoginAtivity.this, MainActivity.class); startActivity(intent); SysValue.is_login = true; this.finish(); } catch (JSONException e) { e.printStackTrace(); } }