From ec9de34cb34e333c1b60dbc9c0251a835095fdc6 Mon Sep 17 00:00:00 2001 From: Pitu Date: Mon, 30 Jan 2017 05:43:15 -0300 Subject: [PATCH] Added changePassword --- pages/panel.html | 3 ++- public/js/panel.js | 51 +++++++++++++++++++++++++++++++++++++++++++++- routes/api.js | 1 + 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/pages/panel.html b/pages/panel.html index a0860cc..e23f9b7 100644 --- a/pages/panel.html +++ b/pages/panel.html @@ -53,7 +53,8 @@ diff --git a/public/js/panel.js b/public/js/panel.js index 8337cd4..a231f21 100644 --- a/public/js/panel.js +++ b/public/js/panel.js @@ -463,7 +463,7 @@ panel.getAlbum = function(item){ panel.getUploads(item.id); } -panel.changeTokens = function(){ +panel.changeToken = function(){ axios.get('/api/tokens') .then(function (response) { @@ -526,6 +526,55 @@ panel.getNewToken = function(){ } +panel.changePassword = function(){ + + panel.page.innerHTML = ''; + var container = document.createElement('div'); + container.className = "container"; + container.innerHTML = ` +

Change your password

+ + +

+ + Set new password +

+ `; + + panel.page.appendChild(container); + + document.getElementById('sendChangePassword').addEventListener('click', function(){ + panel.sendNewPassword(); + }); + +} + +panel.sendNewPassword = function(){ + + axios.post('/api/password/change') + .then(function (response) { + + if(response.data.success === false){ + if(response.data.description === 'No token provided') return panel.verifyToken(panel.token); + else return swal("An error ocurred", response.data.description, "error"); + } + + swal({ + title: "Woohoo!", + text: 'Your password was changed successfully.', + type: "success" + }, function(){ + location.reload(); + }) + + }) + .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); + }); + +} + panel.setActiveMenu = function(item){ var menu = document.getElementById('menu'); var items = menu.getElementsByTagName('a'); diff --git a/routes/api.js b/routes/api.js index 07e13f0..5aa10ea 100644 --- a/routes/api.js +++ b/routes/api.js @@ -14,6 +14,7 @@ routes.get ('/check', (req, res, next) => { routes.post ('/login', (req, res, next) => authController.verify(req, res, next)) routes.post ('/register', (req, res, next) => authController.register(req, res, next)) +routes.post ('/password/change', (req, res, next) => authController.changePassword(req, res, next)) routes.get ('/uploads', (req, res, next) => uploadController.list(req, res)) routes.get ('/uploads/:page', (req, res, next) => uploadController.list(req, res))