mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-09 17:21:28 +03:00
Added UI flow for creating default admin account. Dialog will show up after enabling or in the login menu if the admin account isn't present
This commit is contained in:
@@ -2735,6 +2735,16 @@ app.post('/api/auth/jwtAuth'
|
||||
, auth_api.generateJWT
|
||||
, auth_api.returnAuthResponse
|
||||
);
|
||||
app.post('/api/auth/changePassword', optionalJwt, async (req, res) => {
|
||||
let user_uid = req.user.uid;
|
||||
let password = req.body.password;
|
||||
let success = await auth_api.changeUserPassword(user_uid, password);
|
||||
res.send({success: success});
|
||||
});
|
||||
app.post('/api/auth/adminExists', async (req, res) => {
|
||||
let exists = auth_api.adminExists();
|
||||
res.send({exists: exists});
|
||||
});
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
//if the request is not html then move along
|
||||
|
||||
@@ -96,7 +96,8 @@ exports.registerUser = function(req, res) {
|
||||
video: []
|
||||
},
|
||||
subscriptions: [],
|
||||
created: Date.now()
|
||||
created: Date.now(),
|
||||
role: userid === 'admin' ? 'admin' : 'user'
|
||||
};
|
||||
// check if user exists
|
||||
if (users_db.get('users').find({uid: userid}).value()) {
|
||||
@@ -238,6 +239,23 @@ exports.ensureAuthenticatedElseError = function(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
// change password
|
||||
exports.changeUserPassword = async function(user_uid, new_pass) {
|
||||
return new Promise(resolve => {
|
||||
bcrypt.hash(new_pass, saltRounds)
|
||||
.then(function(hash) {
|
||||
users_db.get('users').find({uid: user_uid}).assign({passhash: hash}).write();
|
||||
resolve(true);
|
||||
}).catch(err => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.adminExists = function() {
|
||||
return !!users_db.get('users').find({uid: 'admin'}).value();
|
||||
}
|
||||
|
||||
// video stuff
|
||||
|
||||
exports.getUserVideos = function(user_uid, type) {
|
||||
|
||||
Reference in New Issue
Block a user