forked from sarthakd999/Hacktoberfest2021-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignupActivity.java
75 lines (64 loc) · 2.89 KB
/
SignupActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.example.connect;
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.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.FirebaseFirestore;
public class SignupActivity extends AppCompatActivity {
FirebaseAuth auth;
TextView email , password , name;
Button login, signup;
FirebaseFirestore database;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
database = FirebaseFirestore.getInstance();
auth = FirebaseAuth.getInstance();
email = findViewById(R.id.email);
password = findViewById(R.id.password);
login = findViewById(R.id.button);
signup = findViewById(R.id.button2);
name = findViewById(R.id.Name);
signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Email,Password,Name;
Email = email.getText().toString();
Password = password.getText().toString();
Name = name.getText().toString();
User user = new User();
user.setEmail(Email);
user.setName(Name);
user.setPassword(Password);
auth.createUserWithEmailAndPassword(Email,Password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
database.collection("Users").document().set(user).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
startActivity(new Intent(SignupActivity.this,LoginActivity.class));
}
});
Toast.makeText(SignupActivity.this, "Account is Created", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(SignupActivity.this,task.getException().getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}