This commit is contained in:
Tiago Kayaya
2020-08-13 17:46:07 +01:00
5 changed files with 83 additions and 16 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
<ion-input type="text" name="domainName" [(ngModel)]="postData.domainName"></ion-input>
</ion-item>
<ion-button expand="block" shape="round" color="primary" (click)="simpleLogin()">Entrar</ion-button>
<ion-button expand="block" shape="round" color="primary" (click)="simpleLogin()">Entrar</ion-button>
</ion-list>
</form>
</div>
+12 -8
View File
@@ -81,18 +81,22 @@ export class LoginPage implements OnInit {
}*/
}
simpleLogin(){
async simpleLogin(){
//Go to our home in home/feed.
if(this.validateInput()){
this.router.navigate(['/home/feed']);
console.log(this.postData);
if (await this.authService.login(this.postData))
{
this.router.navigate(['/home/feed']);
console.log(this.postData);
}
else
{
console.log("Não foi possível fazer login");
}
}
else{
console.log("Preencha todos campos");
console.log("Preencha todos campos");
}
}
}
+38 -7
View File
@@ -4,6 +4,7 @@ import { HttpService } from './http.service';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthConnstants } from '../config/auth-constants';
import axios from "axios";
@Injectable({
providedIn: 'root'
@@ -16,15 +17,45 @@ export class AuthService {
private router: Router
) { }
/* login(postData: any): Observable<any> {
return this.httpService.post('login', postData);
}
async login(postData: any): Promise<any> {
signup(postData: any): Observable<any> {
return this.httpService.post('signup', postData);
}
var session_url = 'https://gpr-dev-08.gabinetedigital.local/api/v2.0/me';
var credentials = btoa(postData.domainName + '\\' + postData.username + ':' + postData.password); //conversão em base64 das credenciais inseridas
var statusresult = -1;
logout(){
//configuração dos headers para autênticação básica, passando as credenciais convertidas em base64
var config = {
headers: {
'Authorization': 'Basic ' + credentials,
},
};
await axios.get(session_url, config)
.then(function (response) {
statusresult = response.status;
})
.catch(function (error) {
if (error.response) {
statusresult = error.response.status;
}
});
if (statusresult == 200)
{
return true;
}
else
if (statusresult == 401)
{
return false;
}
else
{
return false;
}
}
/* logout(){
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
this.router.navigate([''])
})