login-plus 1.9.2 → 1.9.4
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.
- package/README.md +1 -0
- package/for-client/auto-login.js +2 -2
- package/lib/login-plus.js +12 -11
- package/package.json +17 -10
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ login service for express
|
|
|
5
5
|
[](https://npmjs.org/package/login-plus)
|
|
6
6
|
[](https://github.com/codenautas/login-plus/actions/workflows/build-and-test.yml)
|
|
7
7
|
[](https://coveralls.io/r/codenautas/login-plus)
|
|
8
|
+
[](https://sonarcloud.io/summary/overall?id=codenautas_login-plus)
|
|
8
9
|
[](https://github.com/codenautas/login-plus/actions/workflows/qa-control.yml)
|
|
9
10
|
|
|
10
11
|
|
package/for-client/auto-login.js
CHANGED
|
@@ -5,12 +5,12 @@ window.addEventListener('load',function(){
|
|
|
5
5
|
(window.location.hash||"").split(/[#&]/g).forEach(function(pair){
|
|
6
6
|
var pos=pair.indexOf('=');
|
|
7
7
|
if(pos>=0){
|
|
8
|
-
params[pair.
|
|
8
|
+
params[pair.substring(0,pos)]=pair.substring(pos+1);
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
['username','password'].forEach(function(fieldName){
|
|
12
12
|
var elem=document.getElementById(fieldName);
|
|
13
|
-
var parameterName=fieldName.
|
|
13
|
+
var parameterName=fieldName.substring(0,1)
|
|
14
14
|
if(params[parameterName]){
|
|
15
15
|
elem.value=params[parameterName];
|
|
16
16
|
}
|
package/lib/login-plus.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var loginPlus = {};
|
|
4
4
|
|
|
5
|
-
var util = require('util');
|
|
6
|
-
var crypto = require('crypto');
|
|
5
|
+
var util = require('node:util');
|
|
6
|
+
var crypto = require('node:crypto');
|
|
7
7
|
|
|
8
8
|
var connectFlash = require('connect-flash');
|
|
9
9
|
var MiniTools = require('mini-tools');
|
|
@@ -12,7 +12,7 @@ var session = require('express-session');
|
|
|
12
12
|
var fs = require('fs-extra');
|
|
13
13
|
var bestGlobals = require('best-globals');
|
|
14
14
|
var changing = bestGlobals.changing;
|
|
15
|
-
var Path = require('path');
|
|
15
|
+
var Path = require('node:path');
|
|
16
16
|
var Regexplicit = require('regexplicit');
|
|
17
17
|
|
|
18
18
|
loginPlus.init = function AlertDeprecated(){
|
|
@@ -43,7 +43,7 @@ function serveJade(url, opts){
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function completeOptions(opts){
|
|
46
|
-
if(!opts
|
|
46
|
+
if(!opts?.successRedirect){
|
|
47
47
|
console.log('login-plus lack of mandatory: opts.successRedirect');
|
|
48
48
|
throw new Error('login-plus lack of mandatory: opts.successRedirect');
|
|
49
49
|
}
|
|
@@ -112,7 +112,7 @@ function completeOptions(opts){
|
|
|
112
112
|
|
|
113
113
|
function SetInitialOptions(app,opts){
|
|
114
114
|
var Passport = require('passport').Passport;
|
|
115
|
-
|
|
115
|
+
this.passport = new Passport();
|
|
116
116
|
this.LocalStrategy = require('passport-local').Strategy;
|
|
117
117
|
opts = this.opts = completeOptions(opts);
|
|
118
118
|
var sessionOpts=opts.session||{};
|
|
@@ -131,7 +131,7 @@ function SetInitialOptions(app,opts){
|
|
|
131
131
|
maxAge: opts.maxAge,
|
|
132
132
|
httpOnly: true,
|
|
133
133
|
sameSite: 'lax',
|
|
134
|
-
secure
|
|
134
|
+
secure:!opts.allowHttpLogin
|
|
135
135
|
}
|
|
136
136
|
},sessionOpts);
|
|
137
137
|
}
|
|
@@ -161,7 +161,7 @@ loginPlus.Manager.prototype.phpInit = function phpInit(app,opts){
|
|
|
161
161
|
*/
|
|
162
162
|
var ensureMiddlewareWihtoutPHP = this.ensureMiddleware;
|
|
163
163
|
this.ensureMiddleware = function(req, res, next){
|
|
164
|
-
if(req.$SESSION
|
|
164
|
+
if(req.$SESSION?.[opts.php.varLogged]){
|
|
165
165
|
return next();
|
|
166
166
|
}else{
|
|
167
167
|
ensureMiddlewareWihtoutPHP(req, res, next);
|
|
@@ -181,7 +181,7 @@ function checkAlreadyLoggedIn(app, opts){
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
loginPlus.Manager.prototype.init = function init(app,opts){ // eslint-disable-line max-statements
|
|
184
|
-
var thisManager = this;
|
|
184
|
+
var thisManager = this; // eslint-disable-line unicorn/no-this-assignment
|
|
185
185
|
if(!this.passport){
|
|
186
186
|
var router = '_router' in app ? app._router : app.router;
|
|
187
187
|
if(router){
|
|
@@ -215,7 +215,7 @@ loginPlus.Manager.prototype.init = function init(app,opts){ // eslint-disable-li
|
|
|
215
215
|
return fs.exists(fileNameLogin);
|
|
216
216
|
}).then(function(exists){
|
|
217
217
|
if(!exists){
|
|
218
|
-
throw Error('login-plus.init fail "'+fileNameLogin+'" does not exists');
|
|
218
|
+
throw new Error('login-plus.init fail "'+fileNameLogin+'" does not exists');
|
|
219
219
|
}
|
|
220
220
|
});
|
|
221
221
|
app.get(opts.baseUrl+opts.logoutUrlPath, function(req,res,next){
|
|
@@ -243,6 +243,7 @@ loginPlus.Manager.prototype.init = function init(app,opts){ // eslint-disable-li
|
|
|
243
243
|
failureFlash: true,
|
|
244
244
|
keepSessionInfo: true,
|
|
245
245
|
}
|
|
246
|
+
// TODO: validar req.session.returnTo con isLocalPath (exportarla desde ensure-login) antes de que passport redirija, por si se guardó sin validar
|
|
246
247
|
authenticateOptions[opts.successReturns?'successReturnToOrRedirect':'successRedirect'] = opts.redirBaseUrl+opts.successRedirect
|
|
247
248
|
app.post(opts.baseUrl+opts.loginUrlPath,
|
|
248
249
|
this.passport.authenticate('local', authenticateOptions)
|
|
@@ -268,7 +269,7 @@ loginPlus.Manager.prototype.init = function init(app,opts){ // eslint-disable-li
|
|
|
268
269
|
/////// ATENCIÓN NUNCA METER ensureLoggedIn dentro de una cadena de promesas. Necesitamos que se ejecute sí o sí
|
|
269
270
|
app.use(opts.baseUrl,this.ensureMiddleware);
|
|
270
271
|
//// NOW is logged in
|
|
271
|
-
app.post(opts.baseUrl+opts.chPassUrlPath, function(req,res){
|
|
272
|
+
app.post(opts.baseUrl+opts.chPassUrlPath, function(req,res,next){
|
|
272
273
|
if (!req.body.newPassword) {
|
|
273
274
|
req.flash('error', (opts.messages?.passCantBeEmpty || "new pass cant be empty"));
|
|
274
275
|
res.redirect(opts.redirBaseUrl+opts.chPassUrlPath)
|
|
@@ -289,7 +290,7 @@ loginPlus.Manager.prototype.init = function init(app,opts){ // eslint-disable-li
|
|
|
289
290
|
res.redirect(opts.redirBaseUrl+opts.loginUrlPath);
|
|
290
291
|
});
|
|
291
292
|
}else{
|
|
292
|
-
if(err && opts.log.errors.getTime() >
|
|
293
|
+
if(err && opts.log.errors.getTime() > Date.now()){
|
|
293
294
|
console.log('chpass error',err);
|
|
294
295
|
}
|
|
295
296
|
req.flash('error', flashMessage || opts.messages?.internalError || 'internal error');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "login-plus",
|
|
3
3
|
"description": "login service for express",
|
|
4
|
-
"version": "1.9.
|
|
4
|
+
"version": "1.9.4",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "codenautas/login-plus",
|
|
@@ -31,31 +31,34 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"best-globals": "^2.2.3",
|
|
33
33
|
"connect-flash": "^0.1.1",
|
|
34
|
-
"ensure-login": "^0.1.
|
|
34
|
+
"ensure-login": "^0.1.8",
|
|
35
35
|
"express-session": "^1.19.0",
|
|
36
36
|
"fs-extra": "^11.4.1",
|
|
37
|
-
"mini-tools": "^1.13.
|
|
37
|
+
"mini-tools": "^1.13.14",
|
|
38
38
|
"passport": "^0.7.0",
|
|
39
39
|
"passport-local": "^1.0.0",
|
|
40
|
-
"regexplicit": "^0.
|
|
40
|
+
"regexplicit": "^0.2.0",
|
|
41
41
|
"session-file-store": "^1.5.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"ajax-best-promise": "^0.4.
|
|
45
|
-
"body-parser": "^2.
|
|
44
|
+
"ajax-best-promise": "^0.4.7",
|
|
45
|
+
"body-parser": "^2.4.0",
|
|
46
46
|
"concat-stream": "^2.0.0",
|
|
47
47
|
"cookie-parser": "^1.4.7",
|
|
48
|
+
"escape-html": "^1.0.3",
|
|
49
|
+
"eslint-plugin-sonarjs": "^4.2.2",
|
|
50
|
+
"eslint-plugin-unicorn": "^79.0.0",
|
|
48
51
|
"expect.js": "^0.3.1",
|
|
49
52
|
"express": "^5.3.0",
|
|
50
53
|
"mocha": "^12.0.3",
|
|
51
54
|
"nyc": "^18.0.0",
|
|
52
|
-
"pg-promise-strict": "^1.
|
|
55
|
+
"pg-promise-strict": "^1.7.1",
|
|
53
56
|
"php-session": "^0.1.0",
|
|
54
57
|
"pug": "^3.0.4",
|
|
55
|
-
"qa-control": "^0.14.
|
|
58
|
+
"qa-control": "^0.14.2",
|
|
56
59
|
"read-yaml-promise": "^1.0.2",
|
|
57
60
|
"self-explain": "^0.11.0",
|
|
58
|
-
"serve-content": "^1.
|
|
61
|
+
"serve-content": "^1.1.1",
|
|
59
62
|
"sinon": "^22.1.0",
|
|
60
63
|
"stylus": "^0.64.0",
|
|
61
64
|
"supertest": "^7.3.1"
|
|
@@ -81,6 +84,10 @@
|
|
|
81
84
|
"run-in": "server",
|
|
82
85
|
"type": "lib",
|
|
83
86
|
"coverage": 100,
|
|
84
|
-
"gha": "all"
|
|
87
|
+
"gha": "all",
|
|
88
|
+
"silenced": [
|
|
89
|
+
"file_1_does_not_match_custom_2"
|
|
90
|
+
],
|
|
91
|
+
"sonar": true
|
|
85
92
|
}
|
|
86
93
|
}
|