summaryrefslogtreecommitdiff
path: root/www/app/models
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-09-16 14:02:32 -0700
committerKali Kaneko (leap communications) <kali@leap.se>2016-09-22 11:40:11 -0400
commit073393af311d36c8ca7570ff0d3f0a3117c0b544 (patch)
treee59286ac350ba17110392f53b6e48bcedfd12ef1 /www/app/models
parentae5a20d059209f2027c05820dc3b4cfe7346c8a8 (diff)
[pkg] rename www to ui
Diffstat (limited to 'www/app/models')
-rw-r--r--www/app/models/account.js143
-rw-r--r--www/app/models/dummy_account.js33
2 files changed, 0 insertions, 176 deletions
diff --git a/www/app/models/account.js b/www/app/models/account.js
deleted file mode 100644
index 52fea93d..00000000
--- a/www/app/models/account.js
+++ /dev/null
@@ -1,143 +0,0 @@
-//
-// An account is an abstraction of a user and a provider.
-// The user part is optional, so an Account might just represent a provider.
-//
-
-import bitmask from 'lib/bitmask'
-
-export default class Account {
-
- constructor(address, props={}) {
- this.address = address
- this._authenticated = props.authenticated
- }
-
- //
- // currently, bitmask.js uses address for id, so we return address here too.
- // also, we don't know uuid until after authentication.
- //
- // TODO: change to uuid when possible.
- //
- get id() {
- return this._address
- }
-
- get domain() {
- return this._address.split('@')[1]
- }
-
- get address() {
- return this._address
- }
-
- set address(address) {
- if (!address.match('@')) {
- this._address = '@' + address
- } else {
- this._address = address
- }
- }
-
- get userpart() {
- return this._address.split('@')[0]
- }
-
- get authenticated() {
- return this._authenticated
- }
-
- get hasEmail() {
- return true
- }
-
- //
- // returns a promise, fulfill is passed account object
- //
- login(password) {
- return bitmask.bonafide.user.auth(this.address, password).then(
- response => {
- if (response.uuid) {
- this._uuid = response.uuid
- this._authenticated = true
- }
- return this
- }
- )
- }
-
- //
- // returns a promise, fulfill is passed account object
- //
- logout() {
- return bitmask.bonafide.user.logout(this.id).then(
- response => {
- this._authenticated = false
- this._address = '@' + this.domain
- return this
- }
- )
- }
-
- //
- // returns the matching account in the list of accounts, or adds it
- // if it is not already present.
- //
- static find(address) {
- // search by full address
- let account = Account.list.find(i => {
- return i.address == address
- })
- // failing that, search by domain
- if (!account) {
- let domain = '@' + address.split('@')[1]
- account = Account.list.find(i => {
- return i.address == domain
- })
- if (account) {
- account.address = address
- }
- }
- // failing that, create new account
- if (!account) {
- account = new Account(address)
- Account.list.push(account)
- }
- return account
- }
-
- //
- // returns a promise, fullfill is passed account object
- //
- static active() {
- return bitmask.bonafide.user.active().then(
- response => {
- if (response.user == '<none>') {
- return null
- } else {
- return new Account(response.user, {authenticated: true})
- }
- }
- )
- }
-
- static add(account) {
- if (!Account.list.find(i => {return i.id == account.id})) {
- Account.list.push(account)
- }
- }
-
- static remove(account) {
- Account.list = Account.list.filter(i => {
- return i.id != account.id
- })
- }
- // return Account.list
- // return new Promise(function(resolve, reject) {
- // window.setTimeout(function() {
- // resolve(['@blah', '@lala'])
- // }, 1000)
- // })
- // }
-}
-
-Account.list = []
diff --git a/www/app/models/dummy_account.js b/www/app/models/dummy_account.js
deleted file mode 100644
index 99fb6623..00000000
--- a/www/app/models/dummy_account.js
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// A proxy of an account, but with a different ID. For testing.
-//
-
-import bitmask from 'lib/bitmask'
-
-export default class DummyAccount {
-
- constructor(account) {
- this.account = account
- }
-
- get id() {
- return 'dummy--' + this.account.address
- }
-
- get domain() {return this.account.domain}
- get address() {return this.account.address}
- get userpart() {return this.account.userpart}
- get authenticated() {return this.account.authenticated}
- get hasEmail() {return this.account.hasEmail}
- login(password) {return this.account.login(password)}
-
- logout() {
- return bitmask.bonafide.user.logout(this.address).then(
- response => {
- this._authenticated = false
- this._address = '@' + this.domain
- return this
- }
- )
- }
-}