Skip to content

Instantly share code, notes, and snippets.

@bariskarapinar
Created October 7, 2019 18:25
Show Gist options
  • Save bariskarapinar/acc4bf296928edea0a392762da244c0b to your computer and use it in GitHub Desktop.
Save bariskarapinar/acc4bf296928edea0a392762da244c0b to your computer and use it in GitHub Desktop.
package com.example.firebaseauthproject;
import android.annotation.SuppressLint;
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 SignUpActivity extends AppCompatActivity {
EditText SignUpMail,SignUpPass;
Button SignUpButton;
private FirebaseAuth auth;
@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
SignUpMail = findViewById(R.id.SignUpMail);
SignUpPass = findViewById(R.id.SignUpPass);
auth=FirebaseAuth.getInstance();
SignUpButton = (Button) findViewById(R.id.SignUpButton);
SignUpButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String email = SignUpMail.getText().toString();
String pass = SignUpPass.getText().toString();
if(TextUtils.isEmpty(email)){
Toast.makeText(getApplicationContext(),"Please enter your E-mail address",Toast.LENGTH_LONG).show();
return;
}
if(TextUtils.isEmpty(pass)){
Toast.makeText(getApplicationContext(),"Please enter your Password",Toast.LENGTH_LONG).show();
}
if (pass.length() == 0){
Toast.makeText(getApplicationContext(),"Please enter your Password",Toast.LENGTH_LONG).show();
}
if (pass.length()<8){
Toast.makeText(getApplicationContext(),"Password must be more than 8 digit",Toast.LENGTH_LONG).show();
}
else{
auth.createUserWithEmailAndPassword(email,pass)
.addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
Toast.makeText(SignUpActivity.this, "ERROR",Toast.LENGTH_LONG).show();
}
else {
startActivity(new Intent(SignUpActivity.this, EditProfileActivity.class));
finish();
}
}
});}
}
});
}
public void navigate_sign_in(View v){
Intent inent = new Intent(this, SignInActivity.class);
startActivity(inent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment