You are on page 1of 2

public void handleLogin(View view) {

String isRegistered = "true";


if (isRegistered.equalsIgnoreCase("true")) {
mUsernameEdit = (EditText) findViewById(R.id.username_ed
it);
mPasswordEdit = (EditText) findViewById(R.id.password_ed
it);
if (mUsernameEdit.getText() != null
&& mPasswordEdit.getText() != null) {
mUsername = mUsernameEdit.getText().toString();
mPassword = mPasswordEdit.getText().toString();
}
if (TextUtils.isEmpty(mUsername) || TextUtils.isEmpty(mP
assword)) {
Toast.makeText(this, getMessage(), Toast.LENGTH_
LONG).show();
} else {
showProgress();
Map<String, Boolean> authenticatedMap = new Hash
Map<String, Boolean>();
boolean authenticated = false;
try {
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
JSONObject obj = RestUtility.getRequest("http://
10.140.28.123:8081/DeviceLabManagement/rest/service/login/"+mUsername+"/"+mPassw
ord);
ByteArrayInputStream objStream= new ByteArrayInp
utStream(obj.toString().getBytes("UTF-8"));
JsonFactory factory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper(factory);
TypeReference<Map<String, Boolean>> typeRef
= new TypeReference<Map<String, Boolean>>()
{};
authenticatedMap = mappe
r.readValue(objStream, typeRef);
authenticated= authentic
atedMap!= null ? authenticatedMap.get("authenticated"): false;
} catch (JsonParseException e) {
authenticated = false;
} catch (JsonMappingException e)
{
authenticated =
} catch (IOException e)
authenticated =
} catch (ParseException

false;
{
false;
e) {

authenticated = false;
} catch (HttpException e) {
authenticated = false;
} catch (JSONException e) {
authenticated = false;
}
if (authenticated)
{saveToPref(Constants.CUID + "-" + mUsername);
showLandingPage();
}
else {
Toast.makeText(this, getLoginErrorMessag
e(),
Toast.LENGTH_LONG).show(
);
//showLoginPage();
checkMenu();
}
}
}
}

You might also like