use of me.vertretungsplan.objects.authentication.PasswordAuthenticationData in project substitution-schedule-parser by vertretungsplanme.
the class ESchoolParser method getSubstitutionSchedule.
@Override
public SubstitutionSchedule getSubstitutionSchedule() throws IOException, JSONException, CredentialInvalidException {
if (!(scheduleData.getAuthenticationData() instanceof NoAuthenticationData) && (credential == null || !(credential instanceof PasswordCredential) || ((PasswordCredential) credential).getPassword() == null || ((PasswordCredential) credential).getPassword().isEmpty())) {
throw new IOException("no login");
}
List<NameValuePair> nvps = new ArrayList<>();
nvps.add(new BasicNameValuePair("wp", scheduleData.getData().getString(PARAM_ID)));
nvps.add(new BasicNameValuePair("go", "vplan"));
nvps.add(new BasicNameValuePair("content", "x14"));
nvps.add(new BasicNameValuePair("sortby", "S"));
String url = BASE_URL + "?" + URLEncodedUtils.format(nvps, "UTF-8");
Document doc = Jsoup.parse(httpGet(url, ENCODING));
if (doc.select("form[name=loginform]").size() > 0 && scheduleData.getAuthenticationData() instanceof PasswordAuthenticationData) {
// Login required
List<NameValuePair> formParams = new ArrayList<>();
formParams.add(new BasicNameValuePair("password", ((PasswordCredential) credential).getPassword()));
formParams.add(new BasicNameValuePair("login", ""));
doc = Jsoup.parse(httpPost(url, ENCODING, formParams));
if (doc.select("font[color=red]").text().contains("fehlgeschlagen")) {
throw new CredentialInvalidException();
}
}
SubstitutionSchedule schedule = parseESchoolSchedule(doc);
return schedule;
}
Aggregations