Skip to content

Commit

Permalink
Swap out landing form errors #12, move login form into a template so …
Browse files Browse the repository at this point in the history
…we can reuse it in the signup modal
  • Loading branch information
erasaur committed Apr 28, 2015
1 parent 07127bc commit 2620cec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
21 changes: 14 additions & 7 deletions client/views/login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
<div class="landing-form-header">
<h1 class="logo"><a href="{{pathFor route='landing'}}">binary</a></h1>
</div>
<ul class="landing-form-errors"></ul>
<div class="landing-form-body">
<form id="js-login-form" class="stacked-form" role="form">
<input type="text" class="form-control" id="js-email" placeholder="{{_ 'email'}}">
<input type="password" class="form-control" id="js-password" placeholder="{{_ 'password'}}">
<button type="submit" class="btn btn-primary">{{_ "login"}}</button>
</form>
<a href="{{pathFor route='forgotPassword'}}" class="action-link">{{_ "forgot_password"}}</a>
{{> loginForm}}

<ul>
<li><a href="{{pathFor route='signup'}}" class="action-link">{{_ "dont_have_account"}}</a></li>
<li><a href="{{pathFor route='forgotPassword'}}" class="action-link">{{_ "forgot_password"}}</a></li>
</ul>
</div>
</div>
</template>

<template name="loginForm">
<form id="js-login-form" class="stacked-form" role="form">
<input type="text" class="form-control" id="js-email" placeholder="{{_ 'email'}}">
<input type="password" class="form-control" id="js-password" placeholder="{{_ 'password'}}">
<button type="submit" class="btn btn-primary">{{_ "login"}}</button>
</form>
</template>
16 changes: 3 additions & 13 deletions client/views/login/login.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
Template.login.events({
'input input': function (event, template) {
fadeElement(template.$('.landing-form-errors'));
},
Template.loginForm.events({
'submit #js-login-form': function (event, template) {
event.preventDefault();
var email = template.find('#js-email').value;
var password = template.find('#js-password').value;
var $errors = template.$('.landing-form-errors');

function showError (message) {
$errors
.html('<li>' + message + '</li>')
.velocity('fadeIn', { duration: 1000 });
}

if (!email || !password) {
showError(i18n.t('missing_fields'));
toastr.warning(i18n.t('missing_fields'));
return;
}

Meteor.loginWithPassword(email, password, function (error) {
if (error) {
showError(i18n.t('login_error'));
toastr.warning(i18n.t('login_error'));
}
});
}
Expand Down

0 comments on commit 2620cec

Please sign in to comment.