Search in sources :

Example 1 with DeviceRegister

use of de.tum.in.tumcampusapp.api.app.model.DeviceRegister in project TumCampusApp by TCA-Team.

the class AuthenticationManager method uploadKey.

/**
 * Try to upload the public key to the server and remember that state.
 *
 * @param publicKey
 */
private void uploadKey(String publicKey, final ChatMember member) {
    // If we already uploaded it we don't need to redo that
    if (Utils.getSettingBool(mContext, Const.PUBLIC_KEY_UPLOADED, false)) {
        this.tryToUploadGcmToken();
        return;
    }
    try {
        DeviceRegister dr = DeviceRegister.Companion.getDeviceRegister(mContext, publicKey, member);
        // Upload public key to the server
        TUMCabeClient.getInstance(mContext).deviceRegister(dr, new Callback<TUMCabeStatus>() {

            @Override
            public void onResponse(Call<TUMCabeStatus> call, Response<TUMCabeStatus> response) {
                // Remember that we are done, only if we have submitted with the member information
                if (response.isSuccessful() && "ok".equals(response.body().getStatus())) {
                    if (member != null) {
                        Utils.setSetting(mContext, Const.PUBLIC_KEY_UPLOADED, true);
                    }
                    AuthenticationManager.this.tryToUploadGcmToken();
                }
            }

            @Override
            public void onFailure(Call<TUMCabeStatus> call, Throwable t) {
                Utils.log(t, "Failure uploading public key");
                Utils.setSetting(mContext, Const.PUBLIC_KEY_UPLOADED, false);
            }
        });
    } catch (NoPrivateKey noPrivateKey) {
        this.clearKeys();
    }
}
Also used : NoPrivateKey(de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey) TUMCabeStatus(de.tum.in.tumcampusapp.api.app.model.TUMCabeStatus) DeviceRegister(de.tum.in.tumcampusapp.api.app.model.DeviceRegister)

Aggregations

NoPrivateKey (de.tum.in.tumcampusapp.api.app.exception.NoPrivateKey)1 DeviceRegister (de.tum.in.tumcampusapp.api.app.model.DeviceRegister)1 TUMCabeStatus (de.tum.in.tumcampusapp.api.app.model.TUMCabeStatus)1