wstępne usunięcie firebase

This commit is contained in:
mikgaw@st.amu.edu.pl 2023-12-02 17:47:36 +01:00
parent 95289ca2f8
commit 1c1a418b88
5 changed files with 51 additions and 44 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -30,6 +30,9 @@ android {
} }
dependencies { dependencies {
def room_version = "2.6.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0' implementation 'com.google.android.material:material:1.10.0'
@ -38,4 +41,5 @@ dependencies {
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
} }

View File

@ -32,12 +32,14 @@ public class Login extends AppCompatActivity {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser(); FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser != null){ if(currentUser != null){
Intent intent = new Intent(getApplicationContext(), MainActivity.class); Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent); startActivity(intent);
finish(); finish();
} }
} }
@Override @Override

View File

@ -16,16 +16,18 @@ public class MainActivity extends AppCompatActivity {
FirebaseAuth auth; FirebaseAuth auth;
Button logout_btn; Button logout_btn;
TextView textView; TextView textView;
FirebaseUser user; //FirebaseUser user;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
auth = FirebaseAuth.getInstance(); //auth = FirebaseAuth.getInstance();
logout_btn = findViewById(R.id.logout_btn); logout_btn = findViewById(R.id.logout_btn);
textView = findViewById(R.id.user_details); textView = findViewById(R.id.user_details);
/*
user = auth.getCurrentUser(); user = auth.getCurrentUser();
if (user == null){ if (user == null){
@ -34,12 +36,12 @@ public class MainActivity extends AppCompatActivity {
finish(); finish();
}else { }else {
textView.setText(user.getEmail()); textView.setText(user.getEmail());
} }*/
logout_btn.setOnClickListener(new View.OnClickListener() { logout_btn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
FirebaseAuth.getInstance().signOut(); //FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(getApplicationContext(), Login.class); Intent intent = new Intent(getApplicationContext(), Login.class);
startActivity(intent); startActivity(intent);
finish(); finish();

View File

@ -1,12 +1,10 @@
package com.example.bsm_notatnik; package com.example.bsm_notatnik;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -14,46 +12,37 @@ import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener; import java.util.regex.Matcher;
import com.google.android.gms.tasks.Task; import java.util.regex.Pattern;
import com.google.android.material.textfield.TextInputEditText;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser; import com.google.firebase.auth.FirebaseUser;
public class Register extends AppCompatActivity { public class Register extends AppCompatActivity {
EditText editTextEmail, editTextPassword; EditText editTextEmail, editTextPassword;
Button buttonReg; Button buttonReg;
FirebaseAuth mAuth;
ProgressBar progressBar; ProgressBar progressBar;
TextView textView; TextView loginNowTextView;
// Checks if a user is already signed in
@Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
if(currentUser != null){
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register); setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
editTextEmail = findViewById(R.id.username); editTextEmail = findViewById(R.id.username);
editTextPassword = findViewById(R.id.password); editTextPassword = findViewById(R.id.password);
buttonReg = findViewById(R.id.btn_register); buttonReg = findViewById(R.id.btn_register);
progressBar = findViewById(R.id.progressBar); progressBar = findViewById(R.id.progressBar);
textView = findViewById(R.id.loginNow); loginNowTextView = findViewById(R.id.loginNow);
textView.setOnClickListener(new View.OnClickListener() {
//goes to login page
loginNowTextView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), Login.class); Intent intent = new Intent(getApplicationContext(), Login.class);
@ -62,6 +51,8 @@ public class Register extends AppCompatActivity {
} }
}); });
//when register button is clicked
buttonReg.setOnClickListener(new View.OnClickListener() { buttonReg.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -79,26 +70,28 @@ public class Register extends AppCompatActivity {
return; return;
} }
mAuth.createUserWithEmailAndPassword(email, password) // TUTAJ ROBIE USERA
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
progressBar.setVisibility(View.GONE);
if (task.isSuccessful()) {
Toast.makeText(Register.this, "Account created.",
Toast.LENGTH_SHORT).show(); Toast.makeText(Register.this, "Konto utworzone z email: " + email + " oraz hasłem: " + password, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), Login.class);
startActivity(intent);
finish(); // finishes current activity
} else {
// If sign in fails, display a message to the user.
Toast.makeText(Register.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
});
} }
}); });
} }
private boolean validateEmail(){
return true;
}
private boolean validatePassword(){
return true;
}
} }