use of org.flyve.mdm.agent.data.localstorage.UserData in project android-mdm-agent by flyve-mdm.
the class UserModel method load.
@Override
public void load(Context context) {
UserSchema userSchema = new UserSchema();
UserData user = new UserData(context);
userSchema.setEmails(user.getEmails());
userSchema.setFirstName(user.getFirstName());
userSchema.setLastName(user.getLastName());
userSchema.setPhone(user.getPhone());
userSchema.setPhone2(user.getPhone2());
userSchema.setMobilePhone(user.getMobilePhone());
userSchema.setLanguage(user.getLanguage());
userSchema.setPicture(user.getPicture());
userSchema.setAdministrativeNumber(user.getAdministrativeNumber());
presenter.loadSuccess(userSchema);
}
use of org.flyve.mdm.agent.data.localstorage.UserData in project android-mdm-agent by flyve-mdm.
the class EnrollmentModel method enroll.
@Override
public void enroll(final Activity activity, final List<UserData.EmailsData> arrEmails, final String firstName, final String lastName, final String phone, final String phone2, final String mobilePhone, final String inventory, final String photo, final String language, final String administrativeNumber) {
StringBuilder errMsg = new StringBuilder(activity.getResources().getString(R.string.validate_error));
boolean allow = true;
Helpers.hideKeyboard(activity);
if (arrEmails.isEmpty() || arrEmails.get(0).getEmail().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_email_at_least_one));
allow = false;
}
if (firstName.trim().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_first_name));
allow = false;
}
if (lastName.trim().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_last_name));
allow = false;
}
if (inventory.contains("fail")) {
errMsg.append(activity.getResources().getString(R.string.validate_inventory));
allow = false;
}
// inventory running
if (inventory.equals("")) {
errMsg.append(activity.getResources().getString(R.string.inventory_not_exists));
allow = false;
}
if (!allow) {
presenter.showSnackError(CommonErrorType.ENROLLMENT_FIELD_VALIDATION, activity.getResources().getString(R.string.validate_check_details));
presenter.showDetailError(CommonErrorType.ENROLLMENT_FIELD_VALIDATION, errMsg.toString());
return;
}
try {
AndroidCryptoProvider csr = new AndroidCryptoProvider(activity);
String requestCSR = "";
if (csr.getlCsr() != null) {
requestCSR = URLEncoder.encode(csr.getlCsr(), "UTF-8");
}
MqttData cache = new MqttData(activity);
String invitationToken = cache.getInvitationToken();
JSONObject payload = new JSONObject();
String mInventory = Helpers.base64encode(inventory.trim());
// get first email
payload.put("_email", arrEmails.get(0).getEmail());
payload.put("_invitation_token", invitationToken);
payload.put("_serial", Helpers.getDeviceSerial());
payload.put("_uuid", new Hardware(activity).getUUID());
payload.put("csr", requestCSR);
payload.put("firstname", firstName);
payload.put("lastname", lastName);
payload.put("phone", phone);
payload.put("version", BuildConfig.VERSION_NAME);
payload.put("type", "android");
payload.put("has_system_permission", Helpers.isSystemApp(activity));
payload.put("inventory", mInventory);
// could be mqtt or fcm
payload.put("notification_type", "mqtt");
// this is the token get from fcm register
payload.put("notification_token", "");
FlyveLog.d(mInventory);
EnrollmentHelper enroll = new EnrollmentHelper(activity);
enroll.enrollment(payload, new EnrollmentHelper.EnrollCallBack() {
@Override
public void onSuccess(String data) {
// -------------------------------
// Store user information
// -------------------------------
UserData userData = new UserData(activity);
userData.setFirstName(firstName);
userData.setLastName(lastName);
userData.setEmails(arrEmails);
userData.setPicture(photo);
userData.setLanguage(language);
userData.setAdministrativeNumber(administrativeNumber);
// -------------------------------
// Remove Deeplink information
// -------------------------------
MqttData cache = new MqttData(activity);
cache.setInvitationToken("");
presenter.enrollSuccess();
}
@Override
public void onError(int type, String error) {
presenter.showSnackError(type, error);
}
});
} catch (Exception ex) {
presenter.showSnackError(CommonErrorType.ENROLLMENT_REQUEST_EXCEPTION, ex.getMessage());
}
}
use of org.flyve.mdm.agent.data.localstorage.UserData in project android-mdm-agent by flyve-mdm.
the class EditUserActivity method save.
/**
* Storage information
*/
private void save() {
UserSchema userSchema = new UserSchema();
// -------------
// Emails
// -------------
ArrayList<UserData.EmailsData> arrEmails = new ArrayList<>();
List<EditText> emailEdit = editEmail.getEditList();
List<Spinner> emailTypeEdit = editEmail.getSpinnList();
if (!emailEdit.isEmpty()) {
for (int i = 0; i < emailEdit.size(); i++) {
UserData.EmailsData emails = new UserData(EditUserActivity.this).new EmailsData();
EditText editText = emailEdit.get(i);
Spinner spinner = emailTypeEdit.get(i);
if (!editText.getText().toString().equals("")) {
emails.setEmail(editText.getText().toString());
emails.setType(spinner.getSelectedItem().toString());
arrEmails.add(emails);
}
}
}
if (!arrEmails.isEmpty()) {
userSchema.setEmails(arrEmails);
}
userSchema.setFirstName(editName.getText().toString());
userSchema.setLastName(editLastName.getText().toString());
userSchema.setPicture(strPicture);
userSchema.setLanguage(spinnerLanguage.getSelectedItem().toString());
userSchema.setAdministrativeNumber(editAdministrative.getText().toString());
// Mobile Phone
if (!editPhone.getEditList().isEmpty()) {
String mobilePhone = editPhone.getEditList().get(0).getText().toString();
if (!mobilePhone.equals("")) {
userSchema.setMobilePhone(mobilePhone);
}
}
// Phone
if (editPhone.getEditList().size() > 1) {
String phone = editPhone.getEditList().get(1).getText().toString();
if (!phone.equals("")) {
userSchema.setPhone(phone);
}
}
// Phone 2
if (editPhone.getEditList().size() > 2) {
String phone2 = editPhone.getEditList().get(2).getText().toString();
if (!phone2.equals("")) {
userSchema.setPhone2(phone2);
}
}
presenter.save(EditUserActivity.this, userSchema);
}
use of org.flyve.mdm.agent.data.localstorage.UserData in project android-mdm-agent by flyve-mdm.
the class EnrollmentModel method enroll.
@Override
public void enroll(final Activity activity, final List<UserData.EmailsData> arrEmails, final String firstName, final String lastName, final String phone, final String phone2, final String mobilePhone, final String inventory, final String photo, final String language, final String administrativeNumber, final String notificationToken, Context context) {
StringBuilder errMsg = new StringBuilder(activity.getResources().getString(R.string.validate_error));
boolean allow = true;
Helpers.hideKeyboard(activity);
if (arrEmails.isEmpty() || arrEmails.get(0).getEmail().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_email_at_least_one));
allow = false;
}
if (firstName.trim().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_first_name));
allow = false;
}
if (lastName.trim().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_last_name));
allow = false;
}
if (notificationToken.equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_fcm_token));
allow = false;
}
if (inventory.contains("fail")) {
errMsg.append(activity.getResources().getString(R.string.validate_inventory));
allow = false;
}
// inventory running
if (inventory.equals("")) {
errMsg.append(activity.getResources().getString(R.string.inventory_not_exists));
allow = false;
}
if (!allow) {
presenter.showSnackError(CommonErrorType.ENROLLMENT_FIELD_VALIDATION, activity.getResources().getString(R.string.validate_check_details));
presenter.showDetailError(CommonErrorType.ENROLLMENT_FIELD_VALIDATION, errMsg.toString());
return;
}
try {
MqttData cache = new MqttData(activity);
String invitationToken = cache.getInvitationToken();
JSONObject payload = new JSONObject();
String mInventory = Helpers.base64encode(inventory.trim());
// get first email
payload.put("_email", arrEmails.get(0).getEmail());
payload.put("_invitation_token", invitationToken);
payload.put("_serial", Helpers.getDeviceSerial());
payload.put("_uuid", new Hardware(activity).getUUID());
payload.put("csr", "");
payload.put("firstname", firstName);
payload.put("lastname", lastName);
payload.put("phone", phone);
payload.put("version", BuildConfig.VERSION_NAME);
payload.put("type", "android");
payload.put("has_system_permission", Helpers.isSystemApp(activity));
payload.put("inventory", mInventory);
// could be mqtt or fcm
payload.put("notification_type", "fcm");
// this is the token get from fcm register
payload.put("notification_token", notificationToken);
FlyveLog.d(mInventory);
EnrollmentHelper enroll = new EnrollmentHelper(activity);
enroll.enrollment(payload, new EnrollmentHelper.EnrollCallBack() {
@Override
public void onSuccess(String data) {
// -------------------------------
// Store user information
// -------------------------------
UserData userData = new UserData(activity);
userData.setFirstName(firstName);
userData.setLastName(lastName);
userData.setEmails(arrEmails);
userData.setPicture(photo);
userData.setLanguage(language);
userData.setAdministrativeNumber(administrativeNumber);
// -------------------------------
// Remove Deeplink information
// -------------------------------
MqttData cache = new MqttData(activity);
cache.setInvitationToken("");
presenter.enrollSuccess();
}
@Override
public void onError(int type, String error) {
presenter.showSnackError(type, error);
}
});
} catch (Exception ex) {
presenter.showSnackError(CommonErrorType.ENROLLMENT_REQUEST_EXCEPTION, ex.getMessage());
}
}
use of org.flyve.mdm.agent.data.localstorage.UserData in project android-mdm-agent by flyve-mdm.
the class UserModel method save.
@Override
public void save(Activity activity, UserSchema schema) {
StringBuilder errMsg = new StringBuilder(activity.getResources().getString(R.string.validate_error));
boolean allow = true;
Helpers.hideKeyboard(activity);
if (schema.getEmails().isEmpty() || schema.getEmails().get(0).getEmail().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_email_at_least_one));
allow = false;
}
if (schema.getFirstName().trim().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_first_name));
allow = false;
}
if (schema.getLastName().trim().equals("")) {
errMsg.append(activity.getResources().getString(R.string.validate_last_name));
allow = false;
}
if (!allow) {
presenter.showDetailError(CommonErrorType.USER_SAVE_VALIDATION, errMsg.toString());
return;
}
// -------------
try {
UserData user = new UserData(activity);
user.setFirstName(schema.getFirstName());
user.setLastName(schema.getLastName());
user.setEmails(schema.getEmails());
user.setPhone(schema.getPhone());
user.setPhone2(schema.getPhone2());
user.setMobilePhone(schema.getMobilePhone());
user.setPicture(schema.getPicture());
user.setLanguage(schema.getLanguage());
user.setAdministrativeNumber(schema.getAdministrativeNumber());
presenter.saveSuccess();
} catch (Exception ex) {
FlyveLog.e(this.getClass().getName() + ", save", ex.getMessage());
presenter.showDetailError(CommonErrorType.USER_SAVE_EXCEPTION, ex.getMessage());
}
}
Aggregations