use of ca.etsmtl.applets.etsmobile.model.UserCredentials in project ETSMobile-Android2 by ApplETS.
the class ApplicationManager method onCreate.
@Override
public void onCreate() {
super.onCreate();
AnalyticsHelper.getInstance(this);
createDatabaseTables();
// SupportKit.init(this, getString(R.string.credentials_supportkit));
// Fabric.with(this, new Crashlytics());
AccountManager accountManager = AccountManager.get(this);
Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
String username = "", password = "";
if (accounts.length > 0) {
username = accounts[0].name;
password = accountManager.getPassword(accounts[0]);
}
if (username.length() > 0 && password.length() > 0) {
userCredentials = new UserCredentials(username, password);
}
SecurePreferences securePreferences = new SecurePreferences(this);
int typeUsagerId = securePreferences.getInt(Constants.TYPE_USAGER_ID, -1);
String domaine = securePreferences.getString(Constants.DOMAINE, "");
if (typeUsagerId != -1 && !TextUtils.isEmpty(domaine)) {
ApplicationManager.typeUsagerId = typeUsagerId;
ApplicationManager.domaine = domaine;
}
}
use of ca.etsmtl.applets.etsmobile.model.UserCredentials in project ETSMobile-Android2 by ApplETS.
the class LoginActivity method attemptLogin.
/**
* Attempts to sign in or register the account specified by the login form.
* If there are form errors (invalid email, missing fields, etc.), the
* errors are presented and no actual login attempt is made.
*/
public void attemptLogin() {
// Reset errors.
mEmailView.setError(null);
mPasswordView.setError(null);
// Store values at the time of the login attempt.
mEmail = mEmailView.getText().toString();
mPassword = mPasswordView.getText().toString();
boolean cancel = false;
View focusView = null;
// Check for a valid password.
if (TextUtils.isEmpty(mPassword)) {
mPasswordView.setError(getString(R.string.error_field_required));
focusView = mPasswordView;
cancel = true;
}
// Check for a valid email address.
if (TextUtils.isEmpty(mEmail)) {
mEmailView.setError(getString(R.string.error_field_required));
focusView = mEmailView;
cancel = true;
} else if (!mEmail.matches("[a-zA-z]{2}(\\d){5}")) {
mEmailView.setError(getString(R.string.error_invalid_email));
focusView = mEmailView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
mLoginStatusMessageView.setText(R.string.login_progress_signing_in);
showProgress(true);
userCredentials = new UserCredentials(mEmail, mPassword);
dataManager.login(userCredentials, this);
}
}
Aggregations