Commit e878023d authored by Ratnadeep Rajendra Kharade's avatar Ratnadeep Rajendra Kharade
Browse files

Integrated login with api call

parent e329eaf8
......@@ -10,11 +10,14 @@ import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
HttpClientModule,
IonicModule.forRoot(),
AppRoutingModule
],
......
......@@ -27,7 +27,7 @@
</div>
<div padding>
<ion-button size="large" expand="block" (click)="clickMe()">Login</ion-button>
<ion-button size="large" expand="block" (click)="login()">Login</ion-button>
</div>
</ion-col>
</ion-row>
......
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
......@@ -9,20 +12,33 @@ import { Router } from '@angular/router';
export class LoginPage implements OnInit {
username = "";
password = "";
correctCredentials=false;
correctCredentials = false;
loginApi: Observable<any>;
constructor(private router: Router) { }
constructor(private router: Router, public httpClient: HttpClient) {
}
ngOnInit() {
}
clickMe() {
if (this.username === "admin" && this.password === "admin" || this.username === "demo" && this.password === "demo") {
this.router.navigateByUrl('/home');
}
else { this.correctCredentials=true; }
login() {
this.loginApiCall();
}
loginApiCall() {
this.loginApi = this.httpClient.post('http://193.196.52.237:8081/authenticate', {
"email": this.username,
"password": this.password
});
this.loginApi
.subscribe((data) => {
console.log('my data: ', data);
this.router.navigateByUrl('/home');
}, (error) => {
console.log(error);
this.correctCredentials = true;
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment