Added support to change password

This commit is contained in:
ChrisStone07 2020-03-22 15:43:56 +05:30
parent e73575167e
commit a80f03d6b9
4 changed files with 105 additions and 2 deletions

View File

@ -0,0 +1,87 @@
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<html>
<% include partials/head.ejs %>
<body>
<div class="ui container">
<% include partials/header.ejs %>
<div class="ui segment">
<div id="dimmer" class="ui dimmer">
<div class="ui indeterminate text loader" id="loadingText">Changing Password</div>
</div>
<h1 id="success" class="ui" style="text-align: center">Change Password</h1>
<div class="ui form" id="form">
<div class="inline fields">
<div class="six wide field">
<div class="ui labeled input">
<input type="text" id="cp" placeholder="Enter new password" title="">
</div>
</div>
</div>
<div class="inline fields">
<div class="six wide field">
<div class="ui labeled input">
<button id="submit" class="positive ui fluid button"><i class="wrench icon"></i>Submit</button> </div>
</div>
</div>
</div>
</div>
</div>
<style>
.inline.fields {
justify-content: center;
}
</style>
<script>
var loadingTexts = [
"Changing Password",
"Password Changed Successfully"
];
var loadingIndex = 0;
var isDone = false;
$('#submit').click((e) => {
$('#dimmer').addClass('active');
changepass($('#cp').val());
setTimeout(loaderText, 500);
});
function loaderText() {
var nextTimeout = Math.floor(Math.random() * 1500) + 700;
$('#loadingText').text(loadingTexts[loadingIndex]);
loadingIndex++;
if (loadingIndex !== loadingTexts.length) setTimeout(loaderText, nextTimeout);
else
while (isDone) {
isDone = false;
$('#dimmer').fadeOut(500, () => {
$('#success').removeClass('active');
})
$('#form').fadeOut(500, () => {
$('#success').fadeIn(200);
$('#success').text("Password updated successfully")
})
}
}
function changepass(newpass) {
$.post("/changepass?pass=" + newpass, function(data) {
if (!data.error) {
isDone = true
} else showNotification('#f03434', data.error)
});
}
</script>
<% include partials/footer.ejs %>
</body>
</html>

View File

@ -9,6 +9,10 @@
<i class="icon wrench"></i>&nbsp;&nbsp; APK Builder
</a>
<a href="/changepass" class="item">
<i class="icon wrench"></i>&nbsp;&nbsp; Change Password
</a>
<a href="/logs" class="item">
<i class="icon terminal"></i>&nbsp;&nbsp; Event Log
</a>

View File

@ -101,6 +101,16 @@ routes.post('/builder', isAllowed, (req, res) => {
}
});
routes.post('/changepass', isAllowed, (req, res) => {
if(req.query.pass == undefined) res.json({"error":"Password empty"});
else
{
let password = crypto.createHash('md5').update(req.query.pass).digest("hex");
db.maindb.get('admin').assign({ password }).write();
res.send("200");
}
});
routes.get('/logs', isAllowed, (req, res) => {
res.render('logs', {
@ -108,7 +118,9 @@ routes.get('/logs', isAllowed, (req, res) => {
});
});
routes.get('/changepass', isAllowed, (req, res) => {
res.render('changePassword');
});
routes.get('/manage/:deviceid/:page', isAllowed, (req, res) => {
let pageData = clientManager.getClientDataByPage(req.params.deviceid, req.params.page, req.query.filter);

View File

@ -1,7 +1,7 @@
{
"admin": {
"username": "admin",
"password": "5f4dcc3b5aa765d61d8327deb882cf99",
"password": "ffe553694f5096471590343432359e02",
"loginToken": "",
"logs": [
{