aboutsummaryrefslogtreecommitdiff
path: root/public/js/auth.js
diff options
context:
space:
mode:
authorPitu <[email protected]>2017-01-30 05:13:07 -0300
committerPitu <[email protected]>2017-01-30 05:13:07 -0300
commit6b7fd3bcf431fd6df9059c83a34f5a15b00fd7b2 (patch)
treead6efa64785c0862d2c8cf8df2a980580c3a4703 /public/js/auth.js
parentRemoved unused dependency (diff)
parentBumped version (diff)
downloadhost.fuwn.me-6b7fd3bcf431fd6df9059c83a34f5a15b00fd7b2.tar.xz
host.fuwn.me-6b7fd3bcf431fd6df9059c83a34f5a15b00fd7b2.zip
Merged dev into master
Diffstat (limited to 'public/js/auth.js')
-rw-r--r--public/js/auth.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/public/js/auth.js b/public/js/auth.js
new file mode 100644
index 0000000..68cf9e3
--- /dev/null
+++ b/public/js/auth.js
@@ -0,0 +1,56 @@
+var page = {};
+
+page.do = function(dest){
+
+ var user = document.getElementById('user').value;
+ var pass = document.getElementById('pass').value;
+
+ if(user === undefined || user === null || user === '')
+ return swal('Error', 'You need to specify a username', 'error');
+ if(pass === undefined || pass === null || pass === '')
+ return swal('Error', 'You need to specify a username', 'error');
+
+ axios.post('/api/' + dest, {
+ username: user,
+ password: pass
+ })
+ .then(function (response) {
+
+ if(response.data.success === false)
+ return swal('Error', response.data.description, 'error');
+
+ localStorage.token = response.data.token;
+ window.location = '/panel';
+
+ })
+ .catch(function (error) {
+ return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
+ console.log(error);
+ });
+}
+
+page.verify = function(){
+ page.token = localStorage.token;
+ if(page.token === undefined) return;
+
+ axios.post('/api/tokens/verify', {
+ token: page.token
+ })
+ .then(function (response) {
+
+ if(response.data.success === false)
+ return swal('Error', response.data.description, 'error');
+
+ window.location = '/panel';
+
+ })
+ .catch(function (error) {
+ return swal('An error ocurred', 'There was an error with the request, please check the console for more information.', 'error');
+ console.log(error);
+ });
+
+}
+
+window.onload = function () {
+ page.verify();
+} \ No newline at end of file