mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 19:36:12 +01:00
token auth to /login
This commit is contained in:
@@ -1,33 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
const imageService = require('../../services/image');
|
||||
const utils = require('../../services/utils');
|
||||
const dateNoteService = require('../../services/date_notes');
|
||||
const sql = require('../../services/sql');
|
||||
const noteService = require('../../services/notes');
|
||||
const passwordEncryptionService = require('../../services/password_encryption');
|
||||
const optionService = require('../../services/options');
|
||||
const ApiToken = require('../../entities/api_token');
|
||||
|
||||
async function login(req) {
|
||||
const username = req.body.username;
|
||||
const password = req.body.password;
|
||||
|
||||
const isUsernameValid = username === await optionService.getOption('username');
|
||||
const isPasswordValid = await passwordEncryptionService.verifyPassword(password);
|
||||
|
||||
if (!isUsernameValid || !isPasswordValid) {
|
||||
return [401, "Incorrect username/password"];
|
||||
}
|
||||
|
||||
const apiToken = await new ApiToken({
|
||||
token: utils.randomSecureToken()
|
||||
}).save();
|
||||
|
||||
return {
|
||||
token: apiToken.token
|
||||
};
|
||||
}
|
||||
|
||||
async function uploadImage(req) {
|
||||
const file = req.file;
|
||||
@@ -64,7 +39,6 @@ async function saveNote(req) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
login,
|
||||
uploadImage,
|
||||
saveNote
|
||||
};
|
||||
Reference in New Issue
Block a user