Search

Register Page

package com.example.bike_service;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.bike_service.Model.Users;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;

import java.util.HashMap;
import java.util.Map;

public class Register_Page extends AppCompatActivity {
EditText name ,email,password;
Button registerbtn;
TextView gotologin;
    FirebaseAuth fAuth;
    FirebaseDatabase database;
    FirebaseFirestore fstore;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_page);
        name=findViewById(R.id.name);
        email=findViewById(R.id.email);
        password=findViewById(R.id.password);
        registerbtn=findViewById(R.id.registerbtn);
        gotologin=findViewById(R.id.gotologin);
        fAuth=FirebaseAuth.getInstance();
        fstore=FirebaseFirestore.getInstance();
        database=FirebaseDatabase.getInstance();
        gotologin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Register_Page.this,Login_Page.class);
                startActivity(intent);
            }
        });
        registerbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String username = name.getText().toString();
                String useremail = email.getText().toString();
                String userpassword = password.getText().toString();
                fAuth.createUserWithEmailAndPassword(useremail,userpassword).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()){
                            String uid = task.getResult().getUser().getUid();
                            Users users = new Users(username,useremail,userpassword,uid,0);

                            database.getReference().child("Usersregister").child(uid).setValue(users);
                            Toast.makeText(Register_Page.this, "User Create", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(Register_Page.this, Login_Page.class);
                            startActivity(intent);
                            finish();
                        }
                    }
                });



            }
        });
    }
}









Model Class :---






package com.example.bike_service.Model;

public class Users {
    String username,useremail,userpassword,uid;
    int usertype;

    public Users() {
    }

    public Users(String username, String useremail, String userpassword, String uid, int usertype) {
        this.username = username;
        this.useremail = useremail;
        this.userpassword = userpassword;
        this.uid = uid;
        this.usertype = usertype;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUseremail() {
        return useremail;
    }

    public void setUseremail(String useremail) {
        this.useremail = useremail;
    }

    public String getUserpassword() {
        return userpassword;
    }

    public void setUserpassword(String userpassword) {
        this.userpassword = userpassword;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public int getUsertype() {
        return usertype;
    }

    public void setUsertype(int usertype) {
        this.usertype = usertype;
    }
}






Login Page :--



package com.example.bike_service;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;

public class Login_Page extends AppCompatActivity {
EditText lemail,lpass;
Button lbtn;
TextView gotoregister;
FirebaseAuth auth;
    FirebaseDatabase firebaseDatabase;
    FirebaseFirestore firebaseFirestore;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_page);
        lemail=findViewById(R.id.loginemail);
        lpass=findViewById(R.id.loaginpass);
        lbtn=findViewById(R.id.loginbtn);
        gotoregister=findViewById(R.id.gotoregis);
        auth=FirebaseAuth.getInstance();
        firebaseDatabase=FirebaseDatabase.getInstance();
        firebaseFirestore=FirebaseFirestore.getInstance();
        gotoregister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Login_Page.this,Register_Page.class);
                startActivity(intent);

            }
        });
     lbtn.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {

             String useremail = lemail.getText().toString();
             String userpassword = lpass.getText().toString();

             auth.signInWithEmailAndPassword(useremail,userpassword).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                 @Override
                 public void onComplete(@NonNull Task<AuthResult> task) {
                     if (task.isSuccessful()){
                         String uid = task.getResult().getUser().getUid();
                         firebaseDatabase.getReference().child("Usersregister").child(uid).child("usertype").addListenerForSingleValueEvent(new ValueEventListener() {
                             @Override
                             public void onDataChange(@NonNull DataSnapshot snapshot) {
                                 int usertype = snapshot.getValue(Integer.class);
                                 if (usertype == 0){
                                     Intent intent = new Intent(Login_Page.this, AdminPage.class);
                                     startActivity(intent);
                                     finish();

                                 }
                                 if (usertype == 1){
                                     Intent intent = new Intent(Login_Page.this, MainActivity.class);
                                     startActivity(intent);
                                     finish();

                                 }


                             }

                             @Override
                             public void onCancelled(@NonNull DatabaseError error) {

                             }
                         });



                     }

                 }
             });

         }
     });
    }
}
0 comments

Recent Posts

See All

namefood ingredients app flutter projectFood Donation App College ProjectCollege Android and Website ProjectCollege Leave Management SystemServey for Indian fingerprint unlocking system for

Order any project or you have any idea. Contact - 9306637630. Online Course and Examination Management System Advanced Car & Scooty Training Driving School Management System Advanced Employee Manageme