refactor: global namespace + admin pages UI
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* global wiki */
|
||||
/* global WIKI */
|
||||
|
||||
const Promise = require('bluebird')
|
||||
const express = require('express')
|
||||
@@ -12,7 +12,7 @@ const _ = require('lodash')
|
||||
* Setup Express-Brute
|
||||
*/
|
||||
const EBstore = new ExpressBruteRedisStore({
|
||||
client: wiki.redis
|
||||
client: WIKI.redis
|
||||
})
|
||||
const bruteforce = new ExpressBrute(EBstore, {
|
||||
freeRetries: 5,
|
||||
@@ -22,8 +22,8 @@ const bruteforce = new ExpressBrute(EBstore, {
|
||||
failCallback (req, res, next, nextValidRequestDate) {
|
||||
req.flash('alert', {
|
||||
class: 'error',
|
||||
title: wiki.lang.t('auth:errors.toomanyattempts'),
|
||||
message: wiki.lang.t('auth:errors.toomanyattemptsmsg', { time: moment(nextValidRequestDate).fromNow() }),
|
||||
title: WIKI.lang.t('auth:errors.toomanyattempts'),
|
||||
message: WIKI.lang.t('auth:errors.toomanyattemptsmsg', { time: moment(nextValidRequestDate).fromNow() }),
|
||||
iconClass: 'fa-times'
|
||||
})
|
||||
res.redirect('/login')
|
||||
@@ -40,16 +40,16 @@ router.get('/login', function (req, res, next) {
|
||||
router.post('/login', bruteforce.prevent, function (req, res, next) {
|
||||
new Promise((resolve, reject) => {
|
||||
// [1] LOCAL AUTHENTICATION
|
||||
wiki.auth.passport.authenticate('local', function (err, user, info) {
|
||||
WIKI.auth.passport.authenticate('local', function (err, user, info) {
|
||||
if (err) { return reject(err) }
|
||||
if (!user) { return reject(new Error('INVALID_LOGIN')) }
|
||||
resolve(user)
|
||||
})(req, res, next)
|
||||
}).catch({ message: 'INVALID_LOGIN' }, err => {
|
||||
if (_.has(wiki.config.auth.strategy, 'ldap')) {
|
||||
if (_.has(WIKI.config.auth.strategy, 'ldap')) {
|
||||
// [2] LDAP AUTHENTICATION
|
||||
return new Promise((resolve, reject) => {
|
||||
wiki.auth.passport.authenticate('ldapauth', function (err, user, info) {
|
||||
WIKI.auth.passport.authenticate('ldapauth', function (err, user, info) {
|
||||
if (err) { return reject(err) }
|
||||
if (info && info.message) { return reject(new Error(info.message)) }
|
||||
if (!user) { return reject(new Error('INVALID_LOGIN')) }
|
||||
@@ -71,13 +71,13 @@ router.post('/login', bruteforce.prevent, function (req, res, next) {
|
||||
// LOGIN FAIL
|
||||
if (err.message === 'INVALID_LOGIN') {
|
||||
req.flash('alert', {
|
||||
title: wiki.lang.t('auth:errors.invalidlogin'),
|
||||
message: wiki.lang.t('auth:errors.invalidloginmsg')
|
||||
title: WIKI.lang.t('auth:errors.invalidlogin'),
|
||||
message: WIKI.lang.t('auth:errors.invalidloginmsg')
|
||||
})
|
||||
return res.redirect('/login')
|
||||
} else {
|
||||
req.flash('alert', {
|
||||
title: wiki.lang.t('auth:errors.loginerror'),
|
||||
title: WIKI.lang.t('auth:errors.loginerror'),
|
||||
message: err.message
|
||||
})
|
||||
return res.redirect('/login')
|
||||
@@ -89,19 +89,19 @@ router.post('/login', bruteforce.prevent, function (req, res, next) {
|
||||
* Social Login
|
||||
*/
|
||||
|
||||
router.get('/login/ms', wiki.auth.passport.authenticate('windowslive', { scope: ['wl.signin', 'wl.basic', 'wl.emails'] }))
|
||||
router.get('/login/google', wiki.auth.passport.authenticate('google', { scope: ['profile', 'email'] }))
|
||||
router.get('/login/facebook', wiki.auth.passport.authenticate('facebook', { scope: ['public_profile', 'email'] }))
|
||||
router.get('/login/github', wiki.auth.passport.authenticate('github', { scope: ['user:email'] }))
|
||||
router.get('/login/slack', wiki.auth.passport.authenticate('slack', { scope: ['identity.basic', 'identity.email'] }))
|
||||
router.get('/login/azure', wiki.auth.passport.authenticate('azure_ad_oauth2'))
|
||||
router.get('/login/ms', WIKI.auth.passport.authenticate('windowslive', { scope: ['wl.signin', 'wl.basic', 'wl.emails'] }))
|
||||
router.get('/login/google', WIKI.auth.passport.authenticate('google', { scope: ['profile', 'email'] }))
|
||||
router.get('/login/facebook', WIKI.auth.passport.authenticate('facebook', { scope: ['public_profile', 'email'] }))
|
||||
router.get('/login/github', WIKI.auth.passport.authenticate('github', { scope: ['user:email'] }))
|
||||
router.get('/login/slack', WIKI.auth.passport.authenticate('slack', { scope: ['identity.basic', 'identity.email'] }))
|
||||
router.get('/login/azure', WIKI.auth.passport.authenticate('azure_ad_oauth2'))
|
||||
|
||||
router.get('/login/ms/callback', wiki.auth.passport.authenticate('windowslive', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/google/callback', wiki.auth.passport.authenticate('google', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/facebook/callback', wiki.auth.passport.authenticate('facebook', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/github/callback', wiki.auth.passport.authenticate('github', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/slack/callback', wiki.auth.passport.authenticate('slack', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/azure/callback', wiki.auth.passport.authenticate('azure_ad_oauth2', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/ms/callback', WIKI.auth.passport.authenticate('windowslive', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/google/callback', WIKI.auth.passport.authenticate('google', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/facebook/callback', WIKI.auth.passport.authenticate('facebook', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/github/callback', WIKI.auth.passport.authenticate('github', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/slack/callback', WIKI.auth.passport.authenticate('slack', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
router.get('/login/azure/callback', WIKI.auth.passport.authenticate('azure_ad_oauth2', { failureRedirect: '/login', successRedirect: '/' }))
|
||||
|
||||
/**
|
||||
* Logout
|
||||
|
Reference in New Issue
Block a user