use of com.applozic.mobicomkit.exception.UnAuthoriseException in project Applozic-Android-SDK by AppLozic.
the class RegisterUserClientService method createAccount.
// final RegistrationResponse registrationResponse = createAccount(user);
// Intent intent = new Intent(context, ApplozicMqttIntentService.class);
// intent.putExtra(ApplozicMqttIntentService.CONNECTED_PUBLISH,true);
// ApplozicMqttIntentService.enqueueWork(context, intent);
// return registrationResponse;
public RegistrationResponse createAccount(User user) throws Exception {
user.setDeviceType(Short.valueOf("1"));
user.setPrefContactAPI(Short.valueOf("2"));
user.setTimezone(TimeZone.getDefault().getID());
user.setEnableEncryption(user.isEnableEncryption());
MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
Gson gson = new Gson();
user.setAppVersionCode(MOBICOMKIT_VERSION_CODE);
user.setApplicationId(getApplicationKey(context));
user.setRegistrationId(mobiComUserPreference.getDeviceRegistrationId());
if (getAppModuleName(context) != null) {
user.setAppModuleName(getAppModuleName(context));
}
Utils.printLog(context, TAG, "Net status" + Utils.isInternetAvailable(context.getApplicationContext()));
if (!Utils.isInternetAvailable(context.getApplicationContext())) {
throw new ConnectException("No Internet Connection");
}
// Log.i(TAG, "App Id is: " + getApplicationKey(context));
Utils.printLog(context, TAG, "Registration json " + gson.toJson(user));
String response = httpRequestUtils.postJsonToServer(getCreateAccountUrl(), gson.toJson(user));
Utils.printLog(context, TAG, "Registration response is: " + response);
if (TextUtils.isEmpty(response) || response.contains("<html")) {
throw new Exception("503 Service Unavailable");
// return null;
}
if (response.contains(INVALID_APP_ID)) {
throw new InvalidApplicationException("Invalid Application Id");
}
final RegistrationResponse registrationResponse = gson.fromJson(response, RegistrationResponse.class);
if (registrationResponse.isPasswordInvalid()) {
throw new UnAuthoriseException("Invalid uername/password");
}
Utils.printLog(context, "Registration response ", "is " + registrationResponse);
if (registrationResponse.getNotificationResponse() != null) {
Utils.printLog(context, "Registration response ", "" + registrationResponse.getNotificationResponse());
}
mobiComUserPreference.setEncryptionKey(registrationResponse.getEncryptionKey());
mobiComUserPreference.enableEncryption(user.isEnableEncryption());
mobiComUserPreference.setCountryCode(user.getCountryCode());
mobiComUserPreference.setUserId(user.getUserId());
mobiComUserPreference.setContactNumber(user.getContactNumber());
mobiComUserPreference.setEmailVerified(user.isEmailVerified());
mobiComUserPreference.setDisplayName(user.getDisplayName());
mobiComUserPreference.setMqttBrokerUrl(registrationResponse.getBrokerUrl());
mobiComUserPreference.setDeviceKeyString(registrationResponse.getDeviceKey());
mobiComUserPreference.setEmailIdValue(user.getEmail());
mobiComUserPreference.setImageLink(user.getImageLink());
mobiComUserPreference.setSuUserKeyString(registrationResponse.getUserKey());
mobiComUserPreference.setLastSyncTimeForMetadataUpdate(String.valueOf(registrationResponse.getCurrentTimeStamp()));
mobiComUserPreference.setLastSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
mobiComUserPreference.setLastSeenAtSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
mobiComUserPreference.setChannelSyncTime(String.valueOf(registrationResponse.getCurrentTimeStamp()));
mobiComUserPreference.setUserBlockSyncTime("10000");
mobiComUserPreference.setPassword(user.getPassword());
mobiComUserPreference.setPricingPackage(registrationResponse.getPricingPackage());
mobiComUserPreference.setAuthenticationType(String.valueOf(user.getAuthenticationTypeId()));
mobiComUserPreference.setUserRoleType(user.getRoleType());
if (user.getUserTypeId() != null) {
mobiComUserPreference.setUserTypeId(String.valueOf(user.getUserTypeId()));
}
if (!TextUtils.isEmpty(user.getNotificationSoundFilePath())) {
mobiComUserPreference.setNotificationSoundFilePath(user.getNotificationSoundFilePath());
}
Contact contact = new Contact();
contact.setUserId(user.getUserId());
contact.setFullName(registrationResponse.getDisplayName());
contact.setImageURL(registrationResponse.getImageLink());
contact.setContactNumber(registrationResponse.getContactNumber());
if (user.getUserTypeId() != null) {
contact.setUserTypeId(user.getUserTypeId());
}
contact.setRoleType(user.getRoleType());
contact.setMetadata(user.getMetadata());
contact.setStatus(registrationResponse.getStatusMessage());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel(context);
}
contact.processContactNumbers(context);
new AppContactService(context).upsert(contact);
Intent conversationIntentService = new Intent(context, ConversationIntentService.class);
conversationIntentService.putExtra(ConversationIntentService.SYNC, false);
ConversationIntentService.enqueueWork(context, conversationIntentService);
Intent mutedUserListService = new Intent(context, ConversationIntentService.class);
mutedUserListService.putExtra(ConversationIntentService.MUTED_USER_LIST_SYNC, true);
ConversationIntentService.enqueueWork(context, mutedUserListService);
Intent intent = new Intent(context, ApplozicMqttIntentService.class);
intent.putExtra(ApplozicMqttIntentService.CONNECTED_PUBLISH, true);
ApplozicMqttIntentService.enqueueWork(context, intent);
return registrationResponse;
}
use of com.applozic.mobicomkit.exception.UnAuthoriseException in project Applozic-Android-SDK by AppLozic.
the class RegisterUserClientService method updateRegisteredAccount.
public RegistrationResponse updateRegisteredAccount(User user) throws Exception {
RegistrationResponse registrationResponse = null;
user.setDeviceType(Short.valueOf("1"));
user.setPrefContactAPI(Short.valueOf("2"));
user.setTimezone(TimeZone.getDefault().getID());
MobiComUserPreference mobiComUserPreference = MobiComUserPreference.getInstance(context);
Gson gson = new Gson();
user.setEnableEncryption(mobiComUserPreference.isEncryptionEnabled());
user.setAppVersionCode(MOBICOMKIT_VERSION_CODE);
user.setApplicationId(getApplicationKey(context));
user.setAuthenticationTypeId(Short.valueOf(mobiComUserPreference.getAuthenticationType()));
if (!TextUtils.isEmpty(mobiComUserPreference.getUserTypeId())) {
user.setUserTypeId(Short.valueOf(mobiComUserPreference.getUserTypeId()));
}
if (getAppModuleName(context) != null) {
user.setAppModuleName(getAppModuleName(context));
}
if (!TextUtils.isEmpty(mobiComUserPreference.getDeviceRegistrationId())) {
user.setRegistrationId(mobiComUserPreference.getDeviceRegistrationId());
}
Utils.printLog(context, TAG, "Registration update json " + gson.toJson(user));
String response = httpRequestUtils.postJsonToServer(getUpdateAccountUrl(), gson.toJson(user));
if (TextUtils.isEmpty(response) || response.contains("<html")) {
throw null;
}
if (response.contains(INVALID_APP_ID)) {
throw new InvalidApplicationException("Invalid Application Id");
}
registrationResponse = gson.fromJson(response, RegistrationResponse.class);
if (registrationResponse.isPasswordInvalid()) {
throw new UnAuthoriseException("Invalid uername/password");
}
Utils.printLog(context, TAG, "Registration update response: " + registrationResponse);
mobiComUserPreference.setPricingPackage(registrationResponse.getPricingPackage());
if (registrationResponse.getNotificationResponse() != null) {
Utils.printLog(context, TAG, "Notification response: " + registrationResponse.getNotificationResponse());
}
return registrationResponse;
}
Aggregations