Search in sources :

Example 1 with UserCredentials

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;
    }
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) UserCredentials(ca.etsmtl.applets.etsmobile.model.UserCredentials) SecurePreferences(ca.etsmtl.applets.etsmobile.util.SecurePreferences)

Example 2 with UserCredentials

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);
    }
}
Also used : UserCredentials(ca.etsmtl.applets.etsmobile.model.UserCredentials) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Aggregations

UserCredentials (ca.etsmtl.applets.etsmobile.model.UserCredentials)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SecurePreferences (ca.etsmtl.applets.etsmobile.util.SecurePreferences)1