Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "Customer" : {
- "1537672911526" : {
- "email" : "user1@gmail.com",
- "firstName" : "user1",
- "lastName" : "user1",
- "password" : "user1",
- "username" : "user1"
- },
- "1537672951066" : {
- "email" : "user2@gmail.com",
- "firstName" : "user2",
- "lastName" : "user2",
- "password" : "user2",
- "username" : "user2"
- }
- //Init Firebase
- final FirebaseDatabase database = FirebaseDatabase.getInstance();
- final DatabaseReference table_user = database.getReference("Customer");
- btnLogIn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final ProgressDialog mDialog = new ProgressDialog(Login.this);
- mDialog.setMessage("Please wait...");
- mDialog.show();
- table_user.addValueEventListener(new ValueEventListener() {
- @Override
- public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
- //If user exists
- if(dataSnapshot.child(username.getText().toString()).exists()){
- //Get user information
- mDialog.dismiss();
- User user = dataSnapshot.child(username.getText().toString()).getValue(User.class);
- if(user.getPassword().equals(user_pass.getText().toString())){
- Intent showMenu = new Intent(Login.this, Home.class);
- Common.currentUser = user;
- startActivity(showMenu);
- finish();
- }
- else{
- Toast.makeText(Login.this, "Incorrect Email or Password", Toast.LENGTH_SHORT).show();
- }
- }
- else{
- mDialog.dismiss();
- Toast.makeText(Login.this, "User does not exist", Toast.LENGTH_SHORT).show();
- }
- }
- @Override
- public void onCancelled(@NonNull DatabaseError databaseError) {
- }
- });
- }
- });
Add Comment
Please, Sign In to add comment