-
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.
- Loading branch information
1 parent
0a84c1c
commit d5ab14c
Showing
18 changed files
with
391 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,10 +1,23 @@ | ||
import { Component } from '@angular/core'; | ||
import { AuthService } from './services/auth.service'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: 'app.component.html', | ||
styleUrls: ['app.component.scss'], | ||
}) | ||
export class AppComponent { | ||
constructor() {} | ||
constructor(private auth: AuthService) {} | ||
|
||
async signOut() { | ||
await this.auth.signOut(); | ||
} | ||
|
||
async getUser() { | ||
console.log(await this.auth.getUser()) | ||
} | ||
|
||
async verifyToken(){ | ||
await this.auth.verifyToken() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,31 @@ | ||
<ion-content [fullscreen]="true"> | ||
<div id="container"> | ||
<div id="login-container"> | ||
<form #loginForm="ngForm" id="login-container" (keyup.enter)="emailAuth(this.email, this.password)"> | ||
|
||
<img src="../../assets/img/ibge-logo-6.png" id="logo"> | ||
<h1>Login</h1> | ||
<ion-input fill="outline" shape="round" label="Email:" labelPlacement="floating"></ion-input> | ||
|
||
<ion-input fill="outline" shape="round" label="E-mail:" labelPlacement="floating" name="email" ngModel type="email" required [(ngModel)]="email"></ion-input> | ||
|
||
<ion-input fill="outline" shape="round" label="Senha:" labelPlacement="floating" name="password" ngModel type="password" required [(ngModel)]="password"></ion-input> | ||
|
||
<div> | ||
<ion-input type="email" fill="outline" shape="round" label="Email" labelPlacement="floating" helperText="Enter a valid email" errorText="Invalid email" ngModel email></ion-input> | ||
<ion-button fill="clear" shape="round">Esqueceu a senha?</ion-button> | ||
<ion-button fill="clear" shape="round" (click)="googleAuth()"> | ||
<ion-icon name="logo-google"></ion-icon> | ||
</ion-button> | ||
</div> | ||
</div> | ||
|
||
<div class="flex"> | ||
<ion-button shape="round" (click)="emailAuth(this.email, this.password)">Enviar</ion-button> | ||
<ion-button (click)="loginForm.reset()" color="medium" shape="round">Limpar</ion-button> | ||
</div> | ||
|
||
<div *ngIf="error"> | ||
<p style="color: red;"> | ||
{{error}} | ||
</p> | ||
</div> | ||
</form> | ||
</div> | ||
</ion-content> |
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 |
---|---|---|
@@ -1,18 +1,61 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { AuthService } from '../services/auth.service'; | ||
import { LoadingController } from '@ionic/angular'; | ||
import { Router } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'app-login', | ||
templateUrl: './login.page.html', | ||
styleUrls: ['./login.page.scss'], | ||
}) | ||
export class LoginPage { | ||
email = ''; | ||
password = ''; | ||
email: string = ''; | ||
password: string = ''; | ||
error: any; | ||
private loading: any; | ||
private messageTimeout: any; | ||
|
||
constructor(public auth: AuthService) {} | ||
constructor( | ||
private auth: AuthService, | ||
private loadingControler: LoadingController, | ||
private router: Router | ||
) {} | ||
|
||
async login() { | ||
await this.auth.emailSignIn(this.email, this.password); | ||
private errorMessage(message: string) { | ||
this.error = message; | ||
if (this.messageTimeout) clearTimeout(this.messageTimeout); | ||
this.messageTimeout = setTimeout(() => { | ||
this.error = null; | ||
}, 5000); | ||
} | ||
|
||
async emailAuth(email: string, password: string) { | ||
this.showLoading(); | ||
const error = await this.auth.emailSignIn(email, password); | ||
this.dimisLoading(); | ||
|
||
error ? this.errorMessage(error) : this.router.navigate(['/']); | ||
} | ||
|
||
async googleAuth() { | ||
this.showLoading(); | ||
const error = await this.auth.googleSignIn(); | ||
this.dimisLoading(); | ||
|
||
error ? this.errorMessage(error) : this.router.navigate(['/']); | ||
} | ||
|
||
async showLoading() { | ||
this.loading = await this.loadingControler.create({ | ||
message: 'Enviando...', | ||
}); | ||
|
||
this.loading.present(); | ||
} | ||
|
||
async dimisLoading() { | ||
if (this.loading) { | ||
await this.loading.dismiss(); | ||
} | ||
} | ||
} |
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,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AuthGuardService } from './auth-guard.service'; | ||
|
||
describe('AuthGuardService', () => { | ||
let service: AuthGuardService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(AuthGuardService); | ||
}); | ||
|
||
it('should be created', () => { | ||
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,21 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { CanActivate, Router } from '@angular/router'; | ||
import { AuthService } from './auth.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class AuthGuard implements CanActivate { | ||
constructor(private auth: AuthService, private router: Router) {} | ||
|
||
async canActivate() { | ||
const user = await this.auth.getUser(); | ||
|
||
if (!user) { | ||
this.router.navigate(['/login']); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.