UNPKG

awaken-direct-democracy

Version:

This is the functional skeleton / working mock up of a disruptive app to increase voter turnout and participation driven at the start by just one person - Tom Atkinson in New Zealand - after watching in horror the signing of the TPPA in Auckland February

64 lines (50 loc) 1.37 kB
import { Injectable } from '@angular/core'; import { Events } from 'ionic-angular'; import { Storage } from '@ionic/storage'; @Injectable() export class UserData { _favorites = []; HAS_LOGGED_IN = 'hasLoggedIn'; constructor(public events: Events, public storage: Storage) {} hasFavorite(sessionName) { return (this._favorites.indexOf(sessionName) > -1); } addFavorite(sessionName) { this._favorites.push(sessionName); } removeFavorite(sessionName) { let index = this._favorites.indexOf(sessionName); if (index > -1) { this._favorites.splice(index, 1); } } login(username) { this.storage.set(this.HAS_LOGGED_IN, true); this.setUsername(username); this.events.publish('user:login'); } signup(username) { this.storage.set(this.HAS_LOGGED_IN, true); this.setUsername(username); this.events.publish('user:signup'); } logout() { this.storage.remove(this.HAS_LOGGED_IN); this.storage.remove('username'); this.events.publish('user:logout'); } setUsername(username) { this.storage.set('username', username); } getUsername() { return this.storage.get('username').then((value) => { return value; }); } // return a promise hasLoggedIn() { return this.storage.get(this.HAS_LOGGED_IN).then((value) => { return value === true; }); } }