-
Notifications
You must be signed in to change notification settings - Fork 0
/
SigInScreen.java
84 lines (78 loc) · 3.87 KB
/
SigInScreen.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
76
77
78
79
80
81
82
83
84
package com.example.hackmol;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.textfield.TextInputEditText;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class SigInScreen extends AppCompatActivity {
private TextInputEditText email;
String point="0";
private TextInputEditText password,name;
private Button CreateAccount;
private FirebaseAuth auth;
DatabaseReference databaseReference;
FirebaseDatabase firebaseDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sig_in_screen);
TextView textView=(TextView)findViewById(R.id.website);
textView.setMovementMethod(LinkMovementMethod.getInstance());
email=findViewById(R.id.email);
name=findViewById(R.id.name);
password=findViewById(R.id.password);
CreateAccount=findViewById(R.id.newaccbtn);
auth=FirebaseAuth.getInstance();
databaseReference=FirebaseDatabase.getInstance().getReference("UserInfo");
CreateAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String txt_email=email.getText().toString();
String txt_name=name.getText().toString();
String txt_password=password.getText().toString();
if(TextUtils.isEmpty(txt_email)||TextUtils.isEmpty(txt_password)){
Toast.makeText(SigInScreen.this,"Empty Credentials",Toast.LENGTH_SHORT).show();
}
else {
registerUser(txt_email,txt_password,txt_name);
}
}
private void registerUser(String email, String password,String name) {
auth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(SigInScreen.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
User information=new User(name,email,point);
FirebaseDatabase.getInstance().getReference("UserInfo")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(information)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(SigInScreen.this,"Sign In Successfull",Toast.LENGTH_SHORT).show();
Intent intent=new Intent(SigInScreen.this,Activity2.class);
startActivity(intent);
finish();
}
});
}
else {
Toast.makeText(SigInScreen.this,"Sign In F0000ailed",Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}