Przeglądaj źródła

Login service competed

master
kj1352 5 lat temu
rodzic
commit
ae0831ab62
11 zmienionych plików z 1796 dodań i 2798 usunięć
  1. +1734
    -2785
      package-lock.json
  2. +1
    -1
      package.json
  3. +1
    -1
      src/app/app-routing.module.ts
  4. +6
    -0
      src/app/app.component.ts
  5. +2
    -0
      src/app/app.module.ts
  6. +1
    -1
      src/app/login/login.page.html
  7. +18
    -6
      src/app/login/login.page.ts
  8. +1
    -1
      src/app/mocks/url.ts
  9. +12
    -0
      src/app/services/auth.service.spec.ts
  10. +17
    -0
      src/app/services/auth.service.ts
  11. +3
    -3
      src/app/services/mall.service.ts

+ 1734
- 2785
package-lock.json
Plik diff jest za duży
Wyświetl plik


+ 1
- 1
package.json Wyświetl plik

@@ -41,7 +41,7 @@
},
"devDependencies": {
"@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/schematics": "~8.1.2",
"@angular/cli": "~8.1.2",


+ 1
- 1
src/app/app-routing.module.ts Wyświetl plik

@@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [
{ path: '', redirectTo: 'onboarding', pathMatch: 'full' },
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: 'onboarding', loadChildren: './onboarding/onboarding.module#OnboardingPageModule' },
{ path: 'login', loadChildren: './login/login.module#LoginPageModule' },
{ path: 'malls', loadChildren: './malls/malls.module#MallsPageModule' },


+ 6
- 0
src/app/app.component.ts Wyświetl plik

@@ -25,6 +25,12 @@ export class AppComponent {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();

// if (localStorage.access_Token) {
// this.router.navigate(['malls']);
// } else {
// this.router.navigate(['login']);
// }
});
}



+ 2
- 0
src/app/app.module.ts Wyświetl plik

@@ -9,6 +9,7 @@ import { IonicStorageModule } from '@ionic/storage';
import { HttpClientModule } from '@angular/common/http';

// Services import
import { AuthService } from './services/auth.service';
import { MallService } from './services/mall.service';
import { OrderService } from './services/order.service';
import { ToastService } from './services/toast.service';
@@ -34,6 +35,7 @@ import { Geolocation } from '@ionic-native/geolocation/ngx';
providers: [
StatusBar,
SplashScreen,
AuthService,
MallService,
Geolocation,
ToastService,


+ 1
- 1
src/app/login/login.page.html Wyświetl plik

@@ -11,7 +11,7 @@
</p>

<div class="input-holder">
<input type="email" placeholder="Email ID" [(ngModel)]="credentials.email">
<input type="email" placeholder="Email ID" [(ngModel)]="credentials.username">
</div>

<div class="input-holder">


+ 18
- 6
src/app/login/login.page.ts Wyświetl plik

@@ -1,5 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { ToastService } from '../services/toast.service';

@Component({
selector: 'app-login',
@@ -8,14 +10,17 @@ import { Router } from '@angular/router';
})
export class LoginPage implements OnInit {
credentials = {
email: null,
password: null
}
username: 'rakeshsrh',
password: '123456789',
login_type: 'user'
};

show_password = false;

constructor(
private router: Router
private router: Router,
private authService: AuthService,
public toastService: ToastService
) { }

ionViewDidEnter() {
@@ -30,8 +35,15 @@ export class LoginPage implements OnInit {
}

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
- 1
src/app/mocks/url.ts Wyświetl plik

@@ -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';

+ 12
- 0
src/app/services/auth.service.spec.ts Wyświetl plik

@@ -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();
});
});

+ 17
- 0
src/app/services/auth.service.ts Wyświetl plik

@@ -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();
}
}

+ 3
- 3
src/app/services/mall.service.ts Wyświetl plik

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { TOKEN, URL } from '../mocks/url';
import { URL } from '../mocks/url';


@Injectable({
@@ -17,7 +17,7 @@ export class MallService {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': 'Token ' + TOKEN
'Authorization': 'Token ' + localStorage.access_Token
})
};

@@ -29,7 +29,7 @@ export class MallService {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'Authorization': 'Token ' + TOKEN
'Authorization': 'Token ' + localStorage.access_Token
})
};



Ładowanie…
Anuluj
Zapisz