forked from Ongbook/mvp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Ongbook#21 - Criação de usuário no firebase authentication
- Loading branch information
1 parent
02e8253
commit aa3196b
Showing
7 changed files
with
146 additions
and
39 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { AuthService } from './auth.service'; | ||
|
||
describe('AuthService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [AuthService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([AuthService], (service: AuthService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { AngularFireAuth } from '@angular/fire/auth'; | ||
import { FormGroup } from '@angular/forms'; | ||
|
||
import { EntidadeService } from './entidade.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AuthService { | ||
|
||
constructor(public afAuth: AngularFireAuth, private entidadeService: EntidadeService) { } | ||
|
||
public criaUsuarioEntidade(formCadastro: FormGroup) { | ||
|
||
let email = formCadastro.controls['responsavel'].value['emailResponsavel']; | ||
let senha = formCadastro.controls['responsavel'].value['senhaOk']; | ||
|
||
return this.afAuth.auth.createUserWithEmailAndPassword(email, senha) | ||
.then((res) => { | ||
|
||
formCadastro.controls['responsavel'].get('uid').setValue(res.user.uid); | ||
|
||
return this.entidadeService.criaEntidade(formCadastro); | ||
|
||
}).catch((error) => { | ||
|
||
console.log(error); | ||
return new Promise((resolve) => resolve("erro")) | ||
}) | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TestBed, inject } from '@angular/core/testing'; | ||
|
||
import { EntidadeService } from './entidade.service'; | ||
|
||
describe('EntidadeService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [EntidadeService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([EntidadeService], (service: EntidadeService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { FormGroup } from '@angular/forms'; | ||
|
||
import { AngularFireDatabase } from '@angular/fire/database'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class EntidadeService { | ||
|
||
constructor(private db: AngularFireDatabase) { } | ||
|
||
public criaEntidade(formulario: FormGroup) { | ||
|
||
return this.db.list('/entidades').push(formulario.value) | ||
.then((res) => { | ||
return new Promise((resolve) => resolve("sucesso")) | ||
}, error => { | ||
console.log(error) | ||
return new Promise((resolve) => resolve("erro")) | ||
}); | ||
}; | ||
|
||
|
||
|
||
} |
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
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