Search in sources :

Example 91 with FirebaseUser

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);
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 92 with FirebaseUser

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) {
        }
    });
}
Also used : DatabaseReference(com.google.firebase.database.DatabaseReference) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) AuthResult(com.google.firebase.auth.AuthResult) EmployeeObject(aunguyen.quanlycongviec.Object.EmployeeObject) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) DataSnapshot(com.google.firebase.database.DataSnapshot) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 93 with FirebaseUser

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();
                }
            }
        });
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) DatabaseReference(com.google.firebase.database.DatabaseReference) AuthResult(com.google.firebase.auth.AuthResult) EmployeeObject(aunguyen.quanlycongviec.Object.EmployeeObject) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 94 with FirebaseUser

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);
            }
        });
    }
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) Task(com.google.android.gms.tasks.Task) SessionDetailQueryEnum(com.google.samples.apps.iosched.session.SessionDetailModel.SessionDetailQueryEnum) QueueAction(com.google.samples.apps.iosched.session.data.QueueAction) NonNull(android.support.annotation.NonNull) FirebaseUser(com.google.firebase.auth.FirebaseUser) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) DatabaseException(com.google.firebase.database.DatabaseException)

Example 95 with FirebaseUser

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();
    }
}
Also used : GetTokenResult(com.google.firebase.auth.GetTokenResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

FirebaseUser (com.google.firebase.auth.FirebaseUser)100 AuthResult (com.google.firebase.auth.AuthResult)26 Intent (android.content.Intent)22 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)16 DataSnapshot (com.google.firebase.database.DataSnapshot)12 DatabaseError (com.google.firebase.database.DatabaseError)12 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)11 AuthCredential (com.google.firebase.auth.AuthCredential)11 DatabaseReference (com.google.firebase.database.DatabaseReference)11 ValueEventListener (com.google.firebase.database.ValueEventListener)11 View (android.view.View)10 Task (com.google.android.gms.tasks.Task)10 Button (android.widget.Button)9 NonNull (android.support.annotation.NonNull)8 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)7 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)7 TextView (android.widget.TextView)6 Test (org.junit.Test)6 Context (android.content.Context)5 SharedPreferences (android.content.SharedPreferences)5