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 {
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 'com.google.android.material:material:1.10.0'
@ -38,4 +41,5 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

View File

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

View File

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

View File

@ -1,12 +1,10 @@
package com.example.bsm_notatnik;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -14,46 +12,37 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
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 java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class Register extends AppCompatActivity {
EditText editTextEmail, editTextPassword;
Button buttonReg;
FirebaseAuth mAuth;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
editTextEmail = findViewById(R.id.username);
editTextPassword = findViewById(R.id.password);
buttonReg = findViewById(R.id.btn_register);
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
public void onClick(View view) {
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() {
@Override
public void onClick(View view) {
@ -79,26 +70,28 @@ public class Register extends AppCompatActivity {
return;
}
mAuth.createUserWithEmailAndPassword(email, password)
.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();
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();
}
}
});
// TUTAJ ROBIE USERA
Toast.makeText(Register.this, "Konto utworzone z email: " + email + " oraz hasłem: " + password, Toast.LENGTH_SHORT).show();
}
});
}
private boolean validateEmail(){
return true;
}
private boolean validatePassword(){
return true;
}
}