Sunteți pe pagina 1din 2

package com.example.

srdapp;

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.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class MainActivity extends AppCompatActivity {


private EditText username;
private EditText password;
private Button Login;
private TextView Info;
private TextView userRegistration;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

username = findViewById(R.id.username_xml);
password = findViewById(R.id.password_xml);
Login = findViewById(R.id.button);
final String email_string = username.getText().toString();
final String password_string = password.getText().toString();

userRegistration = findViewById(R.id.textView2);

Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mauth.signInWithEmailAndPassword(email_string,password_string).addOnCompleteListene
r(MainActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Logged in
succesfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,
SecondActivity.class);
startActivity(intent);
}
else{
Toast.makeText(MainActivity.this,"Incorrect email or
password",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,
ThirdActivity.class);
startActivity(intent);
}
}
});
}
});
forgotpassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Task<Void> email_sent =
mauth.sendPasswordResetEmail(email_string).addOnCompleteListener(MainActivity.this,
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isComplete()) {
Toast.makeText(MainActivity.this, "Email sent",
Toast.LENGTH_SHORT).show();
}
}
});
}
});
userRegistration.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,
userregistrationactivity.class));
}
});
}