Permalink
Browse files

6. and log back in again

  • Loading branch information...
cainlevy committed Nov 28, 2016
1 parent 8aa1194 commit 5fa4cd6eeac250358c758d828d04b36c820e7650
Showing with 58 additions and 0 deletions.
  1. +4 −0 app.rb
  2. +31 −0 public/application.js
  3. +4 −0 views/layout.erb
  4. +19 −0 views/login.erb
View
4 app.rb
@@ -48,6 +48,10 @@ def gravatar_url(email, size: 200)
end
end
get '/login' do
erb :login
end
get '/signup' do
erb :signup
end
View
@@ -48,4 +48,35 @@
.then(function () { window.location.href = '/'; });
})
}
/*
* Integrate KeratinAuthN.login
*/
var loginForm = document.querySelector("form#login");
if (loginForm) {
var username = loginForm.querySelector("input#user_email");
var password = loginForm.querySelector("input#user_password");
loginForm.addEventListener('submit', function (event) {
event.preventDefault();
loginForm.querySelectorAll(".has-danger").forEach(function(e) {
e.classList.remove('has-danger');
});
function goHome() {
window.location.href = '/';
}
function showErrors() {
username.parentNode.classList.add("has-danger");
password.parentNode.classList.add("has-danger");
}
KeratinAuthN
.login({ username: username.value, password: password.value })
.then(goHome, showErrors);
})
}
})();
View
@@ -13,6 +13,10 @@
<li class="nav-item">
<a class="btn btn-info" href="#" id="logout">Log Out</a>
</li>
<% else %>
<li class="nav-item">
<a class="btn btn-success" href="/login">Log In</a>
</li>
<% end %>
</ul>
</nav>
View
@@ -0,0 +1,19 @@
<h2>Log In</h2>
<form id="login">
<!-- Email (Username) -->
<div class="form-group">
<label for="user_email" class="form-control-label">Email</label>
<input type="email" id="user_email" name="user[email]" class="form-control" />
</div>
<!-- Password -->
<div class="form-group">
<label for="user_password" class="form-control-label">Password</label>
<input type="password" id="user_password" class="form-control" />
</div>
<button type="submit" class="btn btn-primary">Log In</button>
</form>

0 comments on commit 5fa4cd6

Please sign in to comment.