浏览代码

fix: Fixed socket.io guest authorization + rights

NGPixel 8 年之前
父节点
当前提交
ed0253cd0d
共有 6 个文件被更改,包括 14 次插入10 次删除
  1. 7 1
      server/controllers/ws.js
  2. 4 5
      server/index.js
  3. 0 1
      server/libs/entries.js
  4. 1 1
      server/views/error-forbidden.pug
  5. 1 1
      server/views/error-notexist.pug
  6. 1 1
      server/views/error.pug

+ 7 - 1
server/controllers/ws.js

@@ -1,10 +1,16 @@
 'use strict'
 'use strict'
 
 
+/* global appconfig, rights */
 /* eslint-disable standard/no-callback-literal */
 /* eslint-disable standard/no-callback-literal */
 
 
 const _ = require('lodash')
 const _ = require('lodash')
 
 
 module.exports = (socket) => {
 module.exports = (socket) => {
+  // Check if Guest
+  if (!socket.request.user.logged_in) {
+    socket.request.user = _.assign(rights.guest, socket.request.user)
+  }
+
   // -----------------------------------------
   // -----------------------------------------
   // SEARCH
   // SEARCH
   // -----------------------------------------
   // -----------------------------------------
@@ -22,7 +28,7 @@ module.exports = (socket) => {
   // TREE VIEW (LIST ALL PAGES)
   // TREE VIEW (LIST ALL PAGES)
   // -----------------------------------------
   // -----------------------------------------
 
 
-  if (socket.request.user.logged_in) {
+  if (appconfig.public || socket.request.user.logged_in) {
     socket.on('treeFetch', (data, cb) => {
     socket.on('treeFetch', (data, cb) => {
       cb = cb || _.noop
       cb = cb || _.noop
       entries.getFromTree(data.basePath, socket.request.user).then((f) => {
       entries.getFromTree(data.basePath, socket.request.user).then((f) => {

+ 4 - 5
server/index.js

@@ -92,14 +92,14 @@ require('./libs/auth')(passport)
 global.rights = require('./libs/rights')
 global.rights = require('./libs/rights')
 rights.init()
 rights.init()
 
 
-var sessionStore = new SessionMongoStore({
+let sessionStore = new SessionMongoStore({
   mongooseConnection: db.connection,
   mongooseConnection: db.connection,
   touchAfter: 15
   touchAfter: 15
 })
 })
 
 
 app.use(cookieParser())
 app.use(cookieParser())
 app.use(session({
 app.use(session({
-  name: 'requarkswiki.sid',
+  name: 'wikijs.sid',
   store: sessionStore,
   store: sessionStore,
   secret: appconfig.sessionSecret,
   secret: appconfig.sessionSecret,
   resave: false,
   resave: false,
@@ -221,16 +221,15 @@ server.on('listening', () => {
 // ----------------------------------------
 // ----------------------------------------
 
 
 io.use(passportSocketIo.authorize({
 io.use(passportSocketIo.authorize({
-  key: 'requarkswiki.sid',
+  key: 'wikijs.sid',
   store: sessionStore,
   store: sessionStore,
   secret: appconfig.sessionSecret,
   secret: appconfig.sessionSecret,
-  passport,
   cookieParser,
   cookieParser,
   success: (data, accept) => {
   success: (data, accept) => {
     accept()
     accept()
   },
   },
   fail: (data, message, error, accept) => {
   fail: (data, message, error, accept) => {
-    return accept(new Error(message))
+    accept()
   }
   }
 }))
 }))
 
 

+ 0 - 1
server/libs/entries.js

@@ -399,7 +399,6 @@ module.exports = {
   getFromTree (basePath, usr) {
   getFromTree (basePath, usr) {
     return db.Entry.find({ parentPath: basePath }, 'title parentPath isDirectory isEntry').sort({ title: 'asc' }).then(results => {
     return db.Entry.find({ parentPath: basePath }, 'title parentPath isDirectory isEntry').sort({ title: 'asc' }).then(results => {
       return _.filter(results, r => {
       return _.filter(results, r => {
-        console.log(r._id, rights.checkRole(r._id, usr.rights, 'read'))
         return rights.checkRole('/' + r._id, usr.rights, 'read')
         return rights.checkRole('/' + r._id, usr.rights, 'read')
       })
       })
     })
     })

+ 1 - 1
server/views/error-forbidden.pug

@@ -22,7 +22,7 @@ html(data-logic='error')
 
 
   body(class='is-forbidden')
   body(class='is-forbidden')
     .container
     .container
-      a(href='/'): img(src='/favicons/android-icon-96x96.png')
+      a(href='/'): img(src='/images/logo.png')
       h1 Forbidden
       h1 Forbidden
       h2 Sorry, you don't have the necessary permissions to access this page.
       h2 Sorry, you don't have the necessary permissions to access this page.
       a.button.is-amber.is-inverted(href='/') Go Home
       a.button.is-amber.is-inverted(href='/') Go Home

+ 1 - 1
server/views/error-notexist.pug

@@ -22,7 +22,7 @@ html(data-logic='error')
 
 
   body(class='is-notexist')
   body(class='is-notexist')
     .container
     .container
-      a(href='/'): img(src='/favicons/android-icon-96x96.png')
+      a(href='/'): img(src='/images/logo.png')
       h1= message
       h1= message
       h2 Would you like to create this entry?
       h2 Would you like to create this entry?
       a.button.is-amber.is-inverted.is-featured(href='/create/' + newpath) Create
       a.button.is-amber.is-inverted.is-featured(href='/create/' + newpath) Create

+ 1 - 1
server/views/error.pug

@@ -22,7 +22,7 @@ html(data-logic='error')
 
 
   body(class='is-error')
   body(class='is-error')
     .container
     .container
-      a(href='/'): img(src='/favicons/android-icon-96x96.png')
+      a(href='/'): img(src='/images/logo.png')
       h1= message
       h1= message
       h2 Oops, something went wrong
       h2 Oops, something went wrong
       a.button.is-amber.is-inverted.is-featured(href='/') Go Home
       a.button.is-amber.is-inverted.is-featured(href='/') Go Home