1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 02:29:08 -05:00

Fix api login(#119)

This commit is contained in:
Mikołaj Pich 2018-05-23 19:21:35 +02:00 committed by Rafał Borcz
parent 859f8dc319
commit 3592946e6f
5 changed files with 17 additions and 12 deletions

View File

@ -118,7 +118,7 @@ public class Client {
this.cookies.addItems(response.cookies());
Document doc = checkForErrors(response.parse());
Document doc = checkForErrors(response.parse(), response.statusCode());
if (loginBefore) {
lastSuccessRequest = new Date();
@ -144,7 +144,7 @@ public class Client {
response.bufferUp(); // fixes cert parsing issues #109
return checkForErrors(response.parse());
return checkForErrors(response.parse(), response.statusCode());
}
public String getJsonStringByUrl(String url) throws IOException, VulcanException {
@ -182,7 +182,7 @@ public class Client {
return response.body();
}
Document checkForErrors(Document doc) throws VulcanException {
Document checkForErrors(Document doc, int code) throws VulcanException {
lastSuccessRequest = null;
String title = doc.select("title").text();
@ -195,8 +195,8 @@ public class Client {
throw new NotLoggedInErrorException(singIn);
}
if (title.startsWith("Błąd")) {
throw new NotLoggedInErrorException(title + " " + doc.selectFirst("p, body"));
if ("Błąd strony".equals(title)) {
throw new NotLoggedInErrorException(title + " " + doc.selectFirst("p, body") + ", status: " + code);
}
return doc;

View File

@ -65,12 +65,12 @@ public class StudentAndParent implements SnP {
return getBaseUrl();
}
// get url to uonetplus-opiekun.vulcan.net.pl
// get url to uonetplus-opiekun.fakelog.cf
Document startPage = client.getPageByUrl(START_PAGE_URL);
Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first();
if (null == studentTileLink) {
throw new NotLoggedInErrorException("You are probably not logged in. Force login");
throw new VulcanException("Na pewno używasz konta z dostępem do Witryny ucznia i rodzica?");
}
String snpPageUrl = studentTileLink.attr("href");
@ -84,7 +84,7 @@ public class StudentAndParent implements SnP {
String[] path = snpPageUrl.split(client.getHost())[1].split("/");
if (5 != path.length) {
throw new NotLoggedInErrorException("You are probably not logged in");
throw new NotLoggedInErrorException("You are probably not logged in " + snpPageUrl);
}
return path[2];

View File

@ -9,6 +9,7 @@ import org.jsoup.select.Elements;
import java.io.IOException;
import io.github.wulkanowy.api.Client;
import io.github.wulkanowy.api.NotLoggedInErrorException;
import io.github.wulkanowy.api.VulcanException;
public class Login {
@ -27,6 +28,10 @@ public class Login {
public String login(String email, String password, String symbol) throws VulcanException, IOException {
Document certDoc = sendCredentials(email, password);
if ("Błąd".equals(certDoc.title())) {
throw new NotLoggedInErrorException(certDoc.selectFirst("body").text());
}
return sendCertificate(certDoc, symbol);
}

View File

@ -25,7 +25,7 @@ public class ClientTest {
Document doc = Jsoup.parse(getFixtureAsString("login/Logowanie-success.html"));
Assert.assertEquals(doc, client.checkForErrors(doc));
Assert.assertEquals(doc, client.checkForErrors(doc, 200));
}
@Test(expected = VulcanOfflineException.class)
@ -34,7 +34,7 @@ public class ClientTest {
Document doc = Jsoup.parse(getFixtureAsString("login/PrzerwaTechniczna.html"));
client.checkForErrors(doc);
client.checkForErrors(doc, 200);
}
@Test(expected = NotLoggedInErrorException.class)
@ -43,7 +43,7 @@ public class ClientTest {
Document doc = Jsoup.parse(getFixtureAsString("login/Logowanie-notLoggedIn.html"));
client.checkForErrors(doc);
client.checkForErrors(doc, 200);
}
@Test

View File

@ -53,7 +53,7 @@ public class StudentAndParentTest {
snp.getSnpHomePageUrl());
}
@Test(expected = NotLoggedInErrorException.class)
@Test(expected = VulcanException.class)
public void getSnpPageUrlWithWrongPage() throws Exception {
Document wrongPageDocument = Jsoup.parse(
FixtureHelper.getAsString(getClass().getResourceAsStream("OcenyWszystkie-semester.html"))