@Override
public boolean fetchdata(Login login, javax.swing.JTextField username,javax.swing.JPasswordField password) {
boolean flag=false;
User u = new User();
String data = new RestClient().apacheHttpClientGet(Login.url+"api/reservation/auth/user/?format=json", username.getText(), password.getPassword());
if( data!=null) {
try {
u.setUsername(username.getText());
u.setPassword(password.getPassword());
login.setUsers_map(new HashMap());
JSONObject jsonObject = (JSONObject) new JSONParser().parse(data);
for (Object c : (JSONArray) jsonObject.get("objects")){
jsonObject = (JSONObject) c;
User remoteuser = new User(Integer.parseInt((String)jsonObject.get("id")),(String) jsonObject.get("username"));
login.getUsers_map().put(remoteuser.getUsername(), remoteuser);
}
} catch (ParseException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
flag = true;
}
else {
flag=false;
}
User temp = (User) login.getUsers_map().get(u.getUsername());
if (temp!=null){
u=temp;
u.setPassword(password.getPassword());
}