diff --git a/src/app/layouts/full-layout.component.html b/src/app/layouts/full-layout.component.html
index d12013d..8098749 100644
--- a/src/app/layouts/full-layout.component.html
+++ b/src/app/layouts/full-layout.component.html
@@ -38,7 +38,7 @@
Notifications42
Lock account
- Logout
+ Logout
diff --git a/src/app/layouts/full-layout.component.ts b/src/app/layouts/full-layout.component.ts
index d941dcc..2a5c56d 100644
--- a/src/app/layouts/full-layout.component.ts
+++ b/src/app/layouts/full-layout.component.ts
@@ -1,11 +1,17 @@
import { Component, OnInit } from '@angular/core';
+import { ApiService } from '../providers/api-service';
+import {Router } from '@angular/router';
@Component({
selector: 'app-dashboard',
- templateUrl: './full-layout.component.html'
+ templateUrl: './full-layout.component.html',
+ providers: [ApiService]
})
export class FullLayoutComponent implements OnInit {
-
+ constructor(
+ private api: ApiService,
+ private router: Router,
+ ) {}
public disabled = false;
public status: {isopen: boolean} = {isopen: false};
@@ -20,4 +26,14 @@ export class FullLayoutComponent implements OnInit {
}
ngOnInit(): void {}
-}
+ userlogout() {
+ console.log('logout clicked');
+ this.api
+ .logout()
+ .subscribe(
+ result => {
+ console.log('Logged out!');
+ }
+ );
+ }
+}
\ No newline at end of file
diff --git a/src/app/pages/login.component.html b/src/app/pages/login.component.html
index 4e1d620..98d74a3 100644
--- a/src/app/pages/login.component.html
+++ b/src/app/pages/login.component.html
@@ -32,7 +32,7 @@
Sign up
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
+
diff --git a/src/app/pages/register.component.ts b/src/app/pages/register.component.ts
index 9cd0389..76b2f1c 100644
--- a/src/app/pages/register.component.ts
+++ b/src/app/pages/register.component.ts
@@ -72,7 +72,7 @@ export class RegisterComponent {
age_range: customerForm.age_range,
};
console.log(data);
- /* this.api
+ this.api
.register(data)
.subscribe(
result => {
@@ -82,7 +82,7 @@ export class RegisterComponent {
error => {
console.log( error._body );
}
- );*/
+ );
}
onSubmitOrganisation() {
@@ -105,7 +105,7 @@ export class RegisterComponent {
postcode: organisationForm.postcode,
};
console.log(data);
- /* this.api
+ this.api
.register(data)
.subscribe(
result => {
@@ -115,7 +115,7 @@ export class RegisterComponent {
error => {
console.log( error._body );
}
- );*/
+ );
}
diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts
index 244087c..d4d2398 100644
--- a/src/app/providers/api-service.ts
+++ b/src/app/providers/api-service.ts
@@ -3,16 +3,36 @@ import { Http } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
-
/* this provider handles the interaction between server and client */
@Injectable()
export class ApiService {
private apiUrl = 'https://dev.app.peartrade.org/api';
- private sessionKey: string;
+ private sessionKey: string = null;
constructor(
private http: Http,
- ) {}
+ ) {
+ if (localStorage.getItem('sessionKey') ) {
+ this.sessionKey = localStorage.getItem('sessionKey');
+ }
+ }
+
+ private getSessionKey() {
+ console.log('get key');
+ return this.sessionKey;
+ }
+
+ private setSessionKey(key) {
+ console.log('set key');
+ this.sessionKey = key;
+ localStorage.setItem('sessionKey', this.sessionKey);
+ }
+
+ private removeSessionKey() {
+ console.log('remove key');
+ this.sessionKey = null;
+ localStorage.removeItem('sessionKey');
+ }
public getAgeRanges() {
return this.http.get(
@@ -33,10 +53,20 @@ export class ApiService {
data
).map( response => response.json() );
login_event.subscribe(
- result => { this.sessionKey = result.session_key }
+ result => { this.setSessionKey(result.session_key) }
);
return login_event;
}
+
+ public logout() {
+ console.log(this.sessionKey);
+ return this.http.post(
+ this.apiUrl + '/logout',
+ {
+ session_key : this.sessionKey,
+ }
+ ).map( response => { this.removeSessionKey(); return response.json() } );
+ }
public search(data) {
data.session_key = this.sessionKey;