Search in sources :

Example 6 with UserEntity

use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.

the class UserUtils method checkIfUserIsScheduledForDeletion.

public boolean checkIfUserIsScheduledForDeletion(String username, String server) {
    Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username)).and(UserEntity.BASE_URL.eq(server)).limit(1).get();
    UserEntity userEntity;
    if ((userEntity = (UserEntity) findUserQueryResult.firstOrNull()) != null) {
        return userEntity.getScheduledForDeletion();
    }
    return false;
}
Also used : UserEntity(com.nextcloud.talk.models.database.UserEntity) Result(io.requery.query.Result)

Example 7 with UserEntity

use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.

the class UserUtils method createOrUpdateUser.

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, @Nullable Long internalId, @Nullable String capabilities) {
    Result findUserQueryResult;
    if (internalId == null) {
        findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username).and(UserEntity.BASE_URL.eq(serverUrl))).limit(1).get();
    } else {
        findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(internalId)).get();
    }
    UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
    if (user == null) {
        user = new UserEntity();
        user.setBaseUrl(serverUrl);
        user.setUsername(username);
        user.setToken(token);
        if (!TextUtils.isEmpty(displayName)) {
            user.setDisplayName(displayName);
        }
        if (pushConfigurationState != null) {
            user.setPushConfigurationState(pushConfigurationState);
        }
        if (!TextUtils.isEmpty(userId)) {
            user.setUserId(userId);
        }
        if (!TextUtils.isEmpty(capabilities)) {
            user.setCapabilities(capabilities);
        }
        user.setCurrent(true);
    } else {
        if (userId != null && (user.getUserId() == null || !user.getUserId().equals(userId))) {
            user.setUserId(userId);
        }
        if (token != null && !token.equals(user.getToken())) {
            user.setToken(token);
        }
        if ((displayName != null && user.getDisplayName() == null) || (displayName != null && user.getDisplayName() != null && !displayName.equals(user.getDisplayName()))) {
            user.setDisplayName(displayName);
        }
        if (pushConfigurationState != null && !pushConfigurationState.equals(user.getPushConfigurationState())) {
            user.setPushConfigurationState(pushConfigurationState);
        }
        if (capabilities != null && !capabilities.equals(user.getCapabilities())) {
            user.setCapabilities(capabilities);
        }
        if (currentUser != null) {
            user.setCurrent(currentUser);
        }
    }
    return dataStore.upsert(user).toObservable().subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread());
}
Also used : User(com.nextcloud.talk.models.database.User) UserEntity(com.nextcloud.talk.models.database.UserEntity) Result(io.requery.query.Result)

Example 8 with UserEntity

use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.

the class UserUtils method deleteUser.

public Completable deleteUser(String username, String serverUrl) {
    Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USERNAME.eq(username).and(UserEntity.BASE_URL.eq(serverUrl))).limit(1).get();
    UserEntity user = (UserEntity) findUserQueryResult.firstOrNull();
    return dataStore.delete(user).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread());
}
Also used : User(com.nextcloud.talk.models.database.User) UserEntity(com.nextcloud.talk.models.database.UserEntity) Result(io.requery.query.Result)

Example 9 with UserEntity

use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.

the class PushUtils method verifySignature.

public SignatureVerification verifySignature(byte[] signatureBytes, byte[] subjectBytes) {
    Signature signature = null;
    PushConfigurationState pushConfigurationState;
    PublicKey publicKey;
    SignatureVerification signatureVerification = new SignatureVerification();
    signatureVerification.setSignatureValid(false);
    List<UserEntity> userEntities = userUtils.getUsers();
    try {
        signature = Signature.getInstance("SHA512withRSA");
        if (userEntities != null && userEntities.size() > 0) {
            for (UserEntity userEntity : userEntities) {
                if (!TextUtils.isEmpty(userEntity.getPushConfigurationState())) {
                    pushConfigurationState = LoganSquare.parse(userEntity.getPushConfigurationState(), PushConfigurationState.class);
                    publicKey = (PublicKey) readKeyFromString(true, pushConfigurationState.getUserPublicKey());
                    signature.initVerify(publicKey);
                    signature.update(subjectBytes);
                    if (signature.verify(signatureBytes)) {
                        signatureVerification.setSignatureValid(true);
                        signatureVerification.setUserEntity(userEntity);
                        return signatureVerification;
                    }
                }
            }
        }
    } catch (NoSuchAlgorithmException e) {
        Log.d(TAG, "No such algorithm");
    } catch (IOException e) {
        Log.d(TAG, "Error while trying to parse push configuration state");
    } catch (InvalidKeyException e) {
        Log.d(TAG, "Invalid key while trying to verify");
    } catch (SignatureException e) {
        Log.d(TAG, "Signature exception while trying to verify");
    }
    return signatureVerification;
}
Also used : PushConfigurationState(com.nextcloud.talk.models.json.push.PushConfigurationState) PublicKey(java.security.PublicKey) Signature(java.security.Signature) SignatureVerification(com.nextcloud.talk.models.SignatureVerification) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException) UserEntity(com.nextcloud.talk.models.database.UserEntity)

Example 10 with UserEntity

use of com.nextcloud.talk.models.database.UserEntity in project talk-android by nextcloud.

the class ShareUtils method getStringForIntent.

public static String getStringForIntent(Context context, @Nullable String password, UserUtils userUtils, Room room) {
    UserEntity userEntity = userUtils.getCurrentUser();
    String shareString = "";
    if (userEntity != null && context != null) {
        shareString = String.format(context.getResources().getString(R.string.nc_share_text), userEntity.getBaseUrl(), room.getToken());
        if (!TextUtils.isEmpty(password)) {
            shareString += String.format(context.getResources().getString(R.string.nc_share_text_pass), password);
        }
    }
    return shareString;
}
Also used : UserEntity(com.nextcloud.talk.models.database.UserEntity)

Aggregations

UserEntity (com.nextcloud.talk.models.database.UserEntity)17 Disposable (io.reactivex.disposables.Disposable)7 NonNull (android.support.annotation.NonNull)6 NcApi (com.nextcloud.talk.api.NcApi)6 Result (io.requery.query.Result)5 ArrayList (java.util.ArrayList)5 TextUtils (android.text.TextUtils)4 LayoutInflater (android.view.LayoutInflater)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 AutoInjector (autodagger.AutoInjector)4 BindView (butterknife.BindView)4 RouterTransaction (com.bluelinelabs.conductor.RouterTransaction)4 R (com.nextcloud.talk.R)4 Intent (android.content.Intent)3 Bundle (android.os.Bundle)3 Nullable (android.support.annotation.Nullable)3 HorizontalChangeHandler (com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)3 VerticalChangeHandler (com.bluelinelabs.conductor.changehandler.VerticalChangeHandler)3 NextcloudTalkApplication (com.nextcloud.talk.application.NextcloudTalkApplication)3