Created
October 7, 2019 18:32
-
-
Save bariskarapinar/f9ad762ee96d58b9b09dc952bf0406c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.firebaseauthproject; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.annotation.NonNull; | |
import android.support.v7.app.AppCompatActivity; | |
import android.text.TextUtils; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
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 SignInActivity extends AppCompatActivity { | |
private EditText SignInMail, SignInPass; | |
private FirebaseAuth auth; | |
private Button SignInButton; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//Get Firebase auth instance | |
auth = FirebaseAuth.getInstance(); | |
// set the view now | |
setContentView(R.layout.activity_signin); | |
SignInMail = (EditText) findViewById(R.id.SignInMail); | |
SignInPass = (EditText) findViewById(R.id.SignInPass); | |
SignInButton = (Button) findViewById(R.id.SignInButton); | |
//Get Firebase auth instance | |
auth = FirebaseAuth.getInstance(); | |
SignInButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
String email = SignInMail.getText().toString(); | |
final String password = SignInPass.getText().toString(); | |
if (TextUtils.isEmpty(email)) { | |
Toast.makeText(getApplicationContext(), "Enter your mail address", Toast.LENGTH_SHORT).show(); | |
return; | |
} | |
if (TextUtils.isEmpty(password)) { | |
Toast.makeText(getApplicationContext(), "Enter your password", Toast.LENGTH_SHORT).show(); | |
return; | |
} | |
//authenticate user | |
auth.signInWithEmailAndPassword(email, password) | |
.addOnCompleteListener(SignInActivity.this, new OnCompleteListener<AuthResult>() { | |
@Override | |
public void onComplete(@NonNull Task<AuthResult> task) { | |
if (!task.isSuccessful()) { | |
// there was an error | |
if (password.length() < 8) { | |
Toast.makeText(getApplicationContext(),"Password must be more than 8 digit",Toast.LENGTH_SHORT).show(); | |
} else { | |
Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_SHORT).show(); | |
} | |
} else { | |
Intent intent = new Intent(SignInActivity.this, HomeActivity.class); | |
startActivity(intent); | |
finish(); | |
} | |
} | |
}); | |
} | |
}); | |
} | |
public void NavigateSignUp(View v) { | |
Intent inent = new Intent(this, SignUpActivity.class); | |
startActivity(inent); | |
} | |
public void NavigateForgetMyPassword(View v) { | |
Intent inent = new Intent(this, ResetPasswordActivity.class); | |
startActivity(inent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment