use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class OrganizationRegistrationActivity method registerNewOrg.
private void registerNewOrg() {
AutoCompleteTextView mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
EditText mPasswordView = (EditText) findViewById(R.id.password);
CheckBox mTermsAgree = (CheckBox) findViewById(R.id.agreeTerms);
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
String email = mEmailView.getText().toString();
String password = mPasswordView.getText().toString();
if (!email.contains("@")) {
Toast.makeText(this, "Not a valid email address", Toast.LENGTH_SHORT).show();
} else {
if (password.length() < 4) {
Toast.makeText(this, "Password is too short, minimum length is 4.", Toast.LENGTH_SHORT).show();
} else {
if (email.contains(":") || password.contains(":")) {
Toast.makeText(this, "Email address and Password cannot contain ':'", Toast.LENGTH_SHORT).show();
} else {
if (!mTermsAgree.isChecked()) {
Toast.makeText(this, "You need to agree to share your details.", Toast.LENGTH_SHORT).show();
} else {
progressBar.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Context context = getApplicationContext();
progressBar.setVisibility(View.GONE);
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
sendVerificationEmail();
// take user to main screen
progressBar.setVisibility(View.GONE);
Intent intent = new Intent(context, LoginActivity.class);
startActivity(intent);
} else {
if (task.getException() instanceof FirebaseAuthUserCollisionException) {
Toast.makeText(context, "User with this email already exists.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Error creating user", Toast.LENGTH_SHORT).show();
}
}
}
});
}
}
}
}
}
use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class OrganizationRegistrationActivity method sendVerificationEmail.
private void sendVerificationEmail() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
writeNewUser(user.getUid(), user.getEmail());
startActivity(new Intent(OrganizationRegistrationActivity.this, LoginActivity.class));
finish();
} else {
overridePendingTransition(0, 0);
finish();
overridePendingTransition(0, 0);
startActivity(getIntent());
}
}
});
}
use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class DonationsFragment method fetchData.
// Getting data from database
public ArrayList<BloodRequest> fetchData() {
donations = new ArrayList<BloodRequest>();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
Donation donation = child.getValue(Donation.class);
if (donation != null) {
FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(donation.requestid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
BloodRequest request = dataSnapshot.getValue(BloodRequest.class);
if (request != null) {
donations.add(request);
numDonations.setText("LIVES SAVED: " + donations.size());
mAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(donation.requestid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
BloodRequest request = dataSnapshot.getValue(BloodRequest.class);
donations.add(request);
numDonations.setText("LIVES SAVED: " + donations.size());
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return donations;
}
use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class IndividualRegistrationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_individual_registration);
setTitle("Individual Registration");
// make the actionbar show arrow to go back to login
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Toast toast = Toast.makeText(getApplicationContext(), "Sending email", Toast.LENGTH_SHORT);
toast.show();
sendVerificationEmail();
} else {
Toast toast = Toast.makeText(getApplicationContext(), "Not sending email", Toast.LENGTH_SHORT);
toast.show();
}
}
};
username = (AutoCompleteTextView) findViewById(R.id.name);
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
mPasswordView = (EditText) findViewById(R.id.password);
// progressBar = (ProgressBar) findViewById(R.id.progressBar);
bloodGroup = (Spinner) findViewById(R.id.spin);
try {
Field popup = Spinner.class.getDeclaredField("mPopup");
popup.setAccessible(true);
android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(bloodGroup);
popupWindow.setHeight(500);
} catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
}
List<String> bgroups = Arrays.asList(getResources().getStringArray(R.array.blood_groups));
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_text_view, bgroups) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
v.setPadding(8, 8, 8, 15);
if (position == getCount()) {
((TextView) v.findViewById(R.id.text1)).setText("");
((TextView) v.findViewById(R.id.text1)).setHint(getItem(getCount()));
}
return v;
}
@Override
public int getCount() {
return super.getCount() - 1;
}
};
adapter.setDropDownViewResource(R.layout.spinner_text_view);
bloodGroup.setAdapter(adapter);
bloodGroup.setSelection(adapter.getCount());
// Set OnClick Listeners for buttons
photo_btn = (ImageButton) findViewById(R.id.profile_photo);
photo_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_INTENT);
}
});
Button mRegisterButton = (Button) findViewById(R.id.register_individual_button);
mRegisterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
registerNewUser();
}
});
}
use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class IndividualRegistrationActivity method sendVerificationEmail.
private void sendVerificationEmail() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(getApplicationContext(), "sent email", Toast.LENGTH_SHORT);
if (task.isSuccessful()) {
FirebaseAuth.getInstance().signOut();
// startActivity(new Intent(IndividualRegistrationActivity.this, LoginActivity.class));
finish();
Toast.makeText(getApplicationContext(), "sent email success", Toast.LENGTH_SHORT);
} else {
overridePendingTransition(0, 0);
finish();
// overridePendingTransition(0, 0 );
// startActivity(getIntent());
Toast.makeText(getApplicationContext(), "sent email failed", Toast.LENGTH_SHORT);
}
}
});
}
Aggregations