Signin Validation

closes #3120
- create `validateAndAuthenticate` action to validate, send `authenticate` action on success, notifications on error
- signin template uses `validateAndAuthenticate` action instead of `authenticate` action
This commit is contained in:
David Arvelo 2014-06-30 16:07:30 -04:00
parent 087c483498
commit a7f1173f93
2 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,21 @@
var SigninController = Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin, {
import ValidationEngine from 'ghost/mixins/validation-engine';
var SigninController = Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin, ValidationEngine, {
authenticatorFactory: 'ember-simple-auth-authenticator:oauth2-password-grant',
validationType: 'signin',
actions: {
validateAndAuthenticate: function () {
var self = this;
this.validate({ format: false }).then(function () {
self.send('authenticate');
}).catch(function (errors) {
self.notifications.showErrors(errors);
});
}
}
});
export default SigninController;

View File

@ -1,12 +1,12 @@
<section class="login-box js-login-box fade-in">
<form id="login" class="login-form" method="post" novalidate="novalidate" {{action 'authenticate' on='submit'}}>
<form id="login" class="login-form" method="post" novalidate="novalidate" {{action 'validateAndAuthenticate' on='submit'}}>
<div class="email-wrap">
{{input class="email" type="email" placeholder="Email Address" name="identification" autofocus="autofocus" autocapitalize="off" autocorrect="off" value=identification}}
</div>
<div class="password-wrap">
{{input class="password" type="password" placeholder="Password" name="password" value=password}}
</div>
<button class="button-save" type="submit" {{action "authenticate"}} {{bind-attr disabled=submitting}}>Log in</button>
<button class="button-save" type="submit" {{action "validateAndAuthenticate"}} {{bind-attr disabled=submitting}}>Log in</button>
<section class="meta">
{{#link-to 'forgotten' class="forgotten-password"}}Forgotten password?{{/link-to}}
</section>