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 SocialRec by Jkuras.
the class SignIn_SignUp 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(SignIn_SignUp.this, "Verification email sent to " + user.getEmail(), Toast.LENGTH_SHORT).show();
} else {
Log.e(TAG, "sendEmailVerification", task.getException());
Toast.makeText(SignIn_SignUp.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 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 ProfileEdit method updateAccount.
private boolean updateAccount() {
Log.i(TAG, "createAccount");
if (!validateForm()) {
Log.i(TAG, "submitted form is not valid");
Toast.makeText(this, "Invalid form!", Toast.LENGTH_SHORT).show();
return false;
}
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user == null) {
Log.e(TAG, "Error while retriving current user from db");
Toast.makeText(this, "Error while retriving current user from db", Toast.LENGTH_LONG).show();
return false;
}
final String currentUserID = currentUser.getID();
String newName = nameView.getText().toString();
String newSurname = surnameView.getText().toString();
String newUsername = usernameView.getText().toString();
//String newEmail = emailView.getText().toString();
String newPassword = passwordView.getText().toString();
if (!newName.isEmpty() && (currentUser.getName() == null || !currentUser.getName().equals(newName))) {
currentUser.setName(newName);
databaseReference.child("users").child(currentUserID).child("name").setValue(currentUser.getName());
}
if (!newSurname.isEmpty() && (currentUser.getSurname() == null || !currentUser.getSurname().equals(newSurname))) {
currentUser.setSurname(newSurname);
databaseReference.child("users").child(currentUserID).child("surname").setValue(currentUser.getSurname());
}
if (!newUsername.isEmpty() && (currentUser.getUsername() == null || !currentUser.getUsername().equals(newUsername))) {
currentUser.setUsername(newUsername);
databaseReference.child("users").child(currentUserID).child("username").setValue(currentUser.getUsername());
}
if (IMAGE_CHANGED) {
// for saving image
StorageReference uProfileImageFilenameRef = storageReference.child("users").child(currentUserID).child(currentUserID + "_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.
currentUser.setProfileImage(taskSnapshot.getMetadata().getDownloadUrl().toString());
databaseReference.child("users").child(currentUserID).child("image").setValue(currentUser.getProfileImage());
}
});
}
if (!newPassword.isEmpty() && !currentUser.getPassword().equals(User.encryptPassword(newPassword))) {
try {
user.updatePassword(newPassword);
} catch (Exception e) {
Log.e(TAG, e.getClass().toString() + ", message: " + e.getMessage());
Toast.makeText(this, "Can't update password", Toast.LENGTH_LONG).show();
return false;
}
currentUser.setPassword(newPassword);
databaseReference.child("users").child(currentUserID).child("password").setValue(currentUser.getPassword());
}
return true;
}
Aggregations