use of com.google.firebase.auth.FirebaseUser in project quickstart-android by firebase.
the class EmailPasswordActivity method sendEmailVerification.
private void sendEmailVerification() {
// Disable button
findViewById(R.id.verify_email_button).setEnabled(false);
// Send verification email
// [START send_email_verification]
final FirebaseUser user = mAuth.getCurrentUser();
user.sendEmailVerification().addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// [START_EXCLUDE]
// Re-enable button
findViewById(R.id.verify_email_button).setEnabled(true);
if (task.isSuccessful()) {
Toast.makeText(EmailPasswordActivity.this, "Verification email sent to " + user.getEmail(), Toast.LENGTH_SHORT).show();
} else {
Log.e(TAG, "sendEmailVerification", task.getException());
Toast.makeText(EmailPasswordActivity.this, "Failed to send verification email.", Toast.LENGTH_SHORT).show();
}
// [END_EXCLUDE]
}
});
// [END send_email_verification]
}
use of com.google.firebase.auth.FirebaseUser in project quickstart-android by firebase.
the class GoogleSignInActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google);
// Views
mStatusTextView = (TextView) findViewById(R.id.status);
mDetailTextView = (TextView) findViewById(R.id.detail);
// Button listeners
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
findViewById(R.id.disconnect_button).setOnClickListener(this);
// [START config_signin]
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
// [END config_signin]
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, /* FragmentActivity */
this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
// [START initialize_auth]
mAuth = FirebaseAuth.getInstance();
// [END initialize_auth]
// [START auth_state_listener]
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// [START_EXCLUDE]
updateUI(user);
// [END_EXCLUDE]
}
};
// [END auth_state_listener]
}
use of com.google.firebase.auth.FirebaseUser in project NPSmiles by bmcglynn1.
the class LoginAuth method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_auth);
setTitle("Login");
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// ...
}
};
final EditText emailText = (EditText) findViewById(R.id.emailEditText);
final EditText passwordText = (EditText) findViewById(R.id.passwordEditText);
Button loginButton = (Button) findViewById(R.id.loginButton);
loginButton.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
if (emailText.getText().toString().length() != 0 && passwordText.getText().toString().length() != 0) {
signIn(emailText.getText().toString(), passwordText.getText().toString());
}
}
});
findViewById(R.id.relativeLayoutLogin).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindow().getDecorView().getRootView().getWindowToken(), 0);
return true;
}
});
}
use of com.google.firebase.auth.FirebaseUser in project NPSmiles by bmcglynn1.
the class MainActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
FirebaseUser user = mAuth.getCurrentUser();
optionsMenu = menu;
if (user == null) {
getMenuInflater().inflate(R.menu.menu_main_unauthorized, menu);
} else {
getMenuInflater().inflate(R.menu.menu_main, menu);
}
return true;
}
use of com.google.firebase.auth.FirebaseUser in project MadMax by deviz92.
the class SignUpFragment method sendVerificationEmail.
private void sendVerificationEmail() {
Log.i(TAG, "sendVerificationEmail");
final FirebaseUser user = auth.getCurrentUser();
if (user == null) {
Log.e(TAG, "Error while retriving current user from db");
Toast.makeText(getContext(), getString(R.string.error_user_db), Toast.LENGTH_LONG).show();
return;
}
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this.getContext());
String defaultCurrency = sharedPref.getString(SettingsFragment.DEFAULT_CURRENCY, "");
String UID = user.getUid();
final User u = new User(UID, usernameView.getText().toString(), nameView.getText().toString(), surnameView.getText().toString(), emailView.getText().toString(), passwordView.getText().toString(), "", defaultCurrency);
progressDialog.setMessage("Sending email verification, please wait...");
progressDialog.show();
// inserimento dell'utente a db (tranne la foto)
HashMap<String, String> newUserEntry = new HashMap<>();
newUserEntry.put("email", u.getEmail());
newUserEntry.put("password", u.getPassword());
newUserEntry.put("name", u.getName());
newUserEntry.put("surname", u.getSurname());
newUserEntry.put("username", u.getUsername());
databaseReference.child("users").child(u.getID()).setValue(newUserEntry);
Log.i(TAG, "new user sent into db");
// for saving image
if (imageSetted) {
StorageReference uProfileImageFilenameRef = storageReference.child("users").child(UID).child(UID + "_profileImage.jpg");
// Get the data from an ImageView as bytes
profileImageView.setDrawingCacheEnabled(true);
profileImageView.buildDrawingCache();
Bitmap bitmap = profileImageView.getDrawingCache();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = uProfileImageFilenameRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// todo Handle unsuccessful uploads
Log.e(TAG, "image upload failed");
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
// inserimento della foto a db
u.setProfileImage(taskSnapshot.getMetadata().getDownloadUrl().toString());
databaseReference.child("users").child(u.getID()).child("image").setValue(u.getProfileImage());
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
progressDialog.dismiss();
if (task.isSuccessful()) {
Log.i(TAG, "verification email successfully sent");
Toast.makeText(getContext(), R.string.emailVerification_text, Toast.LENGTH_LONG).show();
} else {
databaseReference.child("users").child(u.getID()).removeValue();
user.delete();
Log.d(TAG, "user deleted from db");
Log.e(TAG, "verification email not sent, exception: " + task.getException());
}
onClickSignUpInterface.itemClicked(SignUpFragment.class.getSimpleName(), "1");
}
});
}
});
} else {
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
progressDialog.dismiss();
if (task.isSuccessful()) {
Log.i(TAG, "verification email successful sent");
Toast.makeText(getContext(), R.string.emailVerification_text, Toast.LENGTH_LONG).show();
} else {
databaseReference.child("users").child(u.getID()).removeValue();
user.delete();
Log.d(TAG, "user deleted from db");
Log.e(TAG, "verification email not sent, exception: " + task.getException());
}
onClickSignUpInterface.itemClicked(SignUpFragment.class.getSimpleName(), "1");
}
});
}
}
Aggregations