mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-08 16:30:26 +00:00
parent
02a9fdcd06
commit
1c5648826e
@ -34,7 +34,7 @@ Authenticator.prototype.hashPassword = function(password) {
|
||||
Authenticator.prototype.createSession = function(userId) {
|
||||
var sessionId = crypto.randomBytes(16).toString("hex");
|
||||
// Store the session in your database or in-memory store
|
||||
this.sqlTiddlerDatabase.createOrUpdateUserSession(userId, sessionId);
|
||||
this.sqlTiddlerDatabase.createUserSession(userId, sessionId);
|
||||
return sessionId;
|
||||
};
|
||||
|
||||
|
@ -397,6 +397,7 @@ Server.prototype.authenticateUser = function(request, response) {
|
||||
delete user.password;
|
||||
const userRole = this.sqlTiddlerDatabase.getUserRoles(user.user_id);
|
||||
user['isAdmin'] = userRole?.role_name?.toLowerCase() === 'admin'
|
||||
user['sessionId'] = session_id
|
||||
|
||||
return user
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ SqlTiddlerDatabase.prototype.createTables = function() {
|
||||
session_id TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
last_accessed TEXT NOT NULL,
|
||||
PRIMARY KEY (user_id),
|
||||
PRIMARY KEY (session_id),
|
||||
FOREIGN KEY (user_id) REFERENCES users(user_id)
|
||||
)
|
||||
`,`
|
||||
@ -994,6 +994,20 @@ SqlTiddlerDatabase.prototype.createOrUpdateUserSession = function(userId, sessio
|
||||
return sessionId;
|
||||
};
|
||||
|
||||
SqlTiddlerDatabase.prototype.createUserSession = function(userId, sessionId) {
|
||||
const currentTimestamp = new Date().toISOString();
|
||||
this.engine.runStatement(`
|
||||
INSERT INTO sessions (user_id, session_id, created_at, last_accessed)
|
||||
VALUES ($userId, $sessionId, $timestamp, $timestamp)
|
||||
`, {
|
||||
$userId: userId,
|
||||
$sessionId: sessionId,
|
||||
$timestamp: currentTimestamp
|
||||
});
|
||||
|
||||
return sessionId;
|
||||
};
|
||||
|
||||
SqlTiddlerDatabase.prototype.findUserBySessionId = function(sessionId) {
|
||||
// First, get the user_id from the sessions table
|
||||
const sessionResult = this.engine.runStatementGet(`
|
||||
|
Loading…
Reference in New Issue
Block a user