parse-dashboard 5.2.0-beta.2 → 5.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
- var bcrypt = require('bcryptjs');
3
- var csrf = require('csurf');
4
- var passport = require('passport');
5
- var LocalStrategy = require('passport-local').Strategy;
2
+ const bcrypt = require('bcryptjs');
3
+ const csrf = require('csurf');
4
+ const passport = require('passport');
5
+ const LocalStrategy = require('passport-local').Strategy;
6
6
  const OTPAuth = require('otpauth')
7
7
 
8
8
  /**
@@ -20,11 +20,11 @@ function Authentication(validUsers, useEncryptedPasswords, mountPath) {
20
20
 
21
21
  function initialize(app, options) {
22
22
  options = options || {};
23
- var self = this;
23
+ const self = this;
24
24
  passport.use('local', new LocalStrategy(
25
25
  {passReqToCallback:true},
26
26
  function(req, username, password, cb) {
27
- var match = self.authenticate({
27
+ const match = self.authenticate({
28
28
  name: username,
29
29
  pass: password,
30
30
  otpCode: req.body.otpCode
@@ -47,13 +47,13 @@ function initialize(app, options) {
47
47
  });
48
48
 
49
49
  passport.deserializeUser(function(username, cb) {
50
- var user = self.authenticate({
50
+ const user = self.authenticate({
51
51
  name: username
52
52
  }, true);
53
53
  cb(null, user);
54
54
  });
55
55
 
56
- var cookieSessionSecret = options.cookieSessionSecret || require('crypto').randomBytes(64).toString('hex');
56
+ const cookieSessionSecret = options.cookieSessionSecret || require('crypto').randomBytes(64).toString('hex');
57
57
  const cookieSessionMaxAge = options.cookieSessionMaxAge;
58
58
  app.use(require('connect-flash')());
59
59
  app.use(require('body-parser').urlencoded({ extended: true }));
@@ -67,16 +67,16 @@ function initialize(app, options) {
67
67
 
68
68
  app.post('/login',
69
69
  csrf(),
70
- (req,res,next) => {
71
- let redirect = 'apps';
72
- if (req.body.redirect) {
73
- redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect
74
- }
75
- return passport.authenticate('local', {
76
- successRedirect: `${self.mountPath}${redirect}`,
77
- failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`,
78
- failureFlash : true
79
- })(req, res, next)
70
+ (req,res,next) => {
71
+ let redirect = 'apps';
72
+ if (req.body.redirect) {
73
+ redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect
74
+ }
75
+ return passport.authenticate('local', {
76
+ successRedirect: `${self.mountPath}${redirect}`,
77
+ failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`,
78
+ failureFlash : true
79
+ })(req, res, next)
80
80
  },
81
81
  );
82
82
 
@@ -100,13 +100,13 @@ function authenticate(userToTest, usernameOnly) {
100
100
  let otpValid = true;
101
101
 
102
102
  //they provided auth
103
- let isAuthenticated = userToTest &&
103
+ const isAuthenticated = userToTest &&
104
104
  //there are configured users
105
105
  this.validUsers &&
106
106
  //the provided auth matches one of the users
107
107
  this.validUsers.find(user => {
108
108
  let isAuthenticated = false;
109
- let usernameMatches = userToTest.name == user.user;
109
+ const usernameMatches = userToTest.name == user.user;
110
110
  if (usernameMatches && user.mfa && !usernameOnly) {
111
111
  if (!userToTest.otpCode) {
112
112
  otpMissingLength = user.mfaDigits || 6;
@@ -126,7 +126,7 @@ function authenticate(userToTest, usernameOnly) {
126
126
  }
127
127
  }
128
128
  }
129
- let passwordMatches = this.useEncryptedPasswords && !usernameOnly ? bcrypt.compareSync(userToTest.pass, user.pass) : userToTest.pass == user.pass;
129
+ const passwordMatches = this.useEncryptedPasswords && !usernameOnly ? bcrypt.compareSync(userToTest.pass, user.pass) : userToTest.pass == user.pass;
130
130
  if (usernameMatches && (usernameOnly || passwordMatches)) {
131
131
  isAuthenticated = true;
132
132
  matchingUsername = user.user;
@@ -129,7 +129,7 @@ const showInstructions = ({ app, username, passwordCopied, encrypt, config }) =>
129
129
  `\n${getOrder()}. Make sure that "useEncryptedPasswords" is set to "true" in your dashboard configuration.` +
130
130
  '\n You chose to generate an encrypted password for this user.' +
131
131
  '\n Any existing users with non-encrypted passwords will require newly created, encrypted passwords.'
132
- );
132
+ );
133
133
  }
134
134
  console.log(
135
135
  '\n------------------------------------------------------------------------------\n'
@@ -198,7 +198,7 @@ module.exports = {
198
198
  }
199
199
  ]);
200
200
  const { algorithm, digits, period } = await getAlgorithm();
201
- const secret =generateSecret({ app, username, algorithm, digits, period });
201
+ const secret = generateSecret({ app, username, algorithm, digits, period });
202
202
  Object.assign(config, secret.config);
203
203
  showQR(secret.config.url);
204
204
  }
@@ -4,11 +4,11 @@ const path = require('path');
4
4
  const packageJson = require('package-json');
5
5
  const csrf = require('csurf');
6
6
  const Authentication = require('./Authentication.js');
7
- var fs = require('fs');
7
+ const fs = require('fs');
8
8
 
9
9
  const currentVersionFeatures = require('../package.json').parseDashboardFeatures;
10
10
 
11
- var newFeaturesInLatestVersion = [];
11
+ let newFeaturesInLatestVersion = [];
12
12
  packageJson('parse-dashboard', { version: 'latest', fullMetadata: true })
13
13
  .then(latestPackage => {
14
14
  if (latestPackage.parseDashboardFeatures instanceof Array) {
@@ -31,29 +31,29 @@ function getMount(mountPath) {
31
31
  }
32
32
 
33
33
  function checkIfIconsExistForApps(apps, iconsFolder) {
34
- for (var i in apps) {
35
- var currentApp = apps[i];
36
- var iconName = currentApp.iconName;
37
- var path = iconsFolder + '/' + iconName;
34
+ for (const i in apps) {
35
+ const currentApp = apps[i];
36
+ const iconName = currentApp.iconName;
37
+ const path = iconsFolder + '/' + iconName;
38
38
 
39
39
  fs.stat(path, function(err) {
40
40
  if (err) {
41
- if ('ENOENT' == err.code) {// file does not exist
42
- console.warn('Icon with file name: ' + iconName +' couldn\'t be found in icons folder!');
43
- } else {
44
- console.log(
45
- 'An error occurd while checking for icons, please check permission!');
46
- }
41
+ if ('ENOENT' == err.code) {// file does not exist
42
+ console.warn('Icon with file name: ' + iconName + ' couldn\'t be found in icons folder!');
43
+ } else {
44
+ console.log(
45
+ 'An error occurd while checking for icons, please check permission!');
46
+ }
47
47
  } else {
48
- //every thing was ok so for example you can read it and send it to client
48
+ //every thing was ok so for example you can read it and send it to client
49
49
  }
50
- } );
50
+ });
51
51
  }
52
52
  }
53
53
 
54
54
  module.exports = function(config, options) {
55
55
  options = options || {};
56
- var app = express();
56
+ const app = express();
57
57
  // Serve public files.
58
58
  app.use(express.static(path.join(__dirname,'public')));
59
59
 
@@ -72,7 +72,7 @@ module.exports = function(config, options) {
72
72
 
73
73
  // CSRF error handler
74
74
  app.use(function (err, req, res, next) {
75
- if (err.code !== 'EBADCSRFTOKEN') return next(err)
75
+ if (err.code !== 'EBADCSRFTOKEN') {return next(err)}
76
76
 
77
77
  // handle CSRF token errors here
78
78
  res.status(403)
@@ -81,8 +81,8 @@ module.exports = function(config, options) {
81
81
 
82
82
  // Serve the configuration.
83
83
  app.get('/parse-dashboard-config.json', function(req, res) {
84
- let apps = config.apps.map((app) => Object.assign({}, app)); // make a copy
85
- let response = {
84
+ const apps = config.apps.map((app) => Object.assign({}, app)); // make a copy
85
+ const response = {
86
86
  apps: apps,
87
87
  newFeaturesInLatestVersion: newFeaturesInLatestVersion,
88
88
  };
@@ -159,7 +159,7 @@ module.exports = function(config, options) {
159
159
  // running parse-dashboard from globally installed npm.
160
160
  if (config.iconsFolder) {
161
161
  try {
162
- var stat = fs.statSync(config.iconsFolder);
162
+ const stat = fs.statSync(config.iconsFolder);
163
163
  if (stat.isDirectory()) {
164
164
  app.use('/appicons', express.static(config.iconsFolder));
165
165
  //Check also if the icons really exist
@@ -213,7 +213,7 @@ module.exports = function(config, options) {
213
213
  }
214
214
  return res.redirect(`${mountPath}login`);
215
215
  }
216
- if (users && req.user && req.user.matchingUsername ) {
216
+ if (users && req.user && req.user.matchingUsername) {
217
217
  res.append('username', req.user.matchingUsername);
218
218
  }
219
219
  res.send(`<!DOCTYPE html>