Fake log integration (#39)
* Handle technical break error * Add login by pass email with log host * Use in FirstAccountLogin fully Vulcan facade * Add SnP interface
This commit is contained in:

committed by
Rafał Borcz

parent
c111e43f18
commit
15a1662ac5
@ -2,7 +2,6 @@ package io.github.wulkanowy.services;
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
@ -20,6 +20,7 @@ import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.AccountPermissionException;
|
||||
import io.github.wulkanowy.api.login.BadCredentialsException;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
||||
import io.github.wulkanowy.dao.entities.Account;
|
||||
import io.github.wulkanowy.dao.entities.AccountDao;
|
||||
import io.github.wulkanowy.dao.entities.DaoMaster;
|
||||
@ -60,7 +61,7 @@ public class CurrentAccountLoginTest {
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void emptyUserIdTest() throws CryptoException, BadCredentialsException,
|
||||
AccountPermissionException, IOException, LoginErrorException {
|
||||
AccountPermissionException, IOException, LoginErrorException, VulcanOfflineException {
|
||||
|
||||
CurrentAccountLogin currentAccountLogin = new CurrentAccountLogin(context, daoSession, new Vulcan());
|
||||
currentAccountLogin.loginCurrentUser();
|
||||
@ -80,7 +81,7 @@ public class CurrentAccountLoginTest {
|
||||
setUserIdSharePreferences(userId);
|
||||
|
||||
Vulcan vulcan = Mockito.mock(Vulcan.class);
|
||||
Mockito.doNothing().when(vulcan).login("TEST@TEST", "TEST", "TEST_SYMBOL", "TEST_ID");
|
||||
Mockito.when(vulcan.login("TEST@TEST", "TEST", "TEST_SYMBOL", "TEST_ID")).thenReturn(new Vulcan());
|
||||
|
||||
CurrentAccountLogin currentAccountLogin = new CurrentAccountLogin(targetContext, daoSession, vulcan);
|
||||
LoginSession loginSession = currentAccountLogin.loginCurrentUser();
|
||||
|
@ -14,7 +14,6 @@ import org.mockito.Mockito;
|
||||
|
||||
import io.github.wulkanowy.api.StudentAndParent;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.Login;
|
||||
import io.github.wulkanowy.api.user.BasicInformation;
|
||||
import io.github.wulkanowy.api.user.PersonalData;
|
||||
import io.github.wulkanowy.dao.entities.Account;
|
||||
@ -49,17 +48,6 @@ public class FirstAccountLoginTest {
|
||||
setUserIdSharePreferences(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectTest() throws Exception {
|
||||
String certificate = "<xml>Certificate</xml>";
|
||||
Login login = Mockito.mock(Login.class);
|
||||
Mockito.when(login.sendCredentials(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
|
||||
.thenReturn(certificate);
|
||||
FirstAccountLogin firstAccountLogin = new FirstAccountLogin(login, new Vulcan(), "TEST@TEST", "TEST_PASS", "TEST_SYMBOL");
|
||||
|
||||
Assert.assertEquals(certificate, firstAccountLogin.connect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginTest() throws Exception {
|
||||
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
|
||||
@ -76,11 +64,8 @@ public class FirstAccountLoginTest {
|
||||
Mockito.doReturn(basicInformation).when(vulcan).getBasicInformation();
|
||||
Mockito.doReturn(snp).when(vulcan).getStudentAndParent();
|
||||
|
||||
Login login = Mockito.mock(Login.class);
|
||||
Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenReturn("TEST-SYMBOL");
|
||||
|
||||
FirstAccountLogin firstAccountLogin = new FirstAccountLogin(login, vulcan, "TEST@TEST", "TEST-PASS", "default");
|
||||
LoginSession loginSession = firstAccountLogin.login(targetContext, daoSession, "<xml>cert</xml>");
|
||||
FirstAccountLogin firstAccountLogin = new FirstAccountLogin(targetContext, daoSession, vulcan);
|
||||
LoginSession loginSession = firstAccountLogin.login("TEST@TEST", "TEST-PASS", "default");
|
||||
|
||||
Long userId = targetContext.getSharedPreferences("LoginData", Context.MODE_PRIVATE).getLong("userId", 0);
|
||||
|
||||
|
@ -6,13 +6,12 @@ import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
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.login.NotLoggedInErrorException;
|
||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
||||
import io.github.wulkanowy.dao.entities.DaoSession;
|
||||
import io.github.wulkanowy.security.CryptoException;
|
||||
import io.github.wulkanowy.services.jobs.VulcanJobHelper;
|
||||
@ -26,10 +25,6 @@ public class VulcanSynchronization {
|
||||
|
||||
private LoginSession loginSession;
|
||||
|
||||
private FirstAccountLogin firstAccountLogin;
|
||||
|
||||
private String certificate;
|
||||
|
||||
public VulcanSynchronization(LoginSession loginSession) {
|
||||
this.loginSession = loginSession;
|
||||
}
|
||||
@ -38,30 +33,21 @@ public class VulcanSynchronization {
|
||||
this.loginSession = new LoginSession();
|
||||
}
|
||||
|
||||
public void firstLoginConnectStep(String email, String password, String symbol)
|
||||
throws BadCredentialsException, IOException {
|
||||
firstAccountLogin = new FirstAccountLogin(new Login(new Cookies()), new Vulcan(), email, password, symbol);
|
||||
certificate = firstAccountLogin.connect();
|
||||
}
|
||||
|
||||
public void firstLoginSignInStep(Context context, DaoSession daoSession)
|
||||
throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException {
|
||||
if (firstAccountLogin != null && certificate != null) {
|
||||
loginSession = firstAccountLogin.login(context, daoSession, certificate);
|
||||
} else {
|
||||
Log.e(VulcanJobHelper.DEBUG_TAG, "Before first login, should call firstLoginConnectStep",
|
||||
new UnsupportedOperationException());
|
||||
}
|
||||
public void firstLoginSignInStep(Context context, DaoSession daoSession, String email, String password, String symbol)
|
||||
throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException, VulcanOfflineException, BadCredentialsException {
|
||||
FirstAccountLogin firstAccountLogin = new FirstAccountLogin(context, daoSession, new Vulcan());
|
||||
loginSession = firstAccountLogin.login(email, password, symbol);
|
||||
}
|
||||
|
||||
public VulcanSynchronization loginCurrentUser(Context context, DaoSession daoSession) throws CryptoException,
|
||||
BadCredentialsException, AccountPermissionException, LoginErrorException, IOException {
|
||||
BadCredentialsException, AccountPermissionException, LoginErrorException, IOException, VulcanOfflineException {
|
||||
return loginCurrentUser(context, daoSession, new Vulcan());
|
||||
}
|
||||
|
||||
public VulcanSynchronization loginCurrentUser(Context context, DaoSession daoSession, Vulcan vulcan)
|
||||
throws CryptoException, BadCredentialsException, AccountPermissionException,
|
||||
LoginErrorException, IOException {
|
||||
LoginErrorException, IOException, VulcanOfflineException {
|
||||
|
||||
CurrentAccountLogin currentAccountLogin = new CurrentAccountLogin(context, daoSession, vulcan);
|
||||
loginSession = currentAccountLogin.loginCurrentUser();
|
||||
return this;
|
||||
|
@ -9,6 +9,7 @@ import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.AccountPermissionException;
|
||||
import io.github.wulkanowy.api.login.BadCredentialsException;
|
||||
import io.github.wulkanowy.api.login.LoginErrorException;
|
||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
||||
import io.github.wulkanowy.dao.entities.Account;
|
||||
import io.github.wulkanowy.dao.entities.AccountDao;
|
||||
import io.github.wulkanowy.dao.entities.DaoSession;
|
||||
@ -32,7 +33,7 @@ public class CurrentAccountLogin {
|
||||
}
|
||||
|
||||
public LoginSession loginCurrentUser() throws CryptoException,
|
||||
BadCredentialsException, AccountPermissionException, IOException, LoginErrorException {
|
||||
BadCredentialsException, AccountPermissionException, IOException, LoginErrorException, VulcanOfflineException {
|
||||
|
||||
AccountDao accountDao = daoSession.getAccountDao();
|
||||
|
||||
@ -44,6 +45,7 @@ public class CurrentAccountLogin {
|
||||
|
||||
Safety safety = new Safety();
|
||||
Account account = accountDao.load(userId);
|
||||
|
||||
vulcan.login(
|
||||
account.getEmail(),
|
||||
safety.decrypt(account.getEmail(), account.getPassword()),
|
||||
|
@ -8,8 +8,8 @@ import java.io.IOException;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
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.NotLoggedInErrorException;
|
||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
||||
import io.github.wulkanowy.dao.entities.Account;
|
||||
import io.github.wulkanowy.dao.entities.AccountDao;
|
||||
import io.github.wulkanowy.dao.entities.DaoSession;
|
||||
@ -19,38 +19,22 @@ import io.github.wulkanowy.services.LoginSession;
|
||||
|
||||
public class FirstAccountLogin {
|
||||
|
||||
private final Context context;
|
||||
|
||||
private final Login login;
|
||||
private final DaoSession daoSession;
|
||||
|
||||
private final Vulcan vulcan;
|
||||
|
||||
private final String email;
|
||||
|
||||
private final String password;
|
||||
|
||||
private final String symbol;
|
||||
|
||||
public FirstAccountLogin(Login login, Vulcan vulcan, String email, String password, String symbol) {
|
||||
this.login = login;
|
||||
public FirstAccountLogin(Context context, DaoSession daoSession, Vulcan vulcan) {
|
||||
this.context = context;
|
||||
this.daoSession = daoSession;
|
||||
this.vulcan = vulcan;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String connect()
|
||||
throws BadCredentialsException, IOException {
|
||||
return login.sendCredentials(email, password, symbol);
|
||||
}
|
||||
public LoginSession login(String email, String password, String symbol)
|
||||
throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException, VulcanOfflineException, BadCredentialsException {
|
||||
|
||||
public LoginSession login(Context context, DaoSession daoSession, String certificate)
|
||||
throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException {
|
||||
|
||||
long userId;
|
||||
|
||||
String realSymbol = login.sendCertificate(certificate, symbol);
|
||||
|
||||
vulcan.login(login.getCookiesObject(), realSymbol);
|
||||
vulcan.login(email, password, symbol);
|
||||
|
||||
AccountDao accountDao = daoSession.getAccountDao();
|
||||
Safety safety = new Safety();
|
||||
@ -61,7 +45,7 @@ public class FirstAccountLogin {
|
||||
.setSymbol(vulcan.getStudentAndParent().getSymbol())
|
||||
.setSnpId(vulcan.getStudentAndParent().getId());
|
||||
|
||||
userId = accountDao.insert(account);
|
||||
long userId = accountDao.insert(account);
|
||||
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences("LoginData", Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
|
@ -171,11 +171,11 @@ public class LoginActivity extends Activity {
|
||||
}
|
||||
|
||||
private boolean isEmailValid(String email) {
|
||||
return email.contains("@");
|
||||
return email.contains("@") || email.contains("\\\\");
|
||||
}
|
||||
|
||||
private boolean isPasswordValid(String password) {
|
||||
return password.length() > 7;
|
||||
return password.length() > 4;
|
||||
}
|
||||
|
||||
private void hideSoftKeyboard() {
|
||||
|
@ -24,6 +24,7 @@ import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.api.login.AccountPermissionException;
|
||||
import io.github.wulkanowy.api.login.BadCredentialsException;
|
||||
import io.github.wulkanowy.api.login.NotLoggedInErrorException;
|
||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
||||
import io.github.wulkanowy.dao.entities.DaoSession;
|
||||
import io.github.wulkanowy.security.CryptoException;
|
||||
import io.github.wulkanowy.services.LoginSession;
|
||||
@ -68,20 +69,15 @@ public class LoginTask extends AsyncTask<Void, String, Integer> {
|
||||
@Override
|
||||
protected Integer doInBackground(Void... params) {
|
||||
if (ConnectionUtilities.isOnline(activity.get())) {
|
||||
DaoSession daoSession = ((WulkanowyApp) activity.get().getApplication()).getDaoSession();
|
||||
VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession());
|
||||
|
||||
DaoSession daoSession = ((WulkanowyApp) activity.get().getApplication()).getDaoSession();
|
||||
|
||||
try {
|
||||
publishProgress("1", activity.get().getResources().getString(R.string.step_connecting));
|
||||
vulcanSynchronization.firstLoginConnectStep(email, password, symbol);
|
||||
publishProgress("1", activity.get().getResources().getString(R.string.step_login));
|
||||
vulcanSynchronization.firstLoginSignInStep(activity.get(), daoSession, email, password, symbol);
|
||||
|
||||
publishProgress("2", activity.get().getResources().getString(R.string.step_login));
|
||||
vulcanSynchronization.firstLoginSignInStep(activity.get(), daoSession);
|
||||
|
||||
publishProgress("3", activity.get().getResources().getString(R.string.step_synchronization));
|
||||
publishProgress("2", activity.get().getResources().getString(R.string.step_synchronization));
|
||||
vulcanSynchronization.syncAll();
|
||||
|
||||
} catch (BadCredentialsException e) {
|
||||
return R.string.login_bad_credentials_text;
|
||||
} catch (AccountPermissionException e) {
|
||||
@ -94,6 +90,8 @@ public class LoginTask extends AsyncTask<Void, String, Integer> {
|
||||
return R.string.generic_timeout_error;
|
||||
} catch (NotLoggedInErrorException | IOException e) {
|
||||
return R.string.login_denied_text;
|
||||
} catch (VulcanOfflineException e) {
|
||||
return R.string.error_host_offline;
|
||||
} catch (UnsupportedOperationException e) {
|
||||
return -1;
|
||||
}
|
||||
@ -109,7 +107,7 @@ public class LoginTask extends AsyncTask<Void, String, Integer> {
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(String... progress) {
|
||||
showText.get().setText(String.format("%1$s/3 - %2$s...", progress[0], progress[1]));
|
||||
showText.get().setText(String.format("%1$s/2 - %2$s...", progress[0], progress[1]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,12 +3,12 @@ package io.github.wulkanowy.ui.main;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
||||
|
||||
public class RefreshTask extends AsyncTask<Void, Void, List<?>> {
|
||||
|
||||
@ -30,12 +30,16 @@ public class RefreshTask extends AsyncTask<Void, Void, List<?>> {
|
||||
} catch (UnknownHostException e) {
|
||||
stringEventId = R.string.noInternet_text;
|
||||
Log.i(DEBUG_TAG, "Synchronization is failed because occur problem with internet",
|
||||
new IOException());
|
||||
e.getCause());
|
||||
return null;
|
||||
} catch (SocketTimeoutException e) {
|
||||
stringEventId = R.string.generic_timeout_error;
|
||||
Log.i(DEBUG_TAG, "Too long wait for connection with internet", e);
|
||||
return null;
|
||||
} catch (VulcanOfflineException e) {
|
||||
stringEventId = R.string.error_host_offline;
|
||||
Log.i(DEBUG_TAG, "VULCAN services is offline");
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
stringEventId = R.string.refresh_error_text;
|
||||
Log.e(DEBUG_TAG, "There was a synchronization problem", e);
|
||||
|
@ -22,6 +22,7 @@ import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.api.login.VulcanOfflineException;
|
||||
import io.github.wulkanowy.dao.DatabaseAccess;
|
||||
import io.github.wulkanowy.dao.entities.Account;
|
||||
import io.github.wulkanowy.dao.entities.AccountDao;
|
||||
@ -146,7 +147,7 @@ public class GradesFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
private static class RefreshTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private static class RefreshTask extends AsyncTask<Void, Void, Integer> {
|
||||
|
||||
private DaoSession daoSession;
|
||||
|
||||
@ -161,24 +162,27 @@ public class GradesFragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
protected Integer doInBackground(Void... params) {
|
||||
VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession());
|
||||
try {
|
||||
vulcanSynchronization.loginCurrentUser(activity.get(), daoSession, new Vulcan());
|
||||
vulcanSynchronization.syncGrades();
|
||||
downloadGradesFormDatabase(daoSession);
|
||||
return true;
|
||||
return 1;
|
||||
} catch (VulcanOfflineException e) {
|
||||
Log.e(VulcanJobHelper.DEBUG_TAG, "There was a synchronization problem, because vulcan is offline", e);
|
||||
return R.string.error_host_offline;
|
||||
} catch (Exception e) {
|
||||
Log.e(VulcanJobHelper.DEBUG_TAG, "There was a synchronization problem", e);
|
||||
return false;
|
||||
return R.string.refresh_error_text;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
super.onPostExecute(result);
|
||||
protected void onPostExecute(Integer messageID) {
|
||||
super.onPostExecute(messageID);
|
||||
|
||||
if (result) {
|
||||
if (1 == messageID) {
|
||||
if (mainView.get() != null && activity.get() != null) {
|
||||
createExpList(mainView.get(), activity.get());
|
||||
}
|
||||
@ -195,7 +199,7 @@ public class GradesFragment extends Fragment {
|
||||
Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(activity.get(), R.string.refresh_error_text, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(activity.get(), messageID, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
if (mainView.get() != null) {
|
||||
|
@ -39,6 +39,7 @@
|
||||
<string name="fragment_no_grades">Brak ocen</string>
|
||||
|
||||
<string name="noInternet_text">Brak połączenia z internetem</string>
|
||||
<string name="error_host_offline">Przerwa techniczna. Spróbuj ponownie później</string>
|
||||
<string name="encrypt_failed_text">Szyfrowanie nie powiodło się. Automatyczne logowanie zostało wyłączone</string>
|
||||
<string name="version_text">Wersja %1$s</string>
|
||||
<string name="refresh_error_text">"Podczas odświeżania zawartości wystąpił błąd. "</string>
|
||||
|
@ -72,6 +72,7 @@
|
||||
|
||||
<string name="info_average_grades">Average: %1$.2f</string>
|
||||
<string name="info_no_average">No average</string>
|
||||
<string name="error_host_offline">Technical break</string>
|
||||
|
||||
<string name="timetable_subitem_room">Room %s</string>
|
||||
|
||||
|
Reference in New Issue
Block a user