First full release

This commit is contained in:
Luka Romih
2023-03-10 12:50:23 +01:00
parent 257f3c354f
commit 9867875ef2
285 changed files with 10980 additions and 4692 deletions
+10 -5
View File
@@ -29,8 +29,8 @@ passport.deserializeUser(async (id, done) => {
passport.use(
new LocalStrategy(
{ usernameField: 'usernameOrEmail' },
async (usernameOrEmail, password, done) => {
{ passReqToCallback: true, usernameField: 'usernameOrEmail' },
async (req, usernameOrEmail, password, done) => {
try {
const { rows } = await db.query(
'SELECT id, status, bcrypt_hash FROM "user" WHERE username = $1 OR email = $1',
@@ -40,14 +40,17 @@ passport.use(
if (!user) {
return done(null, false, {
message: 'Nepravilno uporabniško ime, elektronski naslov ali geslo.'
message: req.t(
'Nepravilno uporabniško ime, elektronski naslov ali geslo.'
)
})
}
if (user.status !== 'active') {
return done(null, false, {
message:
message: req.t(
'Uporabniški račun še ni aktiviran. Kliknite aktivacijsko povezavo, katero smo vam poslali po elektronski pošti.'
)
})
}
@@ -57,7 +60,9 @@ passport.use(
)
if (!isCorrectPassword) {
return done(null, false, {
message: 'Nepravilno uporabniško ime, elektronski naslov ali geslo.'
message: req.t(
'Nepravilno uporabniško ime, elektronski naslov ali geslo.'
)
})
}
+47
View File
@@ -0,0 +1,47 @@
const i18next = require('i18next')
const i18nextMiddleware = require('i18next-http-middleware')
const i18nextBackend = require('i18next-fs-backend')
// If you change this one, don't forget to also update the nodemon ignore flag in package.json scripts.
const LOCALES_PATH = 'public/locales'
const DEFAULT_LANGUAGE = 'sl'
exports.determineRequestLanguage = (req, res, next) => {
const language =
req.user?.language || req.session.language || DEFAULT_LANGUAGE
req.determinedLanguage = language
res.locals.determinedLanguage = language
next()
}
const customLanguageDetector = {
name: 'ownDetector',
lookup(req) {
return req.determinedLanguage
}
}
const languageDetector = new i18nextMiddleware.LanguageDetector()
languageDetector.addDetector(customLanguageDetector)
const inDevEnv = process.env.NODE_ENV === 'development'
i18next
.use(languageDetector)
.use(i18nextBackend)
.init({
// debug: true,
supportedLngs: ['sl', 'en', 'dev'],
preload: ['sl', 'en'],
ns: ['core', 'extended'],
defaultNS: 'core',
// TODO Reenable separators once keys are refactored (also in frontend init in scripts.js)
nsSeparator: false,
keySeparator: false,
...(inDevEnv && { saveMissing: true }),
...(!inDevEnv && { fallbackLng: false }),
detection: { order: ['ownDetector'] },
backend: {
loadPath: `${LOCALES_PATH}/{{lng}}/{{ns}}.json`,
addPath: `${LOCALES_PATH}/{{lng}}/{{ns}}.json`
}
})
+1
View File
@@ -2,5 +2,6 @@ const { getInstanceSetting } = require('../models/helpers')
exports.enhanceLocals = async (req, res, next) => {
res.locals.portalCode = await getInstanceSetting('portal_code')
next()
}
+20 -2
View File
@@ -14,6 +14,13 @@ user.enhance = (req, res, next) => {
next()
}
user.isAuthenticated = (req, res, next) => {
if (req.isAuthenticated()) return next()
if (req.isAjax) return res.status(400).end()
res.redirect(req.baseUrl || '/')
}
user.isDictionaryAdmin = (req, res, next) => {
const { dictionaryId } = req.params
const isAdmin = req.user.hasDictionaryRole(dictionaryId, 'administration')
@@ -21,7 +28,7 @@ user.isDictionaryAdmin = (req, res, next) => {
if (isAdmin) return next()
if (req.isAjax) return res.status(400).end()
res.redirect(req.baseUrl)
res.redirect(req.baseUrl || '/')
}
user.isDictionaryEditor = (req, res, next) => {
@@ -31,7 +38,18 @@ user.isDictionaryEditor = (req, res, next) => {
if (isEditor) return next()
if (req.isAjax) return res.status(400).end()
res.redirect(req.baseUrl)
res.redirect(req.baseUrl || '/')
}
user.canContentEdit = (req, res, next) => {
const { dictionaryId } = req.params
const isEditor = req.user.hasAnyDictionaryRole(dictionaryId)
const isPortalAdmin = req.user.hasRole('portal admin')
const isDictionariesAdmin = req.user.hasRole('dictionaries admin')
if (isEditor || isPortalAdmin || isDictionariesAdmin) return next()
if (req.isAjax) return res.status(400).end()
res.redirect(req.baseUrl || '/')
}
/**