login-plus 1.9.0-beta.0 → 1.9.0
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/LICENSE +0 -1
- package/README.md +107 -107
- package/for-client/auto-login.js +1 -1
- package/for-client/strength-pass.js +1 -1
- package/lib/login-plus.js +16 -13
- package/package.json +25 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
# login-plus
|
|
2
|
-
login service for express
|
|
3
|
-
|
|
4
|
-

|
|
13
|
-
also available in:
|
|
14
|
-
[](LEEME.md)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# install
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
> npm install login-plus
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# Use
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```js
|
|
29
|
-
|
|
30
|
-
var express = require('express');
|
|
31
|
-
var app = express();
|
|
32
|
-
var bodyParser = require('body-parser');
|
|
33
|
-
|
|
34
|
-
app.use(bodyParser.urlencoded({extended:true}));
|
|
35
|
-
|
|
36
|
-
var loginPlus = new (require('login-plus').Manager);
|
|
37
|
-
|
|
38
|
-
loginPlus.init(app,{ successRedirect:'/index' });
|
|
39
|
-
|
|
40
|
-
loginPlus.setValidator(
|
|
41
|
-
function(username, password, done) {
|
|
42
|
-
if(username === 'admin' && password === 'secret.pass'){
|
|
43
|
-
done(null, {username: 'admin', when: Date()});
|
|
44
|
-
}else{
|
|
45
|
-
done('username or password error');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
app.get('/user-info',function(req,res){
|
|
51
|
-
res.end(
|
|
52
|
-
'user: '+req.session.passport.username+
|
|
53
|
-
' logged since '+req.session.passport.when
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
## loginPlus.init(app, opts)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
From this line on, `loginPlus` controls whether the session is logged.
|
|
64
|
-
If not, it redirects to `/login`.
|
|
65
|
-
|
|
66
|
-
opts | default opts | use
|
|
67
|
-
--------------------|----------------------|---------------
|
|
68
|
-
loginPagePath | *internal [1]* | path to the .jade file that contains the login screen
|
|
69
|
-
loginPageServe | *jade motor* | function that serves the login page (use this function when a .jade file is not desired)
|
|
70
|
-
baseUrl | `/` | base URL for all other URLs
|
|
71
|
-
successRedirect | *mandatory* | successful login path
|
|
72
|
-
successReturns | false | returns to previous path when login
|
|
73
|
-
loginUrlPath | `/login` | URL to the login page
|
|
74
|
-
noLoggedUrlPath | `/login` | URL to the unlogged page where the authentification is required when trying to log in
|
|
75
|
-
failedLoginUrlPath | `/login` | URL to the failing login page
|
|
76
|
-
userFieldName | `username` | name of the "username" field
|
|
77
|
-
secret | random key | keys for cookies
|
|
78
|
-
alreadyLoggedIn | successRedirect | `/login` redirection when is already logged
|
|
79
|
-
skipCheckAlreadyLoggedIn | false | allows `/login` redirects to login page even if the user is already logged
|
|
80
|
-
**php** | false | hibrid login system mergin with PHP
|
|
81
|
-
.save_path | | path of PHP session files
|
|
82
|
-
.varLogged | | `$SESSION` variable name for login control
|
|
83
|
-
**loginForm** | | opciones del formulario de login
|
|
84
|
-
.usernameLabel | `Username` | username label
|
|
85
|
-
.passwordLabel | `Password` | password label
|
|
86
|
-
.buttonLabel | `Log In` | button label
|
|
87
|
-
.formTitle | `login` | form title
|
|
88
|
-
.formImg | | form image
|
|
89
|
-
.autoLogin | false | enable direct login from URL with `?u=user&p=pass&a=1`
|
|
90
|
-
store.module | null | function that returns the constructor of the module to store sessions (it receive the express-session instance as first argument)
|
|
91
|
-
|
|
92
|
-
From this point on, the middlewares can access the data session contained in `req.user`.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
## loginPlus.setValidator(fn)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
It registers the function that the user must validate and in case of success, obtains
|
|
100
|
-
the additional necessary information for the session (for example, role or level of permission)
|
|
101
|
-
that will be available in `req.session.passport`
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
# License
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
[MIT](LICENSE)
|
|
1
|
+
# login-plus
|
|
2
|
+
login service for express
|
|
3
|
+
|
|
4
|
+
[](https://npmjs.org/package/login-plus)
|
|
5
|
+
[](https://npmjs.org/package/login-plus)
|
|
6
|
+
[](https://github.com/codenautas/login-plus/actions/workflows/build-and-test.yml)
|
|
7
|
+
[](https://coveralls.io/r/codenautas/login-plus)
|
|
8
|
+
[](https://socket.dev/npm/package/login-plus)
|
|
9
|
+
[](https://github.com/codenautas/login-plus/actions/workflows/qa-control.yml)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
language: 
|
|
13
|
+
also available in:
|
|
14
|
+
[](LEEME.md)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# install
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
> npm install login-plus
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Use
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
|
|
30
|
+
var express = require('express');
|
|
31
|
+
var app = express();
|
|
32
|
+
var bodyParser = require('body-parser');
|
|
33
|
+
|
|
34
|
+
app.use(bodyParser.urlencoded({extended:true}));
|
|
35
|
+
|
|
36
|
+
var loginPlus = new (require('login-plus').Manager);
|
|
37
|
+
|
|
38
|
+
loginPlus.init(app,{ successRedirect:'/index' });
|
|
39
|
+
|
|
40
|
+
loginPlus.setValidator(
|
|
41
|
+
function(username, password, done) {
|
|
42
|
+
if(username === 'admin' && password === 'secret.pass'){
|
|
43
|
+
done(null, {username: 'admin', when: Date()});
|
|
44
|
+
}else{
|
|
45
|
+
done('username or password error');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
app.get('/user-info',function(req,res){
|
|
51
|
+
res.end(
|
|
52
|
+
'user: '+req.session.passport.username+
|
|
53
|
+
' logged since '+req.session.passport.when
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## loginPlus.init(app, opts)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
From this line on, `loginPlus` controls whether the session is logged.
|
|
64
|
+
If not, it redirects to `/login`.
|
|
65
|
+
|
|
66
|
+
opts | default opts | use
|
|
67
|
+
--------------------|----------------------|---------------
|
|
68
|
+
loginPagePath | *internal [1]* | path to the .jade file that contains the login screen
|
|
69
|
+
loginPageServe | *jade motor* | function that serves the login page (use this function when a .jade file is not desired)
|
|
70
|
+
baseUrl | `/` | base URL for all other URLs
|
|
71
|
+
successRedirect | *mandatory* | successful login path
|
|
72
|
+
successReturns | false | returns to previous path when login
|
|
73
|
+
loginUrlPath | `/login` | URL to the login page
|
|
74
|
+
noLoggedUrlPath | `/login` | URL to the unlogged page where the authentification is required when trying to log in
|
|
75
|
+
failedLoginUrlPath | `/login` | URL to the failing login page
|
|
76
|
+
userFieldName | `username` | name of the "username" field
|
|
77
|
+
secret | random key | keys for cookies
|
|
78
|
+
alreadyLoggedIn | successRedirect | `/login` redirection when is already logged
|
|
79
|
+
skipCheckAlreadyLoggedIn | false | allows `/login` redirects to login page even if the user is already logged
|
|
80
|
+
**php** | false | hibrid login system mergin with PHP
|
|
81
|
+
.save_path | | path of PHP session files
|
|
82
|
+
.varLogged | | `$SESSION` variable name for login control
|
|
83
|
+
**loginForm** | | opciones del formulario de login
|
|
84
|
+
.usernameLabel | `Username` | username label
|
|
85
|
+
.passwordLabel | `Password` | password label
|
|
86
|
+
.buttonLabel | `Log In` | button label
|
|
87
|
+
.formTitle | `login` | form title
|
|
88
|
+
.formImg | | form image
|
|
89
|
+
.autoLogin | false | enable direct login from URL with `?u=user&p=pass&a=1`
|
|
90
|
+
store.module | null | function that returns the constructor of the module to store sessions (it receive the express-session instance as first argument)
|
|
91
|
+
|
|
92
|
+
From this point on, the middlewares can access the data session contained in `req.user`.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## loginPlus.setValidator(fn)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
It registers the function that the user must validate and in case of success, obtains
|
|
100
|
+
the additional necessary information for the session (for example, role or level of permission)
|
|
101
|
+
that will be available in `req.session.passport`
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# License
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
[MIT](LICENSE)
|
package/for-client/auto-login.js
CHANGED
package/lib/login-plus.js
CHANGED
|
@@ -123,8 +123,8 @@ function SetInitialOptions(app,opts){
|
|
|
123
123
|
this.store=sessionOpts.store;
|
|
124
124
|
}
|
|
125
125
|
this.sessionOpts=changing({
|
|
126
|
-
secret: opts.secret || this.secret,
|
|
127
|
-
resave: false,
|
|
126
|
+
secret: opts.secret || this.secret,
|
|
127
|
+
resave: false,
|
|
128
128
|
saveUninitialized: true,
|
|
129
129
|
rolling: true,
|
|
130
130
|
cookie: {
|
|
@@ -180,11 +180,11 @@ function checkAlreadyLoggedIn(app, opts){
|
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
loginPlus.Manager.prototype.init = function init(app,opts){
|
|
183
|
+
loginPlus.Manager.prototype.init = function init(app,opts){ // eslint-disable-line max-statements
|
|
184
184
|
var thisManager = this;
|
|
185
185
|
if(!this.passport){
|
|
186
186
|
var router = '_router' in app ? app._router : app.router;
|
|
187
|
-
if(
|
|
187
|
+
if(router){
|
|
188
188
|
var forbidensMiddlewares=router.stack.filter(function(layer){
|
|
189
189
|
return layer.name==='cookieParser';
|
|
190
190
|
});
|
|
@@ -200,7 +200,7 @@ loginPlus.Manager.prototype.init = function init(app,opts){
|
|
|
200
200
|
this.ensureMiddleware = ensureLoggedIn({baseUrl: opts.baseUrl, redirectTo:opts.noLoggedUrlPath, setReturnTo:Regexplicit.detectNonEmptyUrlWithoutResources});
|
|
201
201
|
// this.ensureMiddleware = ensureLoggedIn(opts.baseUrl+opts.noLoggedUrlPath);
|
|
202
202
|
['auto-login.js', 'strength-pass.js', 'Oxygen480-actions-key-enter.svg.png'].forEach(function(fileName){
|
|
203
|
-
app.use(opts.baseUrl+'/'+fileName,
|
|
203
|
+
app.use(opts.baseUrl+'/'+fileName,
|
|
204
204
|
MiniTools.serveFile(Path.join(opts.loginPagePath,fileName))
|
|
205
205
|
);
|
|
206
206
|
});
|
|
@@ -238,12 +238,12 @@ loginPlus.Manager.prototype.init = function init(app,opts){
|
|
|
238
238
|
checkAlreadyLoggedIn(app, opts);
|
|
239
239
|
}
|
|
240
240
|
app.get(opts.baseUrl+opts.loginUrlPath, opts.loginPageServe);
|
|
241
|
-
var authenticateOptions={
|
|
241
|
+
var authenticateOptions={
|
|
242
242
|
failureRedirect: opts.redirBaseUrl+opts.failedLoginUrlPath,
|
|
243
243
|
failureFlash: true,
|
|
244
244
|
keepSessionInfo: true,
|
|
245
245
|
}
|
|
246
|
-
authenticateOptions[opts.successReturns?'successReturnToOrRedirect':'successRedirect'] = opts.redirBaseUrl+opts.successRedirect
|
|
246
|
+
authenticateOptions[opts.successReturns?'successReturnToOrRedirect':'successRedirect'] = opts.redirBaseUrl+opts.successRedirect
|
|
247
247
|
app.post(opts.baseUrl+opts.loginUrlPath,
|
|
248
248
|
this.passport.authenticate('local', authenticateOptions)
|
|
249
249
|
);
|
|
@@ -266,18 +266,21 @@ loginPlus.Manager.prototype.init = function init(app,opts){
|
|
|
266
266
|
}
|
|
267
267
|
opts.schrödinger();
|
|
268
268
|
/////// ATENCIÓN NUNCA METER ensureLoggedIn dentro de una cadena de promesas. Necesitamos que se ejecute sí o sí
|
|
269
|
-
app.use(opts.baseUrl,this.ensureMiddleware);
|
|
269
|
+
app.use(opts.baseUrl,this.ensureMiddleware);
|
|
270
270
|
//// NOW is logged in
|
|
271
271
|
app.post(opts.baseUrl+opts.chPassUrlPath, function(req,res){
|
|
272
|
-
if(req.body.newPassword
|
|
272
|
+
if (!req.body.newPassword) {
|
|
273
|
+
req.flash('error', (opts.messages?.passCantBeEmpty || "new pass cant be empty"));
|
|
274
|
+
res.redirect(opts.redirBaseUrl+opts.chPassUrlPath)
|
|
275
|
+
}else if (req.body.newPassword !== req.body.repPassword) {
|
|
273
276
|
req.flash('error', (opts.messages?.passDoesntMatch || "new pass doesn't match"));
|
|
274
277
|
res.redirect(opts.redirBaseUrl+opts.chPassUrlPath);
|
|
275
|
-
}else if(req.body.newPassword.length>=opts.passMinLength){
|
|
278
|
+
}else if((req.body.newPassword||'').length>=opts.passMinLength){
|
|
276
279
|
thisManager.passwordChanger(
|
|
277
280
|
req,
|
|
278
|
-
req.user[opts.userFieldName],
|
|
279
|
-
req.body.oldPassword,
|
|
280
|
-
req.body.newPassword,
|
|
281
|
+
req.user[opts.userFieldName],
|
|
282
|
+
req.body.oldPassword,
|
|
283
|
+
req.body.newPassword,
|
|
281
284
|
function(err, ok, flashMessage){
|
|
282
285
|
if(ok){
|
|
283
286
|
req.logout(function(err) {
|
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.0
|
|
4
|
+
"version": "1.9.0",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "codenautas/login-plus",
|
|
@@ -20,34 +20,43 @@
|
|
|
20
20
|
"email": "diegoefe@gmail.com"
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
|
+
"overrides": {
|
|
24
|
+
"diff": ">=8.0.2",
|
|
25
|
+
"serialize-javascript": ">=7.0.0",
|
|
26
|
+
"stylus": {
|
|
27
|
+
"glob": "^11"
|
|
28
|
+
},
|
|
29
|
+
"uuid": ">=14.0.0"
|
|
30
|
+
},
|
|
23
31
|
"dependencies": {
|
|
24
|
-
"best-globals": "^2.
|
|
32
|
+
"best-globals": "^2.2.2",
|
|
25
33
|
"connect-flash": "^0.1.1",
|
|
26
|
-
"ensure-login": "0.1.6
|
|
34
|
+
"ensure-login": "^0.1.6",
|
|
27
35
|
"express-session": "^1.19.0",
|
|
28
|
-
"fs-extra": "^11.
|
|
29
|
-
"mini-tools": "^1.13.
|
|
36
|
+
"fs-extra": "^11.4.0",
|
|
37
|
+
"mini-tools": "^1.13.10",
|
|
30
38
|
"passport": "^0.7.0",
|
|
31
39
|
"passport-local": "^1.0.0",
|
|
32
40
|
"regexplicit": "^0.1.3",
|
|
33
41
|
"session-file-store": "^1.5.0"
|
|
34
42
|
},
|
|
35
43
|
"devDependencies": {
|
|
36
|
-
"ajax-best-promise": "^0.4.
|
|
37
|
-
"body-parser": "^2.
|
|
44
|
+
"ajax-best-promise": "^0.4.5",
|
|
45
|
+
"body-parser": "^2.3.0",
|
|
38
46
|
"concat-stream": "^2.0.0",
|
|
39
47
|
"cookie-parser": "^1.4.7",
|
|
40
48
|
"expect.js": "^0.3.1",
|
|
41
49
|
"express": "^5.2.1",
|
|
42
|
-
"mocha": "^
|
|
43
|
-
"nyc": "^
|
|
44
|
-
"pg-promise-strict": "^1.
|
|
50
|
+
"mocha": "^12.0.0-rc.5",
|
|
51
|
+
"nyc": "^18.0.0",
|
|
52
|
+
"pg-promise-strict": "^1.5.0",
|
|
45
53
|
"php-session": "^0.1.0",
|
|
46
|
-
"pug": "^3.0.
|
|
54
|
+
"pug": "^3.0.4",
|
|
55
|
+
"qa-control": "^0.9.2",
|
|
47
56
|
"read-yaml-promise": "^1.0.2",
|
|
48
57
|
"self-explain": "^0.11.0",
|
|
49
|
-
"serve-content": "^1.0.
|
|
50
|
-
"sinon": "^
|
|
58
|
+
"serve-content": "^1.0.5",
|
|
59
|
+
"sinon": "^22.1.0",
|
|
51
60
|
"stylus": "^0.64.0",
|
|
52
61
|
"supertest": "^7.2.2"
|
|
53
62
|
},
|
|
@@ -59,8 +68,7 @@
|
|
|
59
68
|
},
|
|
60
69
|
"scripts": {
|
|
61
70
|
"test": "mocha --reporter spec --bail --check-leaks --globals __core-js_shared__ --exit test/test*.js",
|
|
62
|
-
"test-ci": "nyc
|
|
63
|
-
"test-cov": "nyc mocha --exit test/test*.js && nyc report --reporter=lcov",
|
|
71
|
+
"test-ci": "nyc mocha --exit test/test*.js --exit --check-leaks --globals __core-js_shared__ && nyc report --reporter=lcov",
|
|
64
72
|
"start": "node example/server.js"
|
|
65
73
|
},
|
|
66
74
|
"nyc": {
|
|
@@ -74,6 +82,7 @@
|
|
|
74
82
|
"run-in": "server",
|
|
75
83
|
"type": "lib",
|
|
76
84
|
"stage": "stable",
|
|
77
|
-
"coverage": 100
|
|
85
|
+
"coverage": 100,
|
|
86
|
+
"gha": "all"
|
|
78
87
|
}
|
|
79
88
|
}
|