login.js 909 B

123456789101112131415161718192021222324252627282930313233
  1. var message = document.getElementById("message");
  2. //message.style.visibility = "hidden";
  3. var loginSubmit = function() {
  4. message.style.visibility = "hidden";
  5. var username = document.getElementById('username').value;
  6. var password = document.getElementById('password').value;
  7. var promise = ajaxPost("/api/login", {"username": username, "password": password });
  8. promise.success = function(response) {
  9. if(response.error) {
  10. message.innerHTML = response.error;
  11. message.style.visibility = "visible";
  12. } else {
  13. window.location = "/dashboard/";
  14. }
  15. };
  16. promise.failure = function(response) {
  17. console.warn("Communication failure", response);
  18. }
  19. };
  20. var loginButton = document.getElementById("login");
  21. loginButton.addEventListener('click', loginSubmit, false);
  22. window.addEventListener("keypress", function(event) {
  23. var keyCode = event.which;
  24. if (keyCode == 13) {
  25. loginSubmit();
  26. }
  27. }, false);