2019-05-09 18:54:39 +12:00
|
|
|
// Init
|
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
window.ls.error = function () {
|
|
|
|
return function (error) {
|
2020-06-04 23:20:30 +12:00
|
|
|
window.console.error(error);
|
2020-06-07 02:04:18 +12:00
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
if (window.location.pathname !== '/console') {
|
2020-06-07 02:04:18 +12:00
|
|
|
window.location = '/console';
|
|
|
|
}
|
2019-09-13 22:47:07 +12:00
|
|
|
};
|
2019-05-09 18:54:39 +12:00
|
|
|
};
|
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
window.addEventListener("error", function (event) {
|
2019-09-13 22:47:07 +12:00
|
|
|
console.error("ERROR-EVENT:", event.error.message, event.error.stack);
|
2019-05-09 18:54:39 +12:00
|
|
|
});
|
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
document.addEventListener("account.deleteSession", function () {
|
2019-09-13 22:47:07 +12:00
|
|
|
window.location = "/auth/signin";
|
2020-02-13 21:04:52 +13:00
|
|
|
});
|
|
|
|
|
2021-05-14 00:37:54 +12:00
|
|
|
document.addEventListener("account.create", function () {
|
2020-02-13 21:04:52 +13:00
|
|
|
let container = window.ls.container;
|
|
|
|
let form = container.get('serviceForm');
|
|
|
|
let sdk = container.get('console');
|
|
|
|
|
|
|
|
let promise = sdk.account.createSession(form.email, form.password);
|
|
|
|
|
2020-02-18 18:25:28 +13:00
|
|
|
container.set("serviceForm", {}, true, true); // Remove sensetive data when not needed
|
2021-05-14 01:16:30 +12:00
|
|
|
|
2020-02-13 21:04:52 +13:00
|
|
|
promise.then(function () {
|
2021-05-14 00:37:54 +12:00
|
|
|
var subscribe = document.getElementById('newsletter').checked;
|
|
|
|
if (subscribe) {
|
2021-05-14 01:16:30 +12:00
|
|
|
let alerts = container.get('alerts');
|
|
|
|
let loaderId = alerts.add({ text: 'Loading...', class: "" }, 0);
|
2021-05-14 00:37:54 +12:00
|
|
|
fetch('https://appwrite.io/v1/newsletter/subscribe', {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
name: form.name,
|
|
|
|
email: form.email,
|
|
|
|
}),
|
|
|
|
}).finally(function () {
|
2021-05-14 01:16:30 +12:00
|
|
|
alerts.remove(loaderId);
|
2021-05-14 00:37:54 +12:00
|
|
|
window.location = '/console';
|
|
|
|
});
|
|
|
|
} else {
|
2020-02-13 21:04:52 +13:00
|
|
|
window.location = '/console';
|
2021-05-14 00:37:54 +12:00
|
|
|
}
|
|
|
|
}, function (error) {
|
|
|
|
window.location = '/auth/signup?failure=1';
|
2020-02-13 21:04:52 +13:00
|
|
|
});
|
2020-02-04 08:20:10 +13:00
|
|
|
});
|