diff --git a/app/app/components/password-reset.js b/app/app/components/password-reset.js new file mode 100644 index 00000000..2492fb95 --- /dev/null +++ b/app/app/components/password-reset.js @@ -0,0 +1,57 @@ +import Ember from 'ember'; + +const { + isEmpty, + isEqual, + +} = Ember; + +export default Ember.Component.extend({ + password: "", + passwordConfirm: "", + mustMatch: false, + passwordEmpty: computed('passwordError', { + get() { + if (this.get('passwordError')) { + return `error`; + } + + return; + } + }), + confirmEmpty: computed('passwordConfirmError', { + get() { + if (this.get('passwordConfirmError')) { + return `error`; + } + + return; + } + }), + + actions: { + reset() { + let password = this.get('password'); + let passwordConfirm = this.get('passwordConfirm'); + + if (isEmpty(password)) { + Ember.set(this, 'passwordError', true); + return $("#newPassword").focus(); + } + + if (isEmpty(passwordConfirm)) { + Ember.set(this, 'passwordConfirmError', true); + return $("#passwordConfirm").focus(); + } + + if (!isEqual(password, passwordConfirm)) { + $("#newPassword").addClass("error").focus(); + $("#passwordConfirm").addClass("error"); + this.set('mustMatch', true); + return; + } + + this.get('reset')(); + } + } +}); diff --git a/app/app/pods/auth/reset/template.hbs b/app/app/pods/auth/reset/template.hbs index 2f26e5fb..78b551bb 100644 --- a/app/app/pods/auth/reset/template.hbs +++ b/app/app/pods/auth/reset/template.hbs @@ -2,23 +2,5 @@ -
-
-
- -
Choose a strong password
- {{focus-input type="password" value=password id="newPassword"}} -
-
- -
Please type your new password again
- {{input type="password" value=passwordConfirm id="passwordConfirm"}} -
-
-
- - Passwords must match -
- -
+ {{password-reset reset=(action 'reset')}}
diff --git a/app/app/services/user.js b/app/app/services/user.js index a8385ee1..28df54e9 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -126,4 +126,4 @@ export default Ember.Service.extend({ data: password }); } -}); \ No newline at end of file +}); diff --git a/app/app/templates/components/password-reset.hbs b/app/app/templates/components/password-reset.hbs new file mode 100644 index 00000000..2f88498a --- /dev/null +++ b/app/app/templates/components/password-reset.hbs @@ -0,0 +1,19 @@ +
+
+
+ +
Choose a strong password
+ {{focus-input type="password" value=password id="newPassword" class=passwordError}} +
+
+ +
Please type your new password again
+ {{input type="password" value=passwordConfirm id="passwordConfirm" class=confirmEmpty}} +
+
+
+ + Passwords must match +
+ +