diff options
author | elijah <elijah@riseup.net> | 2016-09-29 11:56:44 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2016-09-29 11:58:51 -0700 |
commit | e7281dd47f375c1b0a72ae85505319c4d87fb524 (patch) | |
tree | 8cc4c3967eebefd26eaaedabbfd41ea4cde0390d /ui | |
parent | bf6571764fc0d7c0ef0153e3e5e9174221aa167d (diff) |
[feat] ui - improved account list, show multiple login sessions
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app/app.js | 19 | ||||
-rw-r--r-- | ui/app/components/login.js | 2 | ||||
-rw-r--r-- | ui/app/components/main_panel/index.js | 1 | ||||
-rw-r--r-- | ui/app/models/account.js | 35 |
4 files changed, 41 insertions, 16 deletions
diff --git a/ui/app/app.js b/ui/app/app.js index 45f87ddf..3b3ac5de 100644 --- a/ui/app/app.js +++ b/ui/app/app.js @@ -1,5 +1,6 @@ import bitmask from 'lib/bitmask' import Account from 'models/account' +import Provider from 'models/provider' class Application { constructor() { @@ -17,12 +18,18 @@ class Application { } start() { - Account.active().then(account => { - if (account == null) { - this.show('greeter') - } else { - this.show('main', {initialAccount: account}) - } + Provider.list(false).then(domains => { + Account.initialize_list(domains) + Account.active().then(account => { + if (account == null) { + this.show('greeter') + } else { + Account.add_primary(account) + this.show('main', {initialAccount: account}) + } + }, error => { + this.show('error', {error: error}) + }) }, error => { this.show('error', {error: error}) }) diff --git a/ui/app/components/login.js b/ui/app/components/login.js index 562ab5ac..059551f9 100644 --- a/ui/app/components/login.js +++ b/ui/app/components/login.js @@ -356,7 +356,7 @@ class Login extends React.Component { } doLogin() { - let account = Account.find(this.state.username) + let account = Account.find_or_add(this.state.username) account.login(this.state.password).then( account => { this.setState({loading: false}) diff --git a/ui/app/components/main_panel/index.js b/ui/app/components/main_panel/index.js index a05f3077..775dff61 100644 --- a/ui/app/components/main_panel/index.js +++ b/ui/app/components/main_panel/index.js @@ -32,7 +32,6 @@ export default class MainPanel extends React.Component { componentWillMount() { if (this.props.initialAccount) { - Account.add(this.props.initialAccount) this.setState({ account: this.props.initialAccount, accounts: Account.list diff --git a/ui/app/models/account.js b/ui/app/models/account.js index 726a8b8c..04c8163e 100644 --- a/ui/app/models/account.js +++ b/ui/app/models/account.js @@ -57,11 +57,6 @@ export default class Account { return bitmask.bonafide.user.auth(this.address, password).then( response => { if (response.uuid) { - // currently, only one account can be authenticated at once - Account.list.forEach(account => { - account._authenticated = false - // if(account.id != this.id) {account.logout()} - }) this._uuid = response.uuid this._authenticated = true } @@ -84,8 +79,7 @@ export default class Account { } // - // returns the matching account in the list of accounts, or adds it - // if it is not already present. + // returns the matching account in the list of accounts // static find(address) { // search by full address @@ -102,7 +96,11 @@ export default class Account { account.address = address } } - // failing that, create new account + return account + } + + static find_or_add(address) { + let account = Account.find(address) if (!account) { account = new Account(address) Account.list.push(account) @@ -116,6 +114,7 @@ export default class Account { static active() { return bitmask.bonafide.user.active().then( response => { + console.log(response) if (response.user == '<none>') { return null } else { @@ -145,6 +144,26 @@ export default class Account { } ) } + + static initialize_list(domains) { + for (let domain of domains) { + Account.add(new Account(domain)) + } + } + + // + // inserts at the front of the account list + // removing any other accounts with the same domain. + // + // this is a temporary hack to support the old behavior + // util the backend has a proper concept of an account list. + // + static add_primary(account) { + Account.list = Account.list.filter(i => { + return i.domain != account.domain + }) + Account.list.unshift(account) + } } Account.list = [] |