diff --git a/assets/js/auth.js b/assets/js/auth.js index f41d421..88aa60d 100644 --- a/assets/js/auth.js +++ b/assets/js/auth.js @@ -11,16 +11,44 @@ function postAjax(url, data, success) { return xhr; } +function showErrorPopup(errorText) { + console.log(errorText) +} + function login() { var xhr = postAjax('/api/v1/login', { email: document.getElementById('email_input').value, password: document.getElementById('password_input').value }); xhr.onload = function () { - console.log(xhr.responseText); + if (xhr.responseText.charAt(0) !== "{") { + return showErrorPopup('Whoops, something went wrong. Try again later.'); + } response = JSON.parse(xhr.responseText); if (response.success === true) { location.pathname = '/pnid/dashboard'; + } else if (response.errors) { + showErrorPopup(response.errors); + } + } +} + +function register() { + var xhr = postAjax('/api/v1/register', { + email: document.getElementById('email_input').value, + username: document.getElementById('username_input').value, + password: document.getElementById('password_input').value, + confirm_password: document.getElementById('password_confirm_input').value + }); + xhr.onload = function () { + if (xhr.responseText.charAt(0) !== "{") { + return showErrorPopup('Whoops, something went wrong. Try again later.'); + } + response = JSON.parse(xhr.responseText); + if (response.success === true) { + login(); + } else if (response.errors) { + showErrorPopup(response.errors); } } } \ No newline at end of file diff --git a/views/login.hbs b/views/login.hbs index ec66a79..21b6c76 100644 --- a/views/login.hbs +++ b/views/login.hbs @@ -12,13 +12,13 @@

ERROR

{{ locale.login.card.title }}

-
+
- +

ERROR ERROR

diff --git a/views/register.hbs b/views/register.hbs index b380170..20efab8 100644 --- a/views/register.hbs +++ b/views/register.hbs @@ -14,7 +14,7 @@

{{ locale.register.card.caption }}

{{ locale.register.card.title }}

-
+ @@ -25,9 +25,8 @@
- -
+

ERROR ERROR