Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/pages/login/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {FormValidator} from '../../validators/formValidator';
// pages
import { TabsPage } from '../../pages/tabs/tabs.page';
import { ForgetPasswordPage } from '../../pages/forget-password/forget-password';
import { TutorialPage } from '../settings/tutorial/tutorial.page';

/* This page is for handling user login process */
@Component({
selector: 'page-login',
Expand Down Expand Up @@ -70,12 +72,25 @@ export class LoginPage {
return false;
}
}

private popupTutorial() {
// this.navCtrl.push(TutorialPage);
let tutorialModal = this.modalCtrl.create(TutorialPage);
tutorialModal.present();
}

/**
* user login function to authenticate user with email and password
*/
userLogin() {
async userLogin() {
let self = this;
this.cacheService.clear().then(() => {
const hasLoggedInBefore = await this.cacheService.hasBeenAccessed({ verify: true });

this.cacheService.clear().then(async () => {
if (hasLoggedInBefore) { // reset cache
await this.cacheService.hasBeenAccessed();
}

// add loading effect during login process
const loading = this.loadingCtrl.create({
dismissOnPageChange: true,
Expand All @@ -84,7 +99,13 @@ export class LoginPage {
loading.present().then(() => {
// This part is calling post_auth() API from backend
this.authService.loginAuth(this.email, this.password)
.subscribe(data => {
.subscribe(async (data) => {
if (!await this.cacheService.hasBeenAccessed({ verify: true })) {
// show tutorial
this.popupTutorial();
await this.cacheService.hasBeenAccessed();
}

// this.getLogInData(data);
self.cacheService.setLocalObject('apikey', data.apikey);
if (data.Experience.config) {
Expand Down
20 changes: 12 additions & 8 deletions src/pages/settings/settings.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class SettingsPage {
}
// getting user data saved in cashe
this.user = this.cache.getLocalObject('user');

}
public getUserEmail() {
return this.cache.getLocalObject('email') || '';
Expand Down Expand Up @@ -132,13 +132,17 @@ export class SettingsPage {
spinner: 'hide',
content: this.logoutMessage
});
loader.present().then(() => {
this.cache.clear().then(() => {
localStorage.clear();
window.location.reload(); // the reason of doing this is because of we need to refresh page content instead of API data cache issue occurs
loader.dismiss();
this.navCtrl.push(LoginPage);
});
loader.present().then(async () => {
const accessedBefore = this.cache.hasBeenAccessed({ verify: true });
await this.cache.clear();
localStorage.clear();
window.location.reload(); // the reason of doing this is because of we need to refresh page content instead of API data cache issue occurs
loader.dismiss();
this.navCtrl.push(LoginPage);
// reset accessed cache
if (accessedBefore) {
this.cache.hasBeenAccessed();
}
});
}

Expand Down
10 changes: 10 additions & 0 deletions src/shared/cache/cache.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { Cache } from '../app/cache';

import * as _ from 'lodash';

// marking ID for accessed record
const HAS_ACCESSED = 'hasAccessed';

@Injectable()
export class CacheService {

Expand Down Expand Up @@ -136,4 +139,11 @@ export class CacheService {
const readonly = this.getLocalObject('enrolmentStatus');
return (readonly === 'readonly');
}

public hasBeenAccessed(option?): Promise<any> {
if (option && option.verify) {
return this.storage.get(HAS_ACCESSED);
}
return this.storage.set(HAS_ACCESSED, true);
}
}