Skip to content

Commit

Permalink
Aula 184 - Cadastro de Usuário Parte 2
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloamsilva committed Aug 6, 2018
1 parent af9748c commit 39b3fbc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
// Design
implementation 'com.android.support:design:28.0.0-beta01'
// Mascara de formatação
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package br.com.whatsappandroid.cursoandroid.whatsapp2.activity;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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;

import br.com.whatsappandroid.cursoandroid.whatsapp2.R;
import br.com.whatsappandroid.cursoandroid.whatsapp2.config.ConfiguracaoFirebase;
import br.com.whatsappandroid.cursoandroid.whatsapp2.model.Usuario;

public class CadastroUsuarioActivity extends AppCompatActivity {
Expand All @@ -17,6 +25,8 @@ public class CadastroUsuarioActivity extends AppCompatActivity {
private Button botaoCadastrar;
private Usuario usuario;

private FirebaseAuth autenticacao;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -41,7 +51,20 @@ public void onClick(View view) {
}

private void cadastrarUsuario(){

autenticacao = ConfiguracaoFirebase.getFirebaseAutenticacao();
autenticacao.createUserWithEmailAndPassword(
usuario.getEmail(),
usuario.getSenha()
).addOnCompleteListener(CadastroUsuarioActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if( task.isSuccessful() ){
Toast.makeText(CadastroUsuarioActivity.this, "Sucesso ao cadastrar usuário", Toast.LENGTH_LONG ).show();
}else{
Toast.makeText(CadastroUsuarioActivity.this, "Erro ao cadastrar usuário", Toast.LENGTH_LONG ).show();
}
}
});
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package br.com.whatsappandroid.cursoandroid.whatsapp2.config;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public final class ConfiguracaoFirebase {

private static DatabaseReference referenciaFirebase;
private static FirebaseAuth autenticacao;

public static DatabaseReference getFirebase(){
if( referenciaFirebase == null ){
Expand All @@ -14,4 +16,11 @@ public static DatabaseReference getFirebase(){
return referenciaFirebase;
}

public static FirebaseAuth getFirebaseAutenticacao(){
if( autenticacao == null ){
autenticacao = FirebaseAuth.getInstance();
}
return autenticacao;
}

}

0 comments on commit 39b3fbc

Please sign in to comment.