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'; ...@@ -10,11 +10,14 @@ import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { Geolocation } from '@ionic-native/geolocation/ngx'; import { Geolocation } from '@ionic-native/geolocation/ngx';
import { HttpClientModule } from '@angular/common/http';
@NgModule({ @NgModule({
declarations: [AppComponent], declarations: [AppComponent],
entryComponents: [], entryComponents: [],
imports: [ imports: [
BrowserModule, BrowserModule,
HttpClientModule,
IonicModule.forRoot(), IonicModule.forRoot(),
AppRoutingModule AppRoutingModule
], ],
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
</div> </div>
<div padding> <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> </div>
</ion-col> </ion-col>
</ion-row> </ion-row>
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
templateUrl: './login.page.html', templateUrl: './login.page.html',
...@@ -9,20 +12,33 @@ import { Router } from '@angular/router'; ...@@ -9,20 +12,33 @@ import { Router } from '@angular/router';
export class LoginPage implements OnInit { export class LoginPage implements OnInit {
username = ""; username = "";
password = ""; password = "";
correctCredentials=false; correctCredentials = false;
loginApi: Observable<any>;
constructor(private router: Router) { } constructor(private router: Router, public httpClient: HttpClient) {
}
ngOnInit() { 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