@Override protected LoginResults doInBackground(Void... params) { Firebase ref = new Firebase(FIREBASE_URL); ref.authWithPassword( mEmail, mPassword, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { System.out.println( "User ID: " + authData.getUid() + ", Provider: " + authData.getProvider()); loginResults.setAuthSuccess(true); userEmail = mEmail; } @Override public void onAuthenticationError(FirebaseError firebaseError) { // There was an error loginResults.setAuthSuccess(false); loginResults.setError(firebaseError); } }); try { // Simulate network access Thread.sleep(2000); } catch (InterruptedException e) { return loginResults; } return loginResults; }
public void onClick1(View view) { EditText editText1 = (EditText) findViewById(R.id.editText); EditText editText2 = (EditText) findViewById(R.id.editText2); String email = editText1.getText().toString(); String password = editText2.getText().toString(); Firebase.setAndroidContext(getApplicationContext()); Firebase ref = new Firebase("https://relationalmanac1.firebaseio.com/"); ref.authWithPassword( email, password, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { Intent g = new Intent(LoginActivity.this, MainActivity.class); startActivity(g); finish(); } @Override public void onAuthenticationError(FirebaseError firebaseError) { Toast.makeText(LoginActivity.this, "Wrong Email or password", Toast.LENGTH_SHORT) .show(); } }); }
public void connect(String email, String password) { firebase.authWithPassword( email, password, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { isConnected = true; username = authData.getProviderData().get("email").toString(); userId = authData.getUid(); } @Override public void onAuthenticationError(FirebaseError firebaseError) {} }); }
public void logIn(View v) { mEmail = ((EditText) findViewById(R.id.editText)).getText().toString(); mPassword = ((EditText) findViewById(R.id.editText2)).getText().toString(); ref.authWithPassword( mEmail, mPassword, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { Toast.makeText(getApplicationContext(), "Log In Successful!", Toast.LENGTH_SHORT) .show(); user = ref.child("users").child(authData.getUid()); ref.child("users") .child(authData.getUid()) .child("fullName") .addValueEventListener( new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { name = snapshot.getValue().toString(); } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The read failed: " + firebaseError.getMessage()); } }); Intent intent = new Intent(getApplicationContext(), DeliveryList.class); startActivity(intent); } @Override public void onAuthenticationError(FirebaseError firebaseError) { Toast.makeText( getApplicationContext(), "Email or Password incorrect", Toast.LENGTH_SHORT) .show(); // there was an error } }); }
@Override public void signIn(String email, String password, final AuthCallback callback) { firebase.authWithPassword( email, password, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { if ((boolean) authData.getProviderData().get("isTemporaryPassword")) { callback.onError(TEMPORARY_PASSWORD); } else { FirebaseCollection<User> users = new FirebaseCollection<>(Constants.USERS, User.class); users.get( authData.getUid(), new DataCallback<User>() { @Override public void onSuccess(User user) { callback.onSuccess(user); } @Override public void onError(String errorMessage) { callback.onError(errorMessage); } }); } } @Override public void onAuthenticationError(FirebaseError firebaseError) { // FireBaseErrorHandler.getErrorMessage(firebaseError, FirebaseAuth.this) callback.onError(FireBaseErrorHandler.getErrorMessage(firebaseError, context)); } }); }
@Override protected Boolean doInBackground(Void... params) { // Fire base reference for login and writting data. final Firebase myFirebaseRef = new Firebase("https://todorpg.firebaseio.com/"); // attempt authentication against a network service. myFirebaseRef.authWithPassword( mEmail, mPassword, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(final AuthData authData) { CheckBox rememberMe = (CheckBox) findViewById(R.id.autoLoginBox); // Save in Preferences if remember me is checked. if (rememberMe.isChecked()) { SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("rememberMe", true); editor.putString("username", mEmail); editor.putString("password", mPassword); editor.commit(); } else { SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean("rememberMe", false); editor.commit(); } myFirebaseRef.addListenerForSingleValueEvent( new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { long numTasks = (long) snapshot .child("Users") .child(authData.getUid()) .child("numTasks") .getValue(); // Create an account for the data passed only the User ID. Account account = new Account("user", "pass", authData.getUid(), 0, (int) numTasks); // Pass the account to the start of the task activity via intent. System.out.println( snapshot .child("Users") .child(authData.getUid()) .child("intelligenceXP") .getValue()); long intelligenceXP = (long) snapshot .child("Users") .child(authData.getUid()) .child("intelligenceXP") .getValue(); long healthXP = (long) snapshot .child("Users") .child(authData.getUid()) .child("healthXP") .getValue(); long fitnessXP = (long) snapshot .child("Users") .child(authData.getUid()) .child("fitnessXP") .getValue(); long charismaXP = (long) snapshot .child("Users") .child(authData.getUid()) .child("charismaXP") .getValue(); account.setCharismaXP(Integer.parseInt(Long.toString(charismaXP))); account.setHealthXP(Integer.parseInt(Long.toString(healthXP))); account.setFitnessXP(Integer.parseInt(Long.toString(fitnessXP))); account.setIntelligenceXP(Integer.parseInt(Long.toString(intelligenceXP))); Intent i = new Intent(getApplicationContext(), TaskPage.class); i.putExtra("Account", account); // finish(); startActivity(i); finish(); } @Override public void onCancelled(FirebaseError firebaseError) {} }); } @Override public void onAuthenticationError(FirebaseError firebaseError) { Toast.makeText(LoginActivity.this, "No Authentication", Toast.LENGTH_LONG).show(); Intent intent = getIntent(); // finish(); startActivity(intent); finish(); } }); // tr to register the new account here if could not authenciate. myFirebaseRef.createUser( mEmail, mPassword, new Firebase.ValueResultHandler<Map<String, Object>>() { @Override public void onSuccess(Map<String, Object> result) { Account account = new Account(mEmail, mPassword, (String) result.get("uid"), 1, 0); account.setFitnessXP(0); account.setIntelligenceXP(0); account.setHealthXP(0); account.setCharismaXP(0); // Store Account data on success. Firebase ref = new Firebase("https://todorpg.firebaseio.com/Users").child(account.getUserID()); // Write basic user Data to database. ref.child("email").setValue(account.getUsername()); ref.child("Password").setValue(account.getPassword()); ref.child("numTasks").setValue(account.getNumTasks()); ref.child("fitnessXP").setValue(account.getFitnessXP()); ref.child("charismaXP").setValue(account.getCharismaXP()); ref.child("intelligenceXP").setValue(account.getIntelligenceXP()); ref.child("healthXP").setValue(account.getHealthXP()); Toast.makeText(LoginActivity.this, "New User", Toast.LENGTH_LONG).show(); // Start Task page activity. Intent i = new Intent(getApplicationContext(), TaskPage.class); i.putExtra("Account", account); // finish(); startActivity(i); finish(); } @Override public void onError(FirebaseError firebaseError) { Toast.makeText(LoginActivity.this, "Did not make new User", Toast.LENGTH_LONG).show(); Intent intent = getIntent(); // finish(); startActivity(intent); finish(); } }); return true; }
private void addDetails() { firebaseRef.authWithPassword( emailS, password, new AuthResultHandler("password", firstName, lastName, emailS)); }
private void loggingUser() { ringProgressDialog = ProgressDialog.show( MobileVerificationActivity.this, "Please wait ...", "Signing In User ...", true); ringProgressDialog.setCancelable(true); // InstanceID instanceID = InstanceID.getInstance(this); // String token = ""; // try { // token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), // GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); // } catch (IOException e) { // e.printStackTrace(); // } // Log.v("Token!", "Token: "+token); final Firebase ref = new Firebase(Constants.BASE_URL); Log.v("asda", "Password before logging in: " + password); // final String finalToken = token; ref.authWithPassword( emailAuth, password, new Firebase.AuthResultHandler() { @Override public void onAuthenticated(AuthData authData) { Log.v(Tag, "Logging AuthData: " + authData.toString()); Log.v(Tag, "Logging AuthData.getUid(): " + authData.getUid().toString()); Log.v(Tag, "Logging AuthData.getAuth(): " + authData.getAuth().toString()); Log.v(Tag, "Logging AuthData.getExpires(): " + authData.getExpires()); Log.v(Tag, "Logging AuthData.getProvider(): " + authData.getProvider()); Log.v(Tag, "Logging AuthData.getToken(): " + authData.getToken()); Log.v(Tag, "Logging AuthData.getUid(): " + authData.getProviderData()); System.out.println( "User ID: " + authData.getUid() + ", Provider: " + authData.getProvider()); // Authentication just completed successfully :) Map<String, Object> map = new HashMap<String, Object>(); map.put("provider", authData.getProvider()); if (authData.getProviderData().containsKey("id")) { map.put("provider_id", authData.getProviderData().get("id").toString()); } if (!emailString.equalsIgnoreCase("")) { map.put("email", emailString); } map.put("displayName", firstNameString); map.put("firstName", firstNameString); map.put("lastName", lastNameString); map.put("userId", authData.getUid()); map.put("mobileNumber", completeMobileNumber); if (!profileImageString.equalsIgnoreCase("")) { map.put("profileImageString", profileImageString); } else { map.put("profileImageString", ""); } // map.put("token", finalToken); if (selectedUserString.equalsIgnoreCase("p")) { map.put("privateRegistered", "true"); } else if (selectedUserString.equalsIgnoreCase("b")) { map.put("businessRegistered", "true"); map.put("privateRegistered", "true"); } else if (selectedUserString.equalsIgnoreCase("a")) { map.put("agentRegistered", "true"); // map.put("businessRegistered", "true"); map.put("privateRegistered", "true"); } ref.child("users").child(authData.getUid()).updateChildren(map); // ref.child("users").child(completeMobileNumber).updateChildren(map); // // ref.child("users").child(authData.getProviderData().get("email").toString()).setValue(map); userId = authData.getUid(); preferenceSettings = getSharedPreferences(Constants.MY_PREFS_NAME, MODE_PRIVATE); preferenceEditor = preferenceSettings.edit(); preferenceEditor.putString("userId", authData.getUid()); preferenceEditor.putString("email", emailString); preferenceEditor.putString("firstName", firstNameString); preferenceEditor.putString("lastName", lastNameString); preferenceEditor.putString("displayName", firstNameString); preferenceEditor.putString("mobileNumber", completeMobileNumber); preferenceEditor.putString("selectedUserString", selectedUserString); if (!profileImageString.equalsIgnoreCase("")) { preferenceEditor.putString("profileImageString", profileImageString); } preferenceEditor.putString("unit", "kms"); preferenceEditor.putString("voice", "on"); // preferenceEditor.putString("token", finalToken); preferenceEditor.commit(); ringProgressDialog.dismiss(); // Initialising User - Generate GCM Token updateProfile(); if (checkPlayServices()) { // Start IntentService to register this application with GCM. GCMringProgressDialog = ProgressDialog.show( MobileVerificationActivity.this, "Please wait ...", "Initialising User ...", true); GCMringProgressDialog.setCancelable(true); Intent intent = new Intent(MobileVerificationActivity.this, RegistrationIntentService.class); startService(intent); } // Start Private Main Activity } @Override public void onAuthenticationError(FirebaseError firebaseError) { // there was an error ringProgressDialog.dismiss(); switch (firebaseError.getCode()) { case FirebaseError.USER_DOES_NOT_EXIST: // handle a non existing user Log.v(Tag, "Register Error Code: USER_DOES_NOT_EXIST"); Toast.makeText(getApplicationContext(), "NETWORK_ERROR", Toast.LENGTH_LONG).show(); break; case FirebaseError.INVALID_PASSWORD: // handle an invalid password Log.v(Tag, "Register Error Code: INVALID_PASSWORD"); Toast.makeText(getApplicationContext(), "NETWORK_ERROR", Toast.LENGTH_LONG).show(); break; case FirebaseError.AUTHENTICATION_PROVIDER_DISABLED: // handle an invalid password Log.v(Tag, "Register Error Code: AUTHENTICATION_PROVIDER_DISABLED"); Toast.makeText(getApplicationContext(), "NETWORK_ERROR", Toast.LENGTH_LONG).show(); break; case FirebaseError.EMAIL_TAKEN: // handle an invalid password Log.v(Tag, "Register Error Code: EMAIL_TAKEN"); Toast.makeText(getApplicationContext(), "EMAIL_TAKEN", Toast.LENGTH_LONG).show(); break; case FirebaseError.INVALID_AUTH_ARGUMENTS: // handle an invalid password Log.v(Tag, "Register Error Code: INVALID_AUTH_ARGUMENTS"); Toast.makeText(getApplicationContext(), "INVALID_AUTH_ARGUMENTS", Toast.LENGTH_LONG) .show(); break; case FirebaseError.INVALID_CONFIGURATION: // handle an invalid password Log.v(Tag, "IRegister Error Code: INVALID_CONFIGURATION"); Toast.makeText(getApplicationContext(), "INVALID_CONFIGURATION", Toast.LENGTH_LONG) .show(); break; case FirebaseError.INVALID_CREDENTIALS: // handle an invalid password Log.v(Tag, "Register Error Code: INVALID_CREDENTIALS"); Toast.makeText(getApplicationContext(), "INVALID_CREDENTIALS", Toast.LENGTH_LONG) .show(); break; case FirebaseError.INVALID_EMAIL: // handle an invalid password Log.v(Tag, "Register Error Code: INVALID_EMAIL"); Toast.makeText(getApplicationContext(), "INVALID_EMAIL", Toast.LENGTH_LONG).show(); break; case FirebaseError.INVALID_TOKEN: // handle an invalid password Log.v(Tag, "Register Error Code: INVALID_TOKEN"); Toast.makeText(getApplicationContext(), "INVALID_TOKEN", Toast.LENGTH_LONG).show(); break; case FirebaseError.NETWORK_ERROR: // handle an invalid password Log.v(Tag, "Register Error Code: NETWORK_ERROR"); Toast.makeText(getApplicationContext(), "NETWORK_ERROR", Toast.LENGTH_LONG).show(); break; case FirebaseError.PREEMPTED: // handle an invalid password Log.v(Tag, "Register Error Code: PREEMPTED"); Toast.makeText(getApplicationContext(), "PREEMPTED", Toast.LENGTH_LONG).show(); break; case FirebaseError.PROVIDER_ERROR: // handle an invalid password Log.v(Tag, "Register Error Code: PROVIDER_ERROR"); Toast.makeText(getApplicationContext(), "PROVIDER_ERROR", Toast.LENGTH_LONG).show(); break; case FirebaseError.UNKNOWN_ERROR: // handle an invalid password Log.v(Tag, "Register Error Code: UNKNOWN_ERROR"); Toast.makeText(getApplicationContext(), "UNKNOWN_ERROR", Toast.LENGTH_LONG).show(); break; case FirebaseError.DENIED_BY_USER: // handle an invalid password Log.v(Tag, "Register Error Code: DENIED_BY_USER"); Toast.makeText(getApplicationContext(), "DENIED_BY_USER", Toast.LENGTH_LONG).show(); break; default: // handle other errors Log.v(Tag, "Register Error Code: DEFAULT ERROR"); Toast.makeText(getApplicationContext(), "DEFAULT ERROR", Toast.LENGTH_LONG).show(); break; } } }); }