use of com.google.firebase.auth.FirebaseUser in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.
the class SignInActivity method onStart.
@Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
updateUI(currentUser);
}
use of com.google.firebase.auth.FirebaseUser in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.
the class SignUpActivity method signUp.
private void signUp() {
final boolean[] isFirst = { true };
final List<String> listDomain = new ArrayList<>();
final String username = edtUsername.getText().toString();
final String password = edtPassword.getText().toString();
final String domain = edtDomain.getText().toString();
final String fullName = edtFullName.getText().toString();
final String phone = edtPhone.getText().toString();
final String address = edtAddress.getText().toString();
final DatabaseReference referenceDomain, referenceEmployee;
referenceDomain = database.getReference(Constant.NODE_DOMAIN);
referenceEmployee = database.getReference(Constant.NODE_NHAN_VIEN);
// Check domain exist
referenceDomain.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
String domain = snapshot.getValue(String.class);
listDomain.add(domain);
}
if (listDomain.contains(domain) && isFirst[0]) {
Toast.makeText(SignUpActivity.this, "Domain cua ban da ton tai!!!", Toast.LENGTH_SHORT).show();
isFirst[0] = false;
} else if (isFirst[0]) {
if (!username.equals("") && !password.equals("") && !domain.equals("") && !fullName.equals("")) {
mAuth.createUserWithEmailAndPassword(username + domain, password).addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
EmployeeObject employeeObject = new EmployeeObject();
employeeObject.setAccountType("0");
employeeObject.setIdEmployee(user.getUid());
employeeObject.setIdManage("");
employeeObject.setUsernameEmployee(username + domain);
if (!phone.equals("")) {
employeeObject.setPhoneEmployee(phone);
} else {
employeeObject.setPhoneEmployee("");
}
if (!address.equals("")) {
employeeObject.setAddressEmployee(address);
} else {
employeeObject.setAddressEmployee("");
}
employeeObject.setNameEmployee(fullName);
if (rdbMale.isChecked()) {
employeeObject.setGenderEmployee("Nam");
employeeObject.setUrlAvatar(Constant.URL_MALE);
} else {
employeeObject.setGenderEmployee("Nu");
employeeObject.setUrlAvatar(Constant.URL_FEMALE);
}
employeeObject.setBirthdayEmployee("01/01/1990");
referenceEmployee.child(user.getUid()).setValue(employeeObject);
referenceDomain.push().setValue(domain);
Toast.makeText(SignUpActivity.this, "Dang ky thanh cong!!!", Toast.LENGTH_SHORT).show();
isFirst[0] = false;
SharedPreferences preferences = SignUpActivity.this.getSharedPreferences(Constant.PREFERENCE_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString(Constant.PREFERENCE_DOMAIN, domain);
editor.apply();
startActivity(new Intent(SignUpActivity.this, SignInActivity.class));
}
}
});
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.google.firebase.auth.FirebaseUser in project NienLuanChuyenNganh-Android by AuNguyenTrungNguyen.
the class AddEmployeeActivity method signUp.
private void signUp() {
SharedPreferences preferences = AddEmployeeActivity.this.getSharedPreferences(Constant.PREFERENCE_NAME, MODE_PRIVATE);
final String id = preferences.getString(Constant.PREFERENCE_KEY_ID, null);
final String domain = preferences.getString(Constant.PREFERENCE_DOMAIN, null);
final String username = edtUsername.getText().toString();
final String password = edtPassword.getText().toString();
final String fullName = edtFullName.getText().toString();
final String phone = edtPhone.getText().toString();
final String address = edtAddress.getText().toString();
final DatabaseReference referenceEmployee;
referenceEmployee = databaseEmployee.getReference(Constant.NODE_NHAN_VIEN);
if (!username.equals("") && !password.equals("") && !fullName.equals("")) {
mAuth.createUserWithEmailAndPassword(username + domain, password).addOnCompleteListener(AddEmployeeActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
EmployeeObject employeeObject = new EmployeeObject();
if (rdbAdmin.isChecked()) {
employeeObject.setAccountType("0");
} else {
employeeObject.setAccountType("1");
}
employeeObject.setIdEmployee(user.getUid());
employeeObject.setIdManage(id);
employeeObject.setUsernameEmployee(username + domain);
if (!phone.equals("")) {
employeeObject.setPhoneEmployee(phone);
} else {
employeeObject.setPhoneEmployee("");
}
if (!address.equals("")) {
employeeObject.setAddressEmployee(address);
} else {
employeeObject.setAddressEmployee("");
}
employeeObject.setNameEmployee(fullName);
if (rdbMale.isChecked()) {
employeeObject.setGenderEmployee("Nam");
employeeObject.setUrlAvatar(Constant.URL_MALE);
} else {
employeeObject.setGenderEmployee("Nu");
employeeObject.setUrlAvatar(Constant.URL_FEMALE);
}
employeeObject.setBirthdayEmployee("01/01/1990");
referenceEmployee.child(user.getUid()).setValue(employeeObject);
Toast.makeText(AddEmployeeActivity.this, "Dang ky thanh cong!!!", Toast.LENGTH_SHORT).show();
}
}
});
}
}
use of com.google.firebase.auth.FirebaseUser in project iosched by google.
the class SessionDetailModel method attemptReturnReservation.
public void attemptReturnReservation() {
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
if (mQueueReference != null && currentUser != null) {
final String requestId = generateReserveRequestId();
QueueAction queueAction = new QueueAction(mSessionId, "return", requestId);
mQueueReference.addValueEventListener(mQueueEventListener);
mQueueReference.setValue(queueAction).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
LOGD(TAG, "Enter queue.");
mReservationPending = false;
mReturnPending = true;
DataQueryCallback<SessionDetailQueryEnum> reservationPendingCallback = mDataQueryCallbacks.get(RESERVATION_PENDING);
reservationPendingCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_PENDING);
mSessionReservationResultReference.child(requestId).addValueEventListener(mSessionReservationResultEventListener);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
LOGE(TAG, e.getMessage());
mReservationPending = false;
mReturnPending = false;
DataQueryCallback<SessionDetailQueryEnum> reservationFailedCallback = mDataQueryCallbacks.get(RESERVATION_FAILED);
reservationFailedCallback.onModelUpdated(SessionDetailModel.this, RESERVATION_FAILED);
}
});
}
}
use of com.google.firebase.auth.FirebaseUser in project iosched by google.
the class RegistrationStatusService method getFirebaseToken.
/**
* Get Firebase token for current user
*/
private String getFirebaseToken() throws Exception {
FirebaseUser fbUser = mFirebaseAuth.getCurrentUser();
if (fbUser == null) {
throw new IOException("Firebase user not authenticated");
}
// Get Firebase token and wait for operation to complete
final CountDownLatch latch = new CountDownLatch(1);
Task<GetTokenResult> task = fbUser.getToken(false);
task.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
latch.countDown();
}
});
latch.await();
if (task.isSuccessful()) {
String fbToken = task.getResult().getToken();
if (fbToken == null) {
throw new IOException("Received null Firebase token");
}
return fbToken;
} else {
throw task.getException();
}
}
Aggregations