feat: 🎸 Fix import naming

This commit is contained in:
Jin 2025-03-26 02:04:24 +01:00
parent 4762287d61
commit d4b657e4d8
2 changed files with 17 additions and 13 deletions

View File

@ -7,18 +7,17 @@ import assetPath from "../services/asset_path.js";
import appPath from "../services/app_path.js"; import appPath from "../services/app_path.js";
import ValidationError from "../errors/validation_error.js"; import ValidationError from "../errors/validation_error.js";
import type { Request, Response } from 'express'; import type { Request, Response } from 'express';
import recoveryCodeService from '../services/encryption/recovery_codes.js';
import openIDService from '../services/open_id.js';
import openIDEncryption from '../services/encryption/open_id_encryption.js';
import totp from '../services/totp.js'; import totp from '../services/totp.js';
import open_id from '../services/open_id.js'; import recoveryCodeService from '../services/encryption/recovery_codes.js';
import openID from '../services/open_id.js';
import openIDEncryption from '../services/encryption/open_id_encryption.js';
function loginPage(req: Request, res: Response) { function loginPage(req: Request, res: Response) {
res.render('login', { res.render('login', {
wrongPassword: false, wrongPassword: false,
wrongTotp: false, wrongTotp: false,
totpEnabled: totp.isTotpEnabled(), totpEnabled: totp.isTotpEnabled(),
ssoEnabled: open_id.isOpenIDEnabled(), ssoEnabled: openID.isOpenIDEnabled(),
assetPath: assetPath, assetPath: assetPath,
appPath: appPath, appPath: appPath,
}); });
@ -64,6 +63,11 @@ function setPassword(req: Request, res: Response) {
} }
function login(req: Request, res: Response) { function login(req: Request, res: Response) {
if (openID.isOpenIDEnabled()) {
res.oidc.login({ returnTo: '/' });
return;
}
const submittedPassword = req.body.password; const submittedPassword = req.body.password;
const submittedTotpToken = req.body.totpToken; const submittedTotpToken = req.body.totpToken;
@ -92,7 +96,7 @@ function login(req: Request, res: Response) {
req.session.lastAuthState = { req.session.lastAuthState = {
totpEnabled: totp.isTotpEnabled(), totpEnabled: totp.isTotpEnabled(),
ssoEnabled: open_id.isOpenIDEnabled() ssoEnabled: openID.isOpenIDEnabled()
}; };
req.session.loggedIn = true; req.session.loggedIn = true;
@ -128,7 +132,7 @@ function sendLoginError(req: Request, res: Response, errorType: 'password' | 'to
wrongPassword: errorType === 'password', wrongPassword: errorType === 'password',
wrongTotp: errorType === 'totp', wrongTotp: errorType === 'totp',
totpEnabled: totp.isTotpEnabled(), totpEnabled: totp.isTotpEnabled(),
ssoEnabled: open_id.isOpenIDEnabled(), ssoEnabled: openID.isOpenIDEnabled(),
assetPath: assetPath, assetPath: assetPath,
appPath: appPath, appPath: appPath,
}); });
@ -138,7 +142,7 @@ function logout(req: Request, res: Response) {
req.session.regenerate(() => { req.session.regenerate(() => {
req.session.loggedIn = false; req.session.loggedIn = false;
if (openIDService.isOpenIDEnabled() && openIDEncryption.isSubjectIdentifierSaved()) { if (openID.isOpenIDEnabled() && openIDEncryption.isSubjectIdentifierSaved()) {
res.oidc.logout({ returnTo: '/authenticate' }); res.oidc.logout({ returnTo: '/authenticate' });
} else res.redirect('login'); } else res.redirect('login');

View File

@ -6,8 +6,8 @@ import passwordEncryptionService from "./encryption/password_encryption.js";
import config from "./config.js"; import config from "./config.js";
import passwordService from "./encryption/password.js"; import passwordService from "./encryption/password.js";
import totp from "./totp.js"; import totp from "./totp.js";
import open_id from "./open_id.js"; import openID from "./open_id.js";
import open_id_encryption from './encryption/open_id_encryption.js'; import openIDEncryption from './encryption/open_id_encryption.js';
import options from "./options.js"; import options from "./options.js";
import attributes from "./attributes.js"; import attributes from "./attributes.js";
import type { NextFunction, Request, Response } from "express"; import type { NextFunction, Request, Response } from "express";
@ -16,7 +16,7 @@ const noAuthentication = config.General && config.General.noAuthentication === t
function checkAuth(req: Request, res: Response, next: NextFunction) { function checkAuth(req: Request, res: Response, next: NextFunction) {
const currentTotpStatus = totp.isTotpEnabled(); const currentTotpStatus = totp.isTotpEnabled();
const currentSsoStatus = open_id.isOpenIDEnabled(); const currentSsoStatus = openID.isOpenIDEnabled();
const lastAuthState = req.session.lastAuthState || { totpEnabled: false, ssoEnabled: false }; const lastAuthState = req.session.lastAuthState || { totpEnabled: false, ssoEnabled: false };
if (!sqlInit.isDbInitialized()) { if (!sqlInit.isDbInitialized()) {
@ -27,10 +27,10 @@ function checkAuth(req: Request, res: Response, next: NextFunction) {
res.redirect('/login'); res.redirect('/login');
}); });
return; return;
} else if (open_id.isOpenIDEnabled()) { } else if (openID.isOpenIDEnabled()) {
if ( if (
req.oidc.isAuthenticated() && req.oidc.isAuthenticated() &&
open_id_encryption.verifyOpenIDSubjectIdentifier(req.oidc.user?.sub) openIDEncryption.verifyOpenIDSubjectIdentifier(req.oidc.user?.sub)
) { ) {
req.session.loggedIn = true; req.session.loggedIn = true;
next(); next();