403Webshell
Server IP : 167.235.67.158  /  Your IP : 216.73.216.179
Web Server : Apache
System : Linux ubuntu-8gb-nbg1-1 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64
User : upstairsbar.co.uk ( 982)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/api.pda.the-word.com/auth/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/api.pda.the-word.com/auth/service.js
const authHelpers = require('../common/auth');
const helpers = require('../common/helpers');
const { callLegacy } = require('../common/legacyClient');
const { insertRow, queryDatabase } = require('../common/sqlDB');

function mapUserRow(row) {
  return {
    id: Number(row.ID),
    name: row.Name || '',
    credits: Number(row.Credits || 0),
    settings: row.Settings || '',
    role: Number(row.Role || 0),
    reminderTimer: Number(row.ReminderTimer || 1),
    workingHours: row.WorkingHours || ''
  };
}

async function getUserById(userId) {
  const rows = await queryDatabase(
    `SELECT ID, Name, Credits, Settings, Role, ReminderTimer, WorkingHours
     FROM Users
     WHERE ID = ? AND Deleted = 0
     LIMIT 1`,
    [userId]
  );

  if (!rows.length) {
    const error = new Error('User not found.');
    error.statusCode = 404;
    throw error;
  }

  return mapUserRow(rows[0]);
}

async function issueSession(user) {
  const sessionToken = authHelpers.generateSessionToken();

  await insertRow('api_user_tokens', {
    user_id: user.id,
    token_hash: authHelpers.sha256(sessionToken)
  });

  return {
    sessionToken,
    user
  };
}

async function login(body) {
  helpers.requireFields(body, ['email', 'password']);

  const legacyResult = await callLegacy('login', {
    email: body.email,
    password: body.password
  });

  if (!legacyResult || legacyResult.result !== true) {
    const error = new Error(legacyResult?.message || 'Invalid credentials.');
    error.statusCode = 401;
    throw error;
  }

  const user = await getUserById(legacyResult.id);
  return issueSession(user);
}

async function logout(sessionToken) {
  await authHelpers.revokeSessionToken(sessionToken);
  return {
    success: true
  };
}

module.exports = {
  getUserById,
  login,
  logout
};

Youez - 2016 - github.com/yon3zu
LinuXploit