Skip to content

Commit

Permalink
#3 Complete password tested. MFA no longer is two steps to activate.
Browse files Browse the repository at this point in the history
  • Loading branch information
nadnoslen committed Jan 26, 2019
1 parent 5eb12bc commit 9df4774
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 60 deletions.
7 changes: 4 additions & 3 deletions app/routes/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-

export default Route.extend(UnauthenticatedRouteMixin, {
actions: {
completePassword(authenticationState, newPassword) {
completePassword(authenticationState, newPassword, additionalAttributes = {}/*, submitEvent*/) {
this.get('session')
.completePassword(authenticationState, newPassword)
.completePassword(authenticationState, newPassword, additionalAttributes)
.then(authenticationState => {
if (authenticationState.get('mfaRequired?')) {
set(this, 'controller.model.authenticationState', authenticationState);
Expand All @@ -30,7 +30,7 @@ export default Route.extend(UnauthenticatedRouteMixin, {
this.get('session')
.signIn(username, password)
.then(authenticationState => {
if (authenticationState.get('mfaRequired?')) {
if (authenticationState.get('mfaRequired?') || authenticationState.get('newPasswordRequired?')) {
set(this, 'controller.model.authenticationState', authenticationState);
}
})
Expand All @@ -44,6 +44,7 @@ export default Route.extend(UnauthenticatedRouteMixin, {

model(params) {
return {
additionalAttributes: {},
authenticationState: {}, // will be set during sign in if MFA is enabled
mfaCode: '',
newPassword: '',
Expand Down
4 changes: 2 additions & 2 deletions app/routes/protected/profile/change-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default Route.extend({
session
.changePassword(currentPassword, newPassword)
.then(() => {
this.transitionTo('protected.index')
.then(newRoute => newRoute.get('notify').success('Your password was updated successfully.'));
this.refresh();
this.get('notify').success('Your password was updated successfully.');
})
.catch(response => this.get('notify').error(response.message));
return false;
Expand Down
11 changes: 2 additions & 9 deletions app/routes/protected/profile/configure-mfa.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,15 @@ export default Route.extend({
return false;
},

finalize(session, mfaActivationState) {
verify(session, mfaActivationState) {
session
.finalizeTotp(mfaActivationState)
.verifyTotpPasscode(mfaActivationState)
.then(() => {
set(this, 'controller.model.mfaActivationState', {});
this.get('notify').success('Multi-factor authentication is now enabled.')
})
.catch((response) => this.get('notify').error(response.message));
return false;
},

verify(session, mfaActivationState) {
session
.verifyTotpPasscode(mfaActivationState)
.catch((response) => this.get('notify').error(response.message));
return false;
}
},

Expand Down
34 changes: 33 additions & 1 deletion app/templates/login.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
<legend>Set Your Password</legend>
{{!-- --------------------------------------------------------------------------- Complete New Password --}}
<form class="form"
onsubmit={{action (route-action "completePassword" model.authenticationState model.newPassword)}}>
onsubmit={{action
(route-action "completePassword" model.authenticationState model.newPassword model.additionalAttributes)}}>
<div class="form-group d-none">
<label for="js-username-new-password" class="control-label">Email Address</label>
{{input-text
Expand All @@ -67,13 +68,44 @@
autocomplete="new-password"
class="form-control"
placeholder="Password"
required=true
type="password"
value=model.newPassword
}}
<small id="js-password-new-password-help" class="form-text text-muted">
Please choose your new password because that original one we gave you was gnarley!
</small>
</div>
<div class="form-group">
<label for="js-given-name" class="control-label">Given Name</label>
{{input-text
aria-describedby="js-given-name-help"
class="form-control"
id="js-given-name"
placeholder="Given Name"
required=true
type="text"
value=model.additionalAttributes.given_name
}}
<small id="js-given-name-help" class="form-text text-muted">
<strong>Required</strong> What is your given/first name?
</small>
</div>
<div class="form-group">
<label for="js-family-name" class="control-label">Family Name</label>
{{input-text
aria-describedby="js-family-name-help"
class="form-control"
id="js-family-name"
placeholder="Family Name"
required=true
type="text"
value=model.additionalAttributes.family_name
}}
<small id="js-family-name-help" class="form-text text-muted">
<strong>Required</strong> What is your family/last name?
</small>
</div>
<div class="form-group text-right">
<button class="btn btn-outline-primary" type="submit">
Submit
Expand Down
42 changes: 6 additions & 36 deletions app/templates/protected/profile/configure-mfa.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</div>
</form>
{{else}}
{{#if model.mfaActivationState.step1?}}
{{#if model.mfaActivationState.verifyRequired?}}
<legend>Verify Authenticator</legend>
<form class="form" onsubmit={{action (route-action "verify" session model.mfaActivationState)}}>
<div class="form-group">
Expand All @@ -47,18 +47,18 @@
</small>
</div>
<div class="form-group">
<label for="js-passcode-one" class="control-label">Passcode 1 of 2</label>
<label for="js-passcode" class="control-label">Confirm Passcode</label>
{{input-text
aria-describedby="js-passcode-one-help"
aria-describedby="js-passcode-help"
autofocus=true
class="form-control"
id="js-passcode-one"
id="js-passcode"
maxlength=6
placeholder="Passcode"
type="number"
value=model.mfaActivationState.passcodeOne
value=model.mfaActivationState.passcode
}}
<small id="js-passcode-one-help" class="form-text text-muted">
<small id="js-passcode-help" class="form-text text-muted">
What is current code from your Authenticator app?
</small>
</div>
Expand All @@ -73,36 +73,6 @@
</div>
</div>
</form>
{{else if model.mfaActivationState.step2?}}
<legend>Finalize Authenticator Setup</legend>
<form class="form" onsubmit={{action (route-action "finalize" session model.mfaActivationState)}}>
<div class="form-group">
<label for="js-passcode-two" class="control-label">Passcode 2 of 2</label>
{{input-text
aria-describedby="js-passcode-two-help"
autofocus=true
class="form-control"
id="js-passcode-two"
maxlength=6
placeholder="Passcode"
type="number"
value=model.mfaActivationState.passcodeTwo
}}
<small id="js-passcode-two-help" class="form-text text-muted">
What is next code from your Authenticator app?
</small>
</div>
<div class="form-group text-right">
<div class="btn-group">
<button class="btn btn-outline-secondary" onclick={{action (route-action "cancel")}} type="button">
Cancel
</button>
<button class="btn btn-outline-primary" type="submit">
Finish
</button>
</div>
</div>
</form>
{{else}}
<legend>Multi-Factor Authentication Is <span class="text-danger">Disabled</span></legend>
<form class="form" onsubmit={{action (route-action "enable" session)}}>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/protected/profile/locale-timezone.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
autofocus=true
class="form-control"
id="js-locale"
placeholder="en_ca"
placeholder="en_CA"
type="text"
value=model.locale
}}
Expand Down
6 changes: 3 additions & 3 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ module.exports = function (environment) {
// Amazon Cognito Region
region: 'ca-central-1',
// Amazon Cognito User Pool ID
userPoolId: 'ca-central-1_ocRK2nsIR',
// Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: '5ht2oa80l95idve05t3q5ir10u',
userPoolId: 'ca-central-1_gVEm5uxH5',
// Amazon Cognito Web Client ID (26-char alphanumeric string) -> `App integration - App client settings`
userPoolWebClientId: '20fb6agrojrv318os33svrhe9u',
}
},

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"ember-resolver": "^5.0.1",
"ember-route-action-helper": "^2.0.6",
"ember-simple-auth": "^1.8.0",
"ember-simple-auth-aws-amplify": "^0.1.0-alpha.8",
"ember-simple-auth-aws-amplify": "^0.2.0-alpha.0",
"ember-source": "~3.4.0",
"ember-welcome-page": "^3.2.0",
"eslint-plugin-ember": "^5.2.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4668,10 +4668,10 @@ ember-router-generator@^1.2.3:
dependencies:
recast "^0.11.3"

ember-simple-auth-aws-amplify@^0.1.0-alpha.8:
version "0.1.0-alpha.8"
resolved "https://registry.yarnpkg.com/ember-simple-auth-aws-amplify/-/ember-simple-auth-aws-amplify-0.1.0-alpha.8.tgz#7b5010a08b7be0f28eb001069ed196eb1db01aec"
integrity sha512-snPU1ZsOWpSM1cdHMBgVqwGHDwVppZGcpumRgVk9bILY67Km3Bcc1WMs60xIUJ8fE2LJL3LbWJ9GQdF0wNKw2Q==
ember-simple-auth-aws-amplify@^0.2.0-alpha.0:
version "0.2.0-alpha.0"
resolved "https://registry.yarnpkg.com/ember-simple-auth-aws-amplify/-/ember-simple-auth-aws-amplify-0.2.0-alpha.0.tgz#553fccd3836f1eee60f70b29cd730babaf97ba31"
integrity sha512-+STL+ctHwjKHWTPlHnwX8FQN8SVTAPjAOO2K3s81zm06KeGA+Csan+6YQCj01U/rQMJHmq+t5fqW1prXg6idHw==
dependencies:
"@aws-amplify/auth" "^1.2.14"
"@aws-amplify/core" "^1.0.21"
Expand Down

0 comments on commit 9df4774

Please sign in to comment.