| @@ -41,7 +41,7 @@ | |||||
| }, | }, | ||||
| "devDependencies": { | "devDependencies": { | ||||
| "@angular-devkit/architect": "~0.801.2", | "@angular-devkit/architect": "~0.801.2", | ||||
| "@angular-devkit/build-angular": "^0.803.23", | |||||
| "@angular-devkit/build-angular": "^0.803.24", | |||||
| "@angular-devkit/core": "~8.1.2", | "@angular-devkit/core": "~8.1.2", | ||||
| "@angular-devkit/schematics": "~8.1.2", | "@angular-devkit/schematics": "~8.1.2", | ||||
| "@angular/cli": "~8.1.2", | "@angular/cli": "~8.1.2", | ||||
| @@ -2,7 +2,7 @@ import { NgModule } from '@angular/core'; | |||||
| import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; | import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; | ||||
| const routes: Routes = [ | const routes: Routes = [ | ||||
| { path: '', redirectTo: 'onboarding', pathMatch: 'full' }, | |||||
| { path: '', redirectTo: 'login', pathMatch: 'full' }, | |||||
| { path: 'onboarding', loadChildren: './onboarding/onboarding.module#OnboardingPageModule' }, | { path: 'onboarding', loadChildren: './onboarding/onboarding.module#OnboardingPageModule' }, | ||||
| { path: 'login', loadChildren: './login/login.module#LoginPageModule' }, | { path: 'login', loadChildren: './login/login.module#LoginPageModule' }, | ||||
| { path: 'malls', loadChildren: './malls/malls.module#MallsPageModule' }, | { path: 'malls', loadChildren: './malls/malls.module#MallsPageModule' }, | ||||
| @@ -25,6 +25,12 @@ export class AppComponent { | |||||
| this.platform.ready().then(() => { | this.platform.ready().then(() => { | ||||
| this.statusBar.styleDefault(); | this.statusBar.styleDefault(); | ||||
| this.splashScreen.hide(); | this.splashScreen.hide(); | ||||
| // if (localStorage.access_Token) { | |||||
| // this.router.navigate(['malls']); | |||||
| // } else { | |||||
| // this.router.navigate(['login']); | |||||
| // } | |||||
| }); | }); | ||||
| } | } | ||||
| @@ -9,6 +9,7 @@ import { IonicStorageModule } from '@ionic/storage'; | |||||
| import { HttpClientModule } from '@angular/common/http'; | import { HttpClientModule } from '@angular/common/http'; | ||||
| // Services import | // Services import | ||||
| import { AuthService } from './services/auth.service'; | |||||
| import { MallService } from './services/mall.service'; | import { MallService } from './services/mall.service'; | ||||
| import { OrderService } from './services/order.service'; | import { OrderService } from './services/order.service'; | ||||
| import { ToastService } from './services/toast.service'; | import { ToastService } from './services/toast.service'; | ||||
| @@ -34,6 +35,7 @@ import { Geolocation } from '@ionic-native/geolocation/ngx'; | |||||
| providers: [ | providers: [ | ||||
| StatusBar, | StatusBar, | ||||
| SplashScreen, | SplashScreen, | ||||
| AuthService, | |||||
| MallService, | MallService, | ||||
| Geolocation, | Geolocation, | ||||
| ToastService, | ToastService, | ||||
| @@ -11,7 +11,7 @@ | |||||
| </p> | </p> | ||||
| <div class="input-holder"> | <div class="input-holder"> | ||||
| <input type="email" placeholder="Email ID" [(ngModel)]="credentials.email"> | |||||
| <input type="email" placeholder="Email ID" [(ngModel)]="credentials.username"> | |||||
| </div> | </div> | ||||
| <div class="input-holder"> | <div class="input-holder"> | ||||
| @@ -1,5 +1,7 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||
| import { Router } from '@angular/router'; | import { Router } from '@angular/router'; | ||||
| import { AuthService } from '../services/auth.service'; | |||||
| import { ToastService } from '../services/toast.service'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-login', | selector: 'app-login', | ||||
| @@ -8,14 +10,17 @@ import { Router } from '@angular/router'; | |||||
| }) | }) | ||||
| export class LoginPage implements OnInit { | export class LoginPage implements OnInit { | ||||
| credentials = { | credentials = { | ||||
| email: null, | |||||
| password: null | |||||
| } | |||||
| username: 'rakeshsrh', | |||||
| password: '123456789', | |||||
| login_type: 'user' | |||||
| }; | |||||
| show_password = false; | show_password = false; | ||||
| constructor( | constructor( | ||||
| private router: Router | |||||
| private router: Router, | |||||
| private authService: AuthService, | |||||
| public toastService: ToastService | |||||
| ) { } | ) { } | ||||
| ionViewDidEnter() { | ionViewDidEnter() { | ||||
| @@ -30,8 +35,15 @@ export class LoginPage implements OnInit { | |||||
| } | } | ||||
| login() { | login() { | ||||
| this.router.navigate(['/malls']); | |||||
| document.querySelector('.menu-icon-holder').classList.remove('hide'); | |||||
| this.authService.authenticateUser(this.credentials).then((data: any) => { | |||||
| localStorage.userInfo = data; | |||||
| localStorage.access_Token = data.access_Token; | |||||
| this.router.navigate(['/malls']); | |||||
| document.querySelector('.menu-icon-holder').classList.remove('hide'); | |||||
| }, (err) => { | |||||
| console.log(err); | |||||
| this.toastService.presentToast('Please check your credentials', 'danger'); | |||||
| }) | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,3 +1,3 @@ | |||||
| export const URL: string = 'http://13.235.48.49:8989/mall-aggregator'; | |||||
| export const URL: string = 'https://mallapi.maiora.co/mall-aggregator'; | |||||
| export const TOKEN: string = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'; | export const TOKEN: string = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'; | ||||
| @@ -0,0 +1,12 @@ | |||||
| import { TestBed } from '@angular/core/testing'; | |||||
| import { AuthService } from './auth.service'; | |||||
| describe('AuthService', () => { | |||||
| beforeEach(() => TestBed.configureTestingModule({})); | |||||
| it('should be created', () => { | |||||
| const service: AuthService = TestBed.get(AuthService); | |||||
| expect(service).toBeTruthy(); | |||||
| }); | |||||
| }); | |||||
| @@ -0,0 +1,17 @@ | |||||
| import { Injectable } from '@angular/core'; | |||||
| import { HttpClient, HttpHeaders } from '@angular/common/http'; | |||||
| import { URL } from '../mocks/url'; | |||||
| @Injectable({ | |||||
| providedIn: 'root' | |||||
| }) | |||||
| export class AuthService { | |||||
| constructor( | |||||
| private http: HttpClient | |||||
| ) { } | |||||
| authenticateUser(credentials: { username: string, password: string, login_type: string }) { | |||||
| return this.http.post(URL + '/api/auth/signin', credentials).toPromise(); | |||||
| } | |||||
| } | |||||
| @@ -1,6 +1,6 @@ | |||||
| import { Injectable } from '@angular/core'; | import { Injectable } from '@angular/core'; | ||||
| import { HttpClient, HttpHeaders } from '@angular/common/http'; | import { HttpClient, HttpHeaders } from '@angular/common/http'; | ||||
| import { TOKEN, URL } from '../mocks/url'; | |||||
| import { URL } from '../mocks/url'; | |||||
| @Injectable({ | @Injectable({ | ||||
| @@ -17,7 +17,7 @@ export class MallService { | |||||
| headers: new HttpHeaders({ | headers: new HttpHeaders({ | ||||
| 'Access-Control-Allow-Origin': '*', | 'Access-Control-Allow-Origin': '*', | ||||
| 'Content-Type': 'application/json', | 'Content-Type': 'application/json', | ||||
| 'Authorization': 'Token ' + TOKEN | |||||
| 'Authorization': 'Token ' + localStorage.access_Token | |||||
| }) | }) | ||||
| }; | }; | ||||
| @@ -29,7 +29,7 @@ export class MallService { | |||||
| headers: new HttpHeaders({ | headers: new HttpHeaders({ | ||||
| 'Access-Control-Allow-Origin': '*', | 'Access-Control-Allow-Origin': '*', | ||||
| 'Content-Type': 'application/json', | 'Content-Type': 'application/json', | ||||
| 'Authorization': 'Token ' + TOKEN | |||||
| 'Authorization': 'Token ' + localStorage.access_Token | |||||
| }) | }) | ||||
| }; | }; | ||||