1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00
appwrite/public/scripts/init.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

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-05-09 18:54:39 +12:00
};
2021-05-14 00:37:54 +12:00
window.addEventListener("error", function (event) {
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 () {
window.location = "/auth/signin";
});
2021-05-14 00:37:54 +12:00
document.addEventListener("account.create", function () {
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
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 {
window.location = '/console';
2021-05-14 00:37:54 +12:00
}
}, function (error) {
window.location = '/auth/signup?failure=1';
});
2020-02-04 08:20:10 +13:00
});