mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 22:05:44 +01:00
set password from web trilium
This commit is contained in:
@@ -4,21 +4,48 @@ const utils = require('../services/utils');
|
||||
const optionService = require('../services/options');
|
||||
const myScryptService = require('../services/my_scrypt');
|
||||
const log = require('../services/log');
|
||||
const sqlInit = require("../services/sql_init.js");
|
||||
const optionsInitService = require("../services/options_init.js");
|
||||
|
||||
function loginPage(req, res) {
|
||||
res.render('login', { failedAuth: false });
|
||||
}
|
||||
|
||||
function setPasswordPage(req, res) {
|
||||
res.render('set_password', { failed: false });
|
||||
res.render('set_password', { error: false });
|
||||
}
|
||||
|
||||
function setPassword(req, res) {
|
||||
if (sqlInit.isPasswordSet()) {
|
||||
return [400, "Password has been already set"];
|
||||
}
|
||||
|
||||
let {password1, password2} = req.body;
|
||||
password1 = password1.trim();
|
||||
password2 = password2.trim();
|
||||
|
||||
let error;
|
||||
|
||||
if (password1 !== password2) {
|
||||
error = "Entered passwords don't match.";
|
||||
} else if (password1.length < 4) {
|
||||
error = "Password must be at least 4 characters long.";
|
||||
}
|
||||
|
||||
if (error) {
|
||||
res.render('set_password', { error });
|
||||
return;
|
||||
}
|
||||
|
||||
optionsInitService.initPassword(password1);
|
||||
|
||||
res.redirect('login');
|
||||
}
|
||||
|
||||
function login(req, res) {
|
||||
const userName = optionService.getOption('username');
|
||||
|
||||
const guessedPassword = req.body.password;
|
||||
|
||||
if (req.body.username === userName && verifyPassword(guessedPassword)) {
|
||||
if (verifyPassword(guessedPassword)) {
|
||||
const rememberMe = req.body.remember_me;
|
||||
|
||||
req.session.regenerate(() => {
|
||||
@@ -34,7 +61,7 @@ function login(req, res) {
|
||||
}
|
||||
else {
|
||||
// note that logged IP address is usually meaningless since the traffic should come from a reverse proxy
|
||||
log.info(`WARNING: Wrong username / password from ${req.ip}, rejecting.`);
|
||||
log.info(`WARNING: Wrong password from ${req.ip}, rejecting.`);
|
||||
|
||||
res.render('login', {'failedAuth': true});
|
||||
}
|
||||
@@ -60,6 +87,7 @@ function logout(req, res) {
|
||||
module.exports = {
|
||||
loginPage,
|
||||
setPasswordPage,
|
||||
setPassword,
|
||||
login,
|
||||
logout
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user