Added changePassword

This commit is contained in:
Pitu 2017-01-30 05:43:15 -03:00
parent 0540b0775d
commit ec9de34cb3
3 changed files with 53 additions and 2 deletions

View File

@ -53,7 +53,8 @@
</ul>
<p class="menu-label">Administration</p>
<ul class="menu-list">
<li><a id="itemTokens" onclick="panel.changeTokens()">Change your token</a></li>
<li><a id="itemTokens" onclick="panel.changeToken()">Change your token</a></li>
<li><a id="itemTokens" onclick="panel.changePassword()">Change your password</a></li>
<li><a onclick="panel.logout()">Logout</a></li>
</ul>
</aside>

View File

@ -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 = `
<h2 class="subtitle">Change your password</h2>
<label class="label">New password:</label>
<p class="control has-addons">
<input id="password" class="input is-expanded" type="password" placeholder="Your new password">
<a id="sendChangePassword" class="button is-primary">Set new password</a>
</p>
`;
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');

View File

@ -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))