This repository has been archived by the owner on Oct 21, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet): Add wallet authentication using ember-simple-auth
- Loading branch information
Showing
40 changed files
with
615 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Base from 'ember-simple-auth/authenticators/base'; | ||
|
||
import { service } from 'ember-decorators/service'; | ||
|
||
import { defineError } from 'ember-exex/error'; | ||
|
||
export const AuthenticationError = defineError({ | ||
name: 'AuthenticationError', | ||
message: 'Authentication error', | ||
}); | ||
|
||
export default Base.extend({ | ||
@service rpc: null, | ||
@service store: null, | ||
|
||
async restore({ wallet }) { | ||
if (!wallet) { | ||
throw new AuthenticationError('Unable to restore session'); | ||
} | ||
|
||
return { wallet }; | ||
}, | ||
|
||
async authenticate({ wallet, password }) { | ||
try { | ||
await this.get('rpc').passwordEnter(wallet, password); | ||
} catch (err) { | ||
throw new AuthenticationError(err); | ||
} | ||
|
||
return { wallet }; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Component from '@ember/component'; | ||
|
||
import ChangePasswordValidations from '../../validations/change-password'; | ||
|
||
export default Component.extend({ | ||
ChangePasswordValidations, | ||
|
||
wallet: null, | ||
password: null, | ||
onSubmit: null, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{#bs-modal as |modal|}} | ||
{{#modal.header}} | ||
<h4 class="modal-title">{{t 'wallets.password.title'}}</h4> | ||
{{/modal.header}} | ||
{{#modal.body}} | ||
{{#bs-form model=(changeset (hash password=password) ChangePasswordValidations) | ||
onSubmit=(action onSubmit wallet) as |form|}} | ||
{{form.element controlType="password" label=(t 'password') property='password' required=true minlength=8}} | ||
{{/bs-form}} | ||
{{/modal.body}} | ||
{{#modal.footer}} | ||
{{#bs-button onClick=(action modal.submit) type="primary"}} | ||
{{t 'wallets.password.submit'}} | ||
{{/bs-button}} | ||
{{/modal.footer}} | ||
{{/bs-modal}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; | ||
|
||
export default Route.extend(UnauthenticatedRouteMixin, { | ||
beforeModel() { | ||
return this.transitionTo('setup'); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{outlet}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Route from '@ember/routing/route'; | ||
|
||
import { service } from 'ember-decorators/service'; | ||
|
||
export default Route.extend({ | ||
@service session: null, | ||
|
||
beforeModel() { | ||
return this.get('session').invalidate(); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{outlet}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,18 @@ | ||
import Service from '@ember/service'; | ||
import { | ||
get, | ||
set, | ||
getProperties, | ||
setProperties, | ||
getWithDefault, | ||
} from '@ember/object'; | ||
import { get, set } from '@ember/object'; | ||
|
||
import { storageFor } from 'ember-local-storage'; | ||
|
||
export default Service.extend({ | ||
settings: storageFor('settings'), | ||
|
||
get(keyName) { | ||
unknownProperty(keyName) { | ||
const settings = get(this, 'settings'); | ||
return get(settings, keyName); | ||
}, | ||
|
||
set(keyName, value) { | ||
setUnknownProperty(keyName, value) { | ||
const settings = get(this, 'settings'); | ||
return set(settings, keyName, value); | ||
}, | ||
|
||
getProperties(...args) { | ||
const settings = get(this, 'settings'); | ||
return getProperties(settings, ...args); | ||
}, | ||
|
||
setProperties(hash) { | ||
const settings = get(this, 'settings'); | ||
return setProperties(settings, hash); | ||
}, | ||
|
||
getWithDefault(keyName, defaultValue) { | ||
const settings = get(this, 'settings'); | ||
return getWithDefault(settings, keyName, defaultValue); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Route from '@ember/routing/route'; | ||
import { get } from '@ember/object'; | ||
|
||
import { service } from 'ember-decorators/service'; | ||
import { action } from 'ember-decorators/object'; | ||
|
||
export default Route.extend({ | ||
@service rpc: null, | ||
@service session: null, | ||
|
||
@action | ||
async changePassword(wallet, changeset) { | ||
const walletId = get(wallet, 'id'); | ||
const password = get(changeset, 'password'); | ||
await this.get('rpc').passwordChange(walletId, password); | ||
return this.get('session').authenticate('authenticator:wallet', { password, wallet: walletId }); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{wallet-password wallet=model onSubmit=(route-action 'changePassword')}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import validatePassword from '../validators/password'; | ||
|
||
export default { | ||
password: validatePassword(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { validateLength } from 'ember-changeset-validations/validators'; | ||
|
||
export default function validatePassword() { | ||
return validateLength({ min: 8 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Route from '@ember/routing/route'; | ||
import { get } from '@ember/object'; | ||
import { tryInvoke } from '@ember/utils'; | ||
|
||
import { service } from 'ember-decorators/service'; | ||
import { action } from 'ember-decorators/object'; | ||
|
||
export default Route.extend({ | ||
@service window: null, | ||
|
||
@action | ||
cancel() { | ||
const window = this.get('window'); | ||
const history = get(window, 'history'); | ||
return tryInvoke(history, 'back'); | ||
}, | ||
|
||
@action | ||
logout() { | ||
return this.transitionTo('logout'); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{{#bs-modal onHide=(route-action 'cancel') onSubmit=(route-action 'logout') as |modal|}} | ||
{{#modal.header}} | ||
<h4 class="modal-title"> | ||
{{fa-icon 'exclamation-triangle' class="text-danger"}} | ||
{{t 'wallets.logout.title'}} | ||
</h4> | ||
{{/modal.header}} | ||
{{#modal.body}} | ||
<p class="lead">{{t 'wallets.logout.lead'}}</p> | ||
<p>{{t 'wallets.logout.warning' htmlSafe=true}}</p> | ||
{{/modal.body}} | ||
{{#modal.footer}} | ||
{{#bs-button onClick=(action modal.close) type="secondary"}} | ||
{{t 'cancel'}} | ||
{{/bs-button}} | ||
{{#bs-button onClick=(action modal.submit) type="danger"}} | ||
{{fa-icon 'sign-out'}} | ||
{{t 'logout'}} | ||
{{/bs-button}} | ||
{{/modal.footer}} | ||
{{/bs-modal}} |
Oops, something went wrong.