Improvements to login

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-01-12 15:25:15 +01:00
parent 04daed0926
commit 562f5498d1
8 changed files with 83 additions and 45 deletions

View File

@ -242,9 +242,9 @@ public class CallActivity extends AppCompatActivity {
basicInitialization();
if (!userEntity.getCurrent()) {
userUtils.createOrUpdateUser(userEntity.getUsername(),
userEntity.getToken(), userEntity.getBaseUrl(), null,
null, true, null)
userUtils.createOrUpdateUser(null,
null, null, null,
null, true, null, userEntity.getId())
.subscribe(new Observer<UserEntity>() {
@Override
public void onSubscribe(Disposable d) {

View File

@ -82,6 +82,7 @@ public class AccountVerificationController extends BaseController {
private String username;
private String token;
private boolean isAccountImport;
private String originalProtocol;
public AccountVerificationController(Bundle args) {
super(args);
@ -92,6 +93,9 @@ public class AccountVerificationController extends BaseController {
if (args.containsKey(BundleKeys.KEY_IS_ACCOUNT_IMPORT)) {
isAccountImport = true;
}
if (args.containsKey(BundleKeys.KEY_ORIGINAL_PROTOCOL)) {
originalProtocol = args.getString(BundleKeys.KEY_ORIGINAL_PROTOCOL);
}
}
}
@ -115,7 +119,8 @@ public class AccountVerificationController extends BaseController {
dispose(null);
if (isAccountImport && !baseUrl.startsWith("http://") && !baseUrl.startsWith("https://")) {
if (isAccountImport && !baseUrl.startsWith("http://") && !baseUrl.startsWith("https://") || (!TextUtils
.isEmpty(originalProtocol) && !baseUrl.startsWith(originalProtocol))) {
determineBaseUrlProtocol(true);
} else {
checkEverything();
@ -127,6 +132,9 @@ public class AccountVerificationController extends BaseController {
cookieManager.getCookieStore().removeAll();
String queryUrl;
baseUrl = baseUrl.replace("http://", "").replace("https://", "");
if (checkForcedHttps) {
queryUrl = "https://" + baseUrl + ApiHelper.getUrlPostfixForStatus();
} else {
@ -188,7 +196,7 @@ public class AccountVerificationController extends BaseController {
if (!TextUtils.isEmpty(displayName)) {
dbQueryDisposable = userUtils.createOrUpdateUser(username, token,
baseUrl, displayName, null, true,
userProfileOverall.getOcs().getData().getUserId())
userProfileOverall.getOcs().getData().getUserId(), null)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(userEntity -> {
@ -300,7 +308,7 @@ public class AccountVerificationController extends BaseController {
@Override
public void onComplete() {
new Handler().postDelayed(() -> getRouter().popToRoot(), 10000);
new Handler().postDelayed(() -> getRouter().popToRoot(), 7500);
}
@Override
@ -311,7 +319,7 @@ public class AccountVerificationController extends BaseController {
} else {
ErrorMessageHolder.getInstance().setMessageType(
ErrorMessageHolder.ErrorMessageType.FAILED_TO_IMPORT_ACCOUNT);
new Handler().postDelayed(() -> getRouter().popToRoot(), 10000);
new Handler().postDelayed(() -> getRouter().popToRoot(), 7500);
}
}

View File

@ -97,9 +97,9 @@ public class SwitchAccountController extends BaseController {
public boolean onItemClick(int position) {
if (userItems.size() > position) {
UserEntity userEntity = ((AdvancedUserItem) userItems.get(position)).getEntity();
userUtils.createOrUpdateUser(userEntity.getUsername(),
userEntity.getToken(), userEntity.getBaseUrl(), null,
null, true, null)
userUtils.createOrUpdateUser(null,
null, null, null,
null, true, null, userEntity.getId())
.subscribe(new Observer<UserEntity>() {
@Override
public void onSubscribe(Disposable d) {

View File

@ -280,29 +280,50 @@ public class WebViewLoginController extends BaseController {
getRouter().popToRoot();
}
// We use the URL user entered because one provided by the server is NOT reliable
ErrorMessageHolder.ErrorMessageType finalErrorMessageType = errorMessageType;
userQueryDisposable = userUtils.createOrUpdateUser(loginData.getUsername(), loginData.getToken(),
loginData.getServerUrl(), null, null, true,
null).
subscribe(userEntity -> {
cookieManager.getCookieStore().removeAll();
if (!isPasswordUpdate && finalErrorMessageType == null) {
BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
bundleBuilder.putString(BundleKeys.KEY_USERNAME, userEntity.getUsername());
bundleBuilder.putString(BundleKeys.KEY_TOKEN, userEntity.getToken());
bundleBuilder.putString(BundleKeys.KEY_BASE_URL, userEntity.getBaseUrl());
getRouter().pushController(RouterTransaction.with(new AccountVerificationController
(bundleBuilder.build())).pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
} else {
if (finalErrorMessageType != null) {
ErrorMessageHolder.getInstance().setMessageType(finalErrorMessageType);
}
getRouter().popToRoot();
}
}, throwable -> dispose(),
this::dispose);
cookieManager.getCookieStore().removeAll();
if (!isPasswordUpdate && finalErrorMessageType == null) {
BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
bundleBuilder.putString(BundleKeys.KEY_USERNAME, loginData.getUsername());
bundleBuilder.putString(BundleKeys.KEY_TOKEN, loginData.getToken());
bundleBuilder.putString(BundleKeys.KEY_BASE_URL, loginData.getServerUrl());
String protocol = "";
if (baseUrl.startsWith("http://")) {
protocol = "http://";
} else if (baseUrl.startsWith("https://")) {
protocol = "https://";
}
if (!TextUtils.isEmpty(protocol)) {
bundleBuilder.putString(BundleKeys.KEY_ORIGINAL_PROTOCOL, protocol);
}
getRouter().pushController(RouterTransaction.with(new AccountVerificationController
(bundleBuilder.build())).pushChangeHandler(new HorizontalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler()));
} else {
if (isPasswordUpdate) {
if (currentUser != null) {
userQueryDisposable = userUtils.createOrUpdateUser(null, null,
null, null, null, true,
null, currentUser.getId()).
subscribe(userEntity -> {
if (finalErrorMessageType != null) {
ErrorMessageHolder.getInstance().setMessageType(finalErrorMessageType);
}
getRouter().popToRoot();
}, throwable -> dispose(),
this::dispose);
}
} else {
if (finalErrorMessageType != null) {
ErrorMessageHolder.getInstance().setMessageType(finalErrorMessageType);
}
getRouter().popToRoot();
}
}
}
}
}

View File

@ -301,11 +301,11 @@ public class PushUtils {
.getData().getPublicKey());
pushConfigurationState.setUsesRegularPass(false);
userUtils.createOrUpdateUser(userEntity.getUsername(),
userEntity.getToken(), userEntity.getBaseUrl(),
userUtils.createOrUpdateUser(null,
null, null,
userEntity.getDisplayName(),
LoganSquare.serialize(pushConfigurationState), null,
null)
null, userEntity.getId())
.subscribe(new Consumer<UserEntity>() {
@Override
public void accept(UserEntity userEntity) throws Exception {

View File

@ -25,4 +25,5 @@ public class BundleKeys {
public static final String KEY_TOKEN = "KEY_TOKEN";
public static final String KEY_BASE_URL = "KEY_BASE_URL";
public static final String KEY_IS_ACCOUNT_IMPORT = "IS_ACCOUNT_IMPORT";
public static final String KEY_ORIGINAL_PROTOCOL = "ORIGINAL_PROTOCOL";
}

View File

@ -148,13 +148,20 @@ public class UserUtils {
}
public Observable<UserEntity> createOrUpdateUser(String username, String token, String serverUrl,
public Observable<UserEntity> createOrUpdateUser(@Nullable String username, @Nullable String token, @Nullable String
serverUrl,
@Nullable String displayName,
@Nullable String pushConfigurationState,
@Nullable Boolean currentUser,
@Nullable String userId) {
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username).
and(UserEntity.BASE_URL.eq(serverUrl.toLowerCase()))).limit(1).get();
@Nullable String userId,
@Nullable Long internalId) {
Result findUserQueryResult;
if (internalId == null) {
findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username).
and(UserEntity.BASE_URL.eq(serverUrl.toLowerCase()))).limit(1).get();
} else {
findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId)).get();
}
UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
@ -183,7 +190,7 @@ public class UserUtils {
user.setUserId(userId);
}
if (!token.equals(user.getToken())) {
if (token != null && !token.equals(user.getToken())) {
user.setToken(token);
}

View File

@ -20,9 +20,9 @@
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progress_bar"
@ -34,13 +34,14 @@
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:indeterminate="true"
android:indeterminateTintMode="src_in"
android:indeterminateTint="@color/colorPrimary"/>
android:indeterminateTint="@color/colorPrimary"
android:indeterminateTintMode="src_in"/>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:visibility="invisible">
</WebView>