forked from github/wulkanowy-mirror
Fix login process #1, refactoring Login class and more
This commit is contained in:
parent
f53229a055
commit
d49e74f7e8
@ -7,8 +7,8 @@ import android.widget.Toast;
|
|||||||
import org.jsoup.Connection;
|
import org.jsoup.Connection;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
import org.jsoup.helper.HttpConnection.Response;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
@ -19,15 +19,15 @@ public class Login extends AsyncTask<Void, Void, Void> {
|
|||||||
String email;
|
String email;
|
||||||
String password;
|
String password;
|
||||||
String county;
|
String county;
|
||||||
|
|
||||||
|
Map<String, String> loginCookies;
|
||||||
|
|
||||||
Activity activity;
|
Activity activity;
|
||||||
String userMesage;
|
String userMesage;
|
||||||
String wresults;
|
|
||||||
String wa;
|
|
||||||
Document doc4;
|
|
||||||
String htmlDefault = "https://cufs.vulcan.net.pl/Default/Account/LogOn";
|
|
||||||
String htmlStage2 = "https://cufs.vulcan.net.pl/{locationID}/FS/LS?wa=wsignin1.0&wtrealm=https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx&wctx=https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx";
|
|
||||||
String htmlStage3 = "https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx";
|
|
||||||
|
|
||||||
|
String urlForStepOne = "https://cufs.vulcan.net.pl/Default/Account/LogOn";
|
||||||
|
String urlForStepTwo = "https://cufs.vulcan.net.pl/{locationID}/FS/LS?wa=wsignin1.0&wtrealm=https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx&wctx=https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx";
|
||||||
|
String urlForStepThree = "https://uonetplus.vulcan.net.pl/{locationID}/LoginEndpoint.aspx";
|
||||||
|
|
||||||
public Login(String emailT, String passwordT, String countyT, Activity mainAC){
|
public Login(String emailT, String passwordT, String countyT, Activity mainAC){
|
||||||
|
|
||||||
@ -42,39 +42,23 @@ public class Login extends AsyncTask<Void, Void, Void> {
|
|||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection.Response initial = Jsoup
|
if (!stepOne()) {
|
||||||
.connect(htmlDefault)
|
return null;
|
||||||
.data("LoginName", email)
|
}
|
||||||
.data("Password", password)
|
|
||||||
.method(Connection.Method.POST)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
Map<String, String> loginCookies = initial.cookies();
|
Document certificate = stepTwo();
|
||||||
|
|
||||||
CheckPass checkPass = new CheckPass(initial);
|
Connection.Response step3 = stepThree(certificate);
|
||||||
userMesage = checkPass.start();
|
Document dashboardHtml = step3.parse();
|
||||||
|
|
||||||
county = county.replace("ł", "l");
|
|
||||||
htmlStage2 = htmlStage2.replace("{locationID}", county);
|
|
||||||
|
|
||||||
Document doc = Jsoup.connect(htmlStage2)
|
|
||||||
.cookies(loginCookies)
|
|
||||||
.get();
|
|
||||||
|
|
||||||
Elements wresultsInput = doc.select("input[name=wresult]");
|
|
||||||
wresults = wresultsInput.attr("value");
|
|
||||||
|
|
||||||
Elements waInput = doc.select("input[name=wa]");
|
|
||||||
wa = waInput.attr("value");
|
|
||||||
|
|
||||||
htmlStage3 = htmlStage3.replace("{locationID}", county);
|
|
||||||
|
|
||||||
doc4 = Jsoup.connect(htmlStage3)
|
|
||||||
.data("wa", wa)
|
|
||||||
.data("wresults", wresults)
|
|
||||||
.post();
|
|
||||||
|
|
||||||
|
Elements mesageAlert = dashboardHtml.getElementsByClass("welcome");
|
||||||
|
String helloText = dashboardHtml.getElementsByClass("welcome").text();
|
||||||
|
|
||||||
|
if (helloText.equals("Dzień dobry!")) {
|
||||||
|
userMesage = "Zalogowano pomyślnie! " + helloText;
|
||||||
|
} else {
|
||||||
|
userMesage = "Coś poszło nie tak :/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e){
|
catch (IOException e){
|
||||||
userMesage = e.toString();
|
userMesage = e.toString();
|
||||||
@ -83,6 +67,49 @@ public class Login extends AsyncTask<Void, Void, Void> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean stepOne() throws IOException {
|
||||||
|
Connection.Response initial = Jsoup
|
||||||
|
.connect(urlForStepOne)
|
||||||
|
.data("LoginName", email)
|
||||||
|
.data("Password", password)
|
||||||
|
.method(Connection.Method.POST)
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
loginCookies = initial.cookies();
|
||||||
|
|
||||||
|
CheckPass checkPass = new CheckPass(initial);
|
||||||
|
userMesage = checkPass.start();
|
||||||
|
|
||||||
|
return userMesage.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Document stepTwo() throws IOException {
|
||||||
|
county = county.replace("ł", "l");
|
||||||
|
urlForStepTwo = urlForStepTwo.replace("{locationID}", county);
|
||||||
|
|
||||||
|
return Jsoup.connect(urlForStepTwo)
|
||||||
|
.cookies(loginCookies)
|
||||||
|
.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection.Response stepThree(Document certificate) throws IOException {
|
||||||
|
Elements wresultsInput = certificate.select("input[name=wresult]");
|
||||||
|
String wresults = wresultsInput.attr("value");
|
||||||
|
|
||||||
|
Elements waInput = certificate.select("input[name=wa]");
|
||||||
|
String wa = waInput.attr("value");
|
||||||
|
|
||||||
|
urlForStepThree = urlForStepThree.replace("{locationID}", county);
|
||||||
|
|
||||||
|
return Jsoup.connect(urlForStepThree)
|
||||||
|
.data("wa", wa)
|
||||||
|
.data("wresult", wresults)
|
||||||
|
.cookies(loginCookies)
|
||||||
|
.followRedirects(true)
|
||||||
|
.method(Connection.Method.POST)
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
|
||||||
protected void onPostExecute(Void result) {
|
protected void onPostExecute(Void result) {
|
||||||
super.onPostExecute(result);
|
super.onPostExecute(result);
|
||||||
if (!userMesage.isEmpty()){
|
if (!userMesage.isEmpty()){
|
||||||
|
@ -54,7 +54,7 @@ public class MainActivity extends Activity {
|
|||||||
String email = adressEmail.getText().toString();
|
String email = adressEmail.getText().toString();
|
||||||
String county = countyText.getText().toString();
|
String county = countyText.getText().toString();
|
||||||
|
|
||||||
if (password.isEmpty()|| email.isEmpty() || county.isEmpty()){
|
if (password.isEmpty() || email.isEmpty() || county.isEmpty()){
|
||||||
Toast.makeText(this, R.string.data_text, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.data_text, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -18,7 +18,7 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
|||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user