From 0c38be47b9e34073125ccf6ddb307a3f3ef293f8 Mon Sep 17 00:00:00 2001 From: spekulaas Date: Thu, 30 Dec 2021 03:12:55 +0100 Subject: [PATCH] created storage --- AuthentesApp/package-lock.json | 45 ++++++++++++++++++- AuthentesApp/package.json | 1 + AuthentesApp/src/app/app.module.ts | 3 +- .../src/app/modalsGame/modalsGame.page.ts | 8 ++-- AuthentesApp/src/app/services/game.service.ts | 23 ++++++++++ .../src/app/services/storage.service.ts | 33 ++++++++++++++ 6 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 AuthentesApp/src/app/services/game.service.ts create mode 100644 AuthentesApp/src/app/services/storage.service.ts diff --git a/AuthentesApp/package-lock.json b/AuthentesApp/package-lock.json index e179174..3de7a41 100644 --- a/AuthentesApp/package-lock.json +++ b/AuthentesApp/package-lock.json @@ -1889,6 +1889,30 @@ "tslib": "^2.1.0" } }, + "@ionic/storage": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@ionic/storage/-/storage-3.0.6.tgz", + "integrity": "sha512-sw+zSJINIpbQCGZR9mEtb9N0WmZLuhcMVqOZJBqLuDACAMdXqG39zmp5nSVqhGI1/9X3nd0K5gVn6icyVfUnUg==", + "requires": { + "localforage": "^1.9.0" + } + }, + "@ionic/storage-angular": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@ionic/storage-angular/-/storage-angular-3.0.6.tgz", + "integrity": "sha512-ZXlIFWGU27aCxVFgZb0KFJFtWwnn6+HK6v0rMGzjN8f7oV2ewXaQ2dl1gTw/A8YoozTVPOFxwfFHCjhWLFR1Fw==", + "requires": { + "@ionic/storage": "^3.0.4", + "tslib": "^1.10.0" + }, + "dependencies": { + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + } + } + }, "@istanbuljs/schema": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", @@ -7165,8 +7189,7 @@ "immediate": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=", - "dev": true + "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=" }, "import-fresh": { "version": "3.3.0", @@ -8462,6 +8485,24 @@ "json5": "^2.1.2" } }, + "localforage": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz", + "integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==", + "requires": { + "lie": "3.1.1" + }, + "dependencies": { + "lie": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz", + "integrity": "sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=", + "requires": { + "immediate": "~3.0.5" + } + } + } + }, "locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", diff --git a/AuthentesApp/package.json b/AuthentesApp/package.json index cb93e62..70bdac8 100644 --- a/AuthentesApp/package.json +++ b/AuthentesApp/package.json @@ -22,6 +22,7 @@ "@ionic-native/core": "^5.36.0", "@ionic-native/status-bar": "^5.36.0", "@ionic/angular": "^5.5.2", + "@ionic/storage-angular": "^3.0.6", "cordova-android": "9.1.0", "rxjs": "~6.6.0", "tslib": "^2.2.0", diff --git a/AuthentesApp/src/app/app.module.ts b/AuthentesApp/src/app/app.module.ts index 9269da9..7a7844a 100644 --- a/AuthentesApp/src/app/app.module.ts +++ b/AuthentesApp/src/app/app.module.ts @@ -8,11 +8,12 @@ import { AppComponent } from './app.component'; import { AppRoutingModule } from './app-routing.module'; import { StatusBar } from '@ionic-native/status-bar/ngx'; +import { IonicStorageModule } from '@ionic/storage-angular'; @NgModule({ declarations: [AppComponent], entryComponents: [], - imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule], + imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, IonicStorageModule.forRoot()], providers: [ StatusBar, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } diff --git a/AuthentesApp/src/app/modalsGame/modalsGame.page.ts b/AuthentesApp/src/app/modalsGame/modalsGame.page.ts index 81867be..71c5392 100644 --- a/AuthentesApp/src/app/modalsGame/modalsGame.page.ts +++ b/AuthentesApp/src/app/modalsGame/modalsGame.page.ts @@ -1,6 +1,7 @@ import { Component, Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { ModalController } from '@ionic/angular'; +import { GameService } from '../services/game.service'; @Injectable({ providedIn: 'root' @@ -13,7 +14,7 @@ import { ModalController } from '@ionic/angular'; }) export class ModalsGamePage { - constructor(private router: Router, public modalController: ModalController) {} + constructor(private router: Router, public modalController: ModalController, private game: GameService) {} async presentModal(game: string) { const modal = await this.modalController.create({ @@ -34,11 +35,12 @@ export class ModalsGamePage { }); } - play(game: string) { + async play(game: string) { // check if game cookie exists // create cookie with data if non existing // continue or restart with cookie - + await console.log(this.game.checkGameStorage(game)); + console.log("pardon?"); // when all the steps are done and clicked on play, dismiss modal and open page this.dismiss(); // routing is in lowercase, set text to lower diff --git a/AuthentesApp/src/app/services/game.service.ts b/AuthentesApp/src/app/services/game.service.ts new file mode 100644 index 0000000..863e215 --- /dev/null +++ b/AuthentesApp/src/app/services/game.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; +import { StorageService } from './storage.service'; +import { AlertService } from './alert.service'; + +@Injectable({ + providedIn: 'root' +}) +export class GameService { + + constructor(private storage: StorageService, private alert: AlertService) {} + + public async checkGameStorage(game: string){ + + if(await this.storage.get(`${game.toUpperCase()}GAME_TOKEN`)){ + // continue or restart + console.log(await this.alert.presentAlertConfirm("Game found", "Do u want to continue or restart?", "restart", "continue")); + return "storage found"; + } + // standard create new + return "no storage"; + + } +} \ No newline at end of file diff --git a/AuthentesApp/src/app/services/storage.service.ts b/AuthentesApp/src/app/services/storage.service.ts new file mode 100644 index 0000000..50aa19f --- /dev/null +++ b/AuthentesApp/src/app/services/storage.service.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@angular/core'; +import { Storage } from '@ionic/storage-angular'; + +@Injectable({ + providedIn: 'root' +}) +export class StorageService { + + private _storage: Storage | null = null; + + constructor(private storage: Storage) {} + + async init() { + console.log("[StorageService] Initializing storage..."); + const storage = await this.storage.create(); + this._storage = storage; + } + + public async set(key: string, value: any) { + console.log("[StorageService] Setting value in storage:", key, value); + await this._storage?.set(key, value); + } + + public async get(key: string) { + console.log("[StorageService] Getting value from storage:", key); + return await this._storage?.get(key); + } + public async remove(key: string){ + console.log("[StorageService] removing value from storage:", key); + return await this._storage?.remove(key); + } + +} \ No newline at end of file