forked from github/wulkanowy-mirror
Fix merge branches
This commit is contained in:
parent
a5ad57cfde
commit
f4a8ad9b55
@ -30,8 +30,8 @@ import io.github.wulkanowy.R;
|
||||
public class MarksFragment extends Fragment {
|
||||
|
||||
|
||||
ArrayList<String> subject = new ArrayList<>();
|
||||
View view;
|
||||
private ArrayList<String> subject = new ArrayList<>();
|
||||
private View view;
|
||||
|
||||
public MarksFragment() {
|
||||
}
|
||||
|
@ -1,200 +0,0 @@
|
||||
package io.github.wulkanowy.activity.main;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.activity.dashboard.DashboardActivity;
|
||||
|
||||
public class Login extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
String email;
|
||||
String password;
|
||||
String county;
|
||||
|
||||
int check;
|
||||
|
||||
Map<String, String> loginCookies;
|
||||
|
||||
Activity activity;
|
||||
String userMesage;
|
||||
|
||||
String urlForStepOne;
|
||||
String urlForStepTwo;
|
||||
String urlForStepThree;
|
||||
|
||||
ProgressDialog progress;
|
||||
|
||||
public Login(String emailT, String passwordT, String countyT, Activity mainAC, int check) {
|
||||
|
||||
activity = mainAC;
|
||||
progress = new ProgressDialog(activity);
|
||||
this.check = check;
|
||||
|
||||
|
||||
if (countyT.equals("Debug")) {
|
||||
urlForStepOne = activity.getString(R.string.urlStepOneDebug);
|
||||
urlForStepTwo = activity.getString(R.string.urlStepTwoDebug);
|
||||
urlForStepThree = activity.getString(R.string.urlStepThreeDebug);
|
||||
county = activity.getString(R.string.countyDebug);
|
||||
email = emailT;
|
||||
password = passwordT;
|
||||
} else {
|
||||
urlForStepOne = activity.getString(R.string.urlStepOneRelease);
|
||||
urlForStepTwo = activity.getString(R.string.urlStepTwoRelease);
|
||||
urlForStepThree = activity.getString(R.string.urlStepThreeRelease);
|
||||
county = countyT;
|
||||
email = emailT;
|
||||
password = passwordT;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
|
||||
progress.setTitle(activity.getText(R.string.login_title));
|
||||
progress.setMessage(activity.getText(R.string.please_wait));
|
||||
progress.setCancelable(false);
|
||||
progress.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
try {
|
||||
if (!stepOne()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Document certificate = stepTwo();
|
||||
|
||||
Connection.Response step3 = stepThree(certificate);
|
||||
Document dashboardHtml = step3.parse();
|
||||
|
||||
String helloText = dashboardHtml.getElementsByClass("welcome").text();
|
||||
|
||||
if (helloText.equals("Dzień dobry!")) {
|
||||
String cookiesPath = activity.getFilesDir().getPath() + "/cookies.txt";
|
||||
FileOutputStream out = new FileOutputStream(cookiesPath);
|
||||
ObjectOutputStream outputStream = new ObjectOutputStream(out);
|
||||
outputStream.writeObject(loginCookies);
|
||||
outputStream.flush();
|
||||
|
||||
userMesage = activity.getString(R.string.login_accepted);
|
||||
} else {
|
||||
userMesage = activity.getString(R.string.login_denied);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
userMesage = e.toString();
|
||||
}
|
||||
|
||||
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 {
|
||||
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);
|
||||
|
||||
Connection.Response res = Jsoup.connect(urlForStepThree)
|
||||
.data("wa", wa)
|
||||
.data("wresult", wresults)
|
||||
.cookies(loginCookies)
|
||||
.followRedirects(true)
|
||||
.method(Connection.Method.POST)
|
||||
.execute();
|
||||
|
||||
loginCookies = res.cookies();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
progress.dismiss();
|
||||
if (!userMesage.isEmpty()) {
|
||||
Toast.makeText(activity, userMesage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
if (userMesage.equals(activity.getString(R.string.login_accepted))) {
|
||||
if (check == 0) {
|
||||
if (createAccount()) {
|
||||
Intent intent = new Intent(activity, DashboardActivity.class);
|
||||
activity.startActivity(intent);
|
||||
} else if (!createAccount()) {
|
||||
Toast.makeText(activity, "Konto już istnieje", Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(activity, DashboardActivity.class);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
} else if (check == 1) {
|
||||
Intent intent = new Intent(activity, DashboardActivity.class);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean createAccount() {
|
||||
|
||||
SharedPreferences sharedPreferences = activity.getSharedPreferences("io.github.wulkanowy", Context.MODE_PRIVATE);
|
||||
if (!sharedPreferences.contains(email)) {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("wulkanowy",email);
|
||||
editor.putString(email,email);
|
||||
editor.putString("sandi" + email,password);
|
||||
editor.putString("county" + email,county);
|
||||
editor.commit();
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putString("wulkanowy",email);
|
||||
editor.commit();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,10 @@ import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.activity.dashboard.DashboardActivity;
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
@ -47,6 +51,16 @@ public class LoginTask extends AsyncTask<String, Integer, Integer> {
|
||||
return R.string.login_denied;
|
||||
}
|
||||
|
||||
try {
|
||||
String cookiesPath = activity.getFilesDir().getPath() + "/cookies.txt";
|
||||
FileOutputStream out = new FileOutputStream(cookiesPath);
|
||||
ObjectOutputStream outputStream = new ObjectOutputStream(out);
|
||||
outputStream.writeObject(login.getJar());
|
||||
outputStream.flush();
|
||||
} catch (IOException e) {
|
||||
return R.string.login_cookies_save_failed;
|
||||
}
|
||||
|
||||
//Map<String, String> cookiesList = login.getJar();
|
||||
|
||||
return R.string.login_accepted;
|
||||
|
@ -1,9 +1,9 @@
|
||||
package io.github.wulkanowy.activity.main;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
@ -14,11 +14,7 @@ import java.util.LinkedHashMap;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
String password;
|
||||
String email;
|
||||
String county;
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -53,9 +49,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
EditText adressEmail = (EditText)findViewById(R.id.emailText);
|
||||
EditText passwordText = (EditText)findViewById(R.id.passwordText);
|
||||
EditText countyText = (EditText)findViewById(R.id.countyText);
|
||||
password = passwordText.getText().toString();
|
||||
email = adressEmail.getText().toString();
|
||||
county = countyText.getText().toString();
|
||||
String password = passwordText.getText().toString();
|
||||
String email = adressEmail.getText().toString();
|
||||
String county = countyText.getText().toString();
|
||||
|
||||
String[] keys = this.getResources().getStringArray(R.array.counties);
|
||||
String[] values = this.getResources().getStringArray(R.array.counties_values);
|
||||
@ -69,12 +65,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
county = map.get(county);
|
||||
}
|
||||
|
||||
if (!email.isEmpty() || !password.isEmpty() || !county.isEmpty()){
|
||||
new Login(email, password, county, this, 0).execute();
|
||||
}
|
||||
else if (password.isEmpty() || email.isEmpty() || county.isEmpty()) {
|
||||
if (!email.isEmpty() && !password.isEmpty() && !county.isEmpty()){
|
||||
new LoginTask(this).execute(email, password, county);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.data_text, Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -14,19 +14,16 @@ import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.activity.main.Login;
|
||||
import io.github.wulkanowy.activity.main.LoginTask;
|
||||
import io.github.wulkanowy.activity.main.MainActivity;
|
||||
|
||||
public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
Activity activity;
|
||||
boolean isOnline;
|
||||
String idAccount;
|
||||
String email;
|
||||
String password;
|
||||
String county;
|
||||
private Activity activity;
|
||||
private boolean isOnline;
|
||||
|
||||
final boolean SAVE_DATA = true;
|
||||
|
||||
private final boolean SAVE_DATA = false;
|
||||
|
||||
LoadingTask(Activity main) {
|
||||
activity = main;
|
||||
@ -54,13 +51,13 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
if (sharedPreferences.contains("wulkanowy")) {
|
||||
|
||||
idAccount = sharedPreferences.getString("wulkanowy", "");
|
||||
email = sharedPreferences.getString(idAccount, "");
|
||||
password = sharedPreferences.getString("sandi" + email, "");
|
||||
county = sharedPreferences.getString("county" + email, "");
|
||||
String idAccount = sharedPreferences.getString("wulkanowy", "");
|
||||
String email = sharedPreferences.getString(idAccount, "");
|
||||
String password = sharedPreferences.getString("sandi" + email, "");
|
||||
String county = sharedPreferences.getString("county" + email, "");
|
||||
|
||||
if (!email.isEmpty() || !password.isEmpty() || !county.isEmpty()) {
|
||||
new Login(email, password, county, activity, 1).execute();
|
||||
new LoginTask(activity).execute(email, password, county);
|
||||
} else if (password.isEmpty() || email.isEmpty() || county.isEmpty()) {
|
||||
Toast.makeText(activity, R.string.data_text, Toast.LENGTH_SHORT).show();
|
||||
|
||||
@ -80,11 +77,11 @@ public class LoadingTask extends AsyncTask<Void, Void, Void> {
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
activity.startActivity(intent);
|
||||
|
||||
Toast.makeText(activity,"Brak połączenia z internetem",Toast.LENGTH_SHORT ).show();
|
||||
Toast.makeText(activity,R.string.noInternet_text,Toast.LENGTH_SHORT ).show();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
private boolean isOnline() {
|
||||
try {
|
||||
int timeoutMs = 1500;
|
||||
Socket sock = new Socket();
|
||||
|
@ -9,9 +9,8 @@
|
||||
<string name="warning_text">Aplikacja ta nie jest ukończona, więc mogą występować różnego rodzaju błędy lub dane funkcje nie bedą działać. Prosimy o cierpliwość i wyrozumiałość.</string>
|
||||
<string name="warning_label">Ostrzeżenie</string>
|
||||
<string name="data_text">Brak danych logowania</string>
|
||||
<string name="error_feature_text">Funkcja którą chciałeś uruchomić nie działa</string>
|
||||
<string name="login_accepted">Pomyślnie zalogowano</string>
|
||||
<string name="login_bad_credentials">Zła nazwa użytkownika lub hasło</string>
|
||||
<string name="login_bad_credentials">Niepoprawny e-mail lub hasło</string>
|
||||
<string name="login_bad_account_permission">Brak uprawnień do otwarcia dziennika. Sprawdź wprowadzoną nazwę powiatu</string>
|
||||
<string name="login_denied">Logowanie nie powiodło się</string>
|
||||
<string name="please_wait">Proszę czekać…</string>
|
||||
@ -21,4 +20,6 @@
|
||||
<string name="title_attendance">Frekwencja</string>
|
||||
<string name="title_lessonplan">Plan lekcji</string>
|
||||
<string name="title_settings">Ustawienia</string>
|
||||
<string name="noInternet_text">Brak połączenia z internetem</string>
|
||||
<string name="login_cookies_save_failed">Nie udało się zapisać sesji</string>
|
||||
</resources>
|
||||
|
@ -9,9 +9,8 @@
|
||||
<string name="warning_text">This application is not complete, so there may be a variety of errors or features that will not work. Please be patient and understanding.</string>
|
||||
<string name="warning_label">Warning</string>
|
||||
<string name="data_text">No login data</string>
|
||||
<string name="error_feature_text">The function you wanted to run does not work</string>
|
||||
<string name="login_accepted">Login is successful</string>
|
||||
<string name="login_bad_credentials">Bad username or password</string>
|
||||
<string name="login_bad_credentials">Bad e-mail or password</string>
|
||||
<string name="login_bad_account_permission">No permission to open log. Check entered county name</string>
|
||||
<string name="login_denied">Login is failed</string>
|
||||
<string name="please_wait">Please wait…</string>
|
||||
@ -21,4 +20,6 @@
|
||||
<string name="title_attendance">Attendance</string>
|
||||
<string name="title_lessonplan">Lesson Plan</string>
|
||||
<string name="title_settings">Settings</string>
|
||||
<string name="noInternet_text">No internet connection</string>
|
||||
<string name="login_cookies_save_failed">Failed to save session</string>
|
||||
</resources>
|
||||
|
@ -1,16 +1,9 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name = "NoActionBar" parent = "@android:style/Theme.DeviceDefault">
|
||||
<item name = "android:windowActionBar">false</item>
|
||||
<item name = "android:windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user