forked from github/wulkanowy-mirror
Add user api
This commit is contained in:
parent
cd4feb6d83
commit
e845fc1f15
@ -18,6 +18,8 @@ import io.github.wulkanowy.api.login.AccountPermissionException;
|
||||
import io.github.wulkanowy.api.login.BadCredentialsException;
|
||||
import io.github.wulkanowy.api.login.Login;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
import io.github.wulkanowy.api.user.BasicInformation;
|
||||
import io.github.wulkanowy.api.user.PersonalData;
|
||||
import io.github.wulkanowy.database.accounts.AccountData;
|
||||
import io.github.wulkanowy.database.accounts.DatabaseAccount;
|
||||
|
||||
@ -71,22 +73,26 @@ public class LoginTask extends AsyncTask<String, Integer, Integer> {
|
||||
}
|
||||
|
||||
if (save) {
|
||||
try {
|
||||
BasicInformation userInfo = new BasicInformation(login.getCookies(), credentials[2]);
|
||||
PersonalData personalData = userInfo.getPersonalData();
|
||||
String firstAndLastName = personalData.getFirstAndLastName();
|
||||
|
||||
AccountData accountData = new AccountData()
|
||||
.setName("")
|
||||
.setName(firstAndLastName)
|
||||
.setEmail(credentials[0])
|
||||
.setPassword(credentials[1])
|
||||
.setCounty(credentials[2]);
|
||||
|
||||
DatabaseAccount databaseAccount = new DatabaseAccount(activity);
|
||||
|
||||
try{
|
||||
databaseAccount.open();
|
||||
databaseAccount.put(accountData);
|
||||
databaseAccount.close();
|
||||
}
|
||||
catch (SQLException e){
|
||||
|
||||
} catch (SQLException e) {
|
||||
return R.string.SQLite_ioError_text;
|
||||
} catch (IOException | LoginErrorException e) {
|
||||
return R.string.login_denied;
|
||||
}
|
||||
}
|
||||
//Map<String, String> cookiesList = login.getJar();
|
||||
|
@ -23,7 +23,6 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
private Activity activity;
|
||||
private boolean isOnline;
|
||||
|
||||
|
||||
private final boolean SAVE_DATA = true;
|
||||
|
||||
LoadingTask(Activity main) {
|
||||
@ -33,11 +32,13 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
|
||||
if (!SAVE_DATA) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
isOnline = isOnline();
|
||||
|
||||
@ -47,10 +48,8 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
protected void onPostExecute(Void result) {
|
||||
|
||||
if (isOnline) {
|
||||
|
||||
signIn();
|
||||
}
|
||||
else{
|
||||
} else{
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
activity.startActivity(intent);
|
||||
|
||||
@ -87,9 +86,7 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
new LoginTask(activity, false).execute(accountData.getEmail(), accountData.getPassword(), accountData.getCounty());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (SQLException e){
|
||||
|
||||
} catch (SQLException e){
|
||||
Toast.makeText(activity,R.string.SQLite_ioError_text,Toast.LENGTH_LONG ).show();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package io.github.wulkanowy.api.user;
|
||||
|
||||
public class AddressData {
|
||||
|
||||
private String address;
|
||||
|
||||
private String registeredAddress;
|
||||
|
||||
private String correspondenceAddress;
|
||||
|
||||
public AddressData setAddress(String address) {
|
||||
this.address = address;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddressData setRegisteredAddress(String registeredAddress) {
|
||||
this.registeredAddress = registeredAddress;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddressData setCorrespondenceAddress(String correspondenceAddress) {
|
||||
this.correspondenceAddress = correspondenceAddress;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getRegisteredAddress() {
|
||||
return registeredAddress;
|
||||
}
|
||||
|
||||
public String getCorrespondenceAddress() {
|
||||
return correspondenceAddress;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package io.github.wulkanowy.api.user;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
|
||||
public class BasicInformation extends StudentAndParent {
|
||||
|
||||
private String studentDataPageUrl = "https://uonetplus-opiekun.vulcan.net.pl/{locationID}/{ID}/Uczen.mvc/DanePodstawowe";
|
||||
|
||||
private Document studentDataPageDocument;
|
||||
|
||||
public BasicInformation(Cookies cookies, String locationID) throws IOException, LoginErrorException {
|
||||
super(cookies, locationID);
|
||||
|
||||
studentDataPageDocument = getPage();
|
||||
}
|
||||
|
||||
private Document getPage() throws IOException, LoginErrorException {
|
||||
studentDataPageUrl = studentDataPageUrl.replace("{locationID}", getLocationID());
|
||||
studentDataPageUrl = studentDataPageUrl.replace("{ID}", getID());
|
||||
|
||||
return Jsoup.connect(studentDataPageUrl)
|
||||
.cookies(getJar())
|
||||
.get();
|
||||
}
|
||||
|
||||
private String getRowDataChildValue(Element e, int index) {
|
||||
return e.select(".daneWiersz .wartosc").get(index - 1).text();
|
||||
}
|
||||
|
||||
public PersonalData getPersonalData() {
|
||||
Element e = studentDataPageDocument.select(".mainContainer > article").get(0);
|
||||
|
||||
return new PersonalData()
|
||||
.setNames(getRowDataChildValue(e, 1))
|
||||
.setDateAndBirthPlace(getRowDataChildValue(e, 2))
|
||||
.setPesel(getRowDataChildValue(e, 3))
|
||||
.setGender(getRowDataChildValue(e, 4))
|
||||
.setPolishCitizenship(getRowDataChildValue(e, 5))
|
||||
.setFamilyName(getRowDataChildValue(e, 6))
|
||||
.setParentsNames(getRowDataChildValue(e, 7));
|
||||
}
|
||||
|
||||
public AddressData getAddresData() {
|
||||
Element e = studentDataPageDocument.select(".mainContainer > article").get(1);
|
||||
|
||||
return new AddressData()
|
||||
.setAddress(getRowDataChildValue(e, 1))
|
||||
.setRegisteredAddress(getRowDataChildValue(e, 2))
|
||||
.setCorrespondenceAddress(getRowDataChildValue(e, 3));
|
||||
|
||||
}
|
||||
|
||||
public ContactDetails getContactDetails() {
|
||||
Element e = studentDataPageDocument.select(".mainContainer > article").get(2);
|
||||
|
||||
return new ContactDetails()
|
||||
.setPhoneNumber(getRowDataChildValue(e, 1))
|
||||
.setCellPhoneNumber(getRowDataChildValue(e, 2))
|
||||
.setEmail(getRowDataChildValue(e, 3));
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package io.github.wulkanowy.api.user;
|
||||
|
||||
public class ContactDetails {
|
||||
|
||||
private String phoneNumber;
|
||||
|
||||
private String cellPhoneNumber;
|
||||
|
||||
private String email;
|
||||
|
||||
public ContactDetails setPhoneNumber(String phoneNumber) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContactDetails setCellPhoneNumber(String cellPhoneNumber) {
|
||||
this.cellPhoneNumber = cellPhoneNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ContactDetails setEmail(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPhoneNumber() {
|
||||
return phoneNumber;
|
||||
}
|
||||
|
||||
public String getCellPhoneNumber() {
|
||||
return cellPhoneNumber;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
}
|
104
app/src/main/java/io/github/wulkanowy/api/user/PersonalData.java
Normal file
104
app/src/main/java/io/github/wulkanowy/api/user/PersonalData.java
Normal file
@ -0,0 +1,104 @@
|
||||
package io.github.wulkanowy.api.user;
|
||||
|
||||
public class PersonalData {
|
||||
|
||||
private String names;
|
||||
|
||||
private String dateAndBirthPlace;
|
||||
|
||||
private String pesel;
|
||||
|
||||
private String gender;
|
||||
|
||||
private String isPolishCitizenship;
|
||||
|
||||
private String familyName;
|
||||
|
||||
private String parentsNames;
|
||||
|
||||
public PersonalData setNames(String names) {
|
||||
this.names = names;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setDateAndBirthPlace(String dateAndBirthPlace) {
|
||||
this.dateAndBirthPlace = dateAndBirthPlace;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setPesel(String pesel) {
|
||||
this.pesel = pesel;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setGender(String gender) {
|
||||
this.gender = gender;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setPolishCitizenship(String polishCitizenship) {
|
||||
isPolishCitizenship = polishCitizenship;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setFamilyName(String familyName) {
|
||||
this.familyName = familyName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public PersonalData setParentsNames(String parentsNames) {
|
||||
this.parentsNames = parentsNames;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
String[] name = names.split(" ");
|
||||
|
||||
return name[0];
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
String[] name = names.split(" ");
|
||||
|
||||
return name[name.length - 1];
|
||||
}
|
||||
|
||||
public String getFirstAndLastName() {
|
||||
return getFirstName() + " " + getSurname();
|
||||
}
|
||||
|
||||
public String getDateAndBirthPlace() {
|
||||
return dateAndBirthPlace;
|
||||
}
|
||||
|
||||
public String getPesel() {
|
||||
return pesel;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public boolean isPolishCitizenship() {
|
||||
return isPolishCitizenship.equals("Tak");
|
||||
}
|
||||
|
||||
public String getFamilyName() {
|
||||
return familyName;
|
||||
}
|
||||
|
||||
public String getParentsNames() {
|
||||
return parentsNames;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user