login-plus 1.8.1 → 1.9.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.
package/LICENSE CHANGED
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
-
package/README.md CHANGED
@@ -1,107 +1,107 @@
1
- # login-plus
2
- login service for express
3
-
4
- ![stable](https://img.shields.io/badge/stability-stable-blue.svg)
5
- [![npm-version](https://img.shields.io/npm/v/login-plus.svg)](https://npmjs.org/package/login-plus)
6
- [![downloads](https://img.shields.io/npm/dm/login-plus.svg)](https://npmjs.org/package/login-plus)
7
- [![build](https://github.com/codenautas/login-plus/actions/workflows/node.js.yml/badge.svg)](https://github.com/codenautas/login-plus/actions/workflows/node.js.yml)
8
- [![coverage](https://img.shields.io/coveralls/codenautas/login-plus/master.svg)](https://coveralls.io/r/codenautas/login-plus)
9
- [![outdated-deps](https://img.shields.io/github/issues-search/codenautas/login-plus?color=9cf&label=outdated-deps&query=is%3Apr%20author%3Aapp%2Fdependabot%20is%3Aopen)](https://github.com/codenautas/login-plus/pulls/app%2Fdependabot)
10
-
11
-
12
- language: ![English](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-en.png)
13
- also available in:
14
- [![Spanish](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-es.png)](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
+ [![npm-version](https://img.shields.io/npm/v/login-plus.svg)](https://npmjs.org/package/login-plus)
5
+ [![downloads](https://img.shields.io/npm/dm/login-plus.svg)](https://npmjs.org/package/login-plus)
6
+ [![build](https://github.com/codenautas/login-plus/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/codenautas/login-plus/actions/workflows/build-and-test.yml)
7
+ [![coverage](https://img.shields.io/coveralls/codenautas/login-plus/master.svg)](https://coveralls.io/r/codenautas/login-plus)
8
+ [![security](https://socket.dev/api/badge/npm/package/login-plus)](https://socket.dev/npm/package/login-plus)
9
+ [![qa-control](https://github.com/codenautas/login-plus/actions/workflows/qa-control.yml/badge.svg)](https://github.com/codenautas/login-plus/actions/workflows/qa-control.yml)
10
+
11
+
12
+ language: ![English](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-en.png)
13
+ also available in:
14
+ [![Spanish](https://raw.githubusercontent.com/codenautas/multilang/master/img/lang-es.png)](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,4 +1,4 @@
1
1
  "use strict";
2
2
 
3
3
  window.addEventListener('load', function(){
4
- });
4
+ });
package/lib/login-plus.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var loginPlus = {};
4
4
 
5
5
  var util = require('util');
6
+ var crypto = require('crypto');
6
7
 
7
8
  var connectFlash = require('connect-flash');
8
9
  var MiniTools = require('mini-tools');
@@ -25,7 +26,7 @@ loginPlus.Manager = function LoginPlusManager(){
25
26
  'jpg','png','gif',
26
27
  'css','js','manifest'
27
28
  ];
28
- this.secret = 'keyboard cat '+Math.random();
29
+ this.secret = crypto.randomBytes(32).toString('hex');
29
30
  this.savedUser = {};
30
31
  };
31
32
 
@@ -122,13 +123,14 @@ function SetInitialOptions(app,opts){
122
123
  this.store=sessionOpts.store;
123
124
  }
124
125
  this.sessionOpts=changing({
125
- secret: opts.secret || this.secret,
126
- resave: false,
126
+ secret: opts.secret || this.secret,
127
+ resave: false,
127
128
  saveUninitialized: true,
128
129
  rolling: true,
129
130
  cookie: {
130
131
  maxAge: opts.maxAge,
131
132
  httpOnly: true,
133
+ sameSite: 'lax',
132
134
  secure:(opts.allowHttpLogin?false:true)
133
135
  }
134
136
  },sessionOpts);
@@ -178,11 +180,11 @@ function checkAlreadyLoggedIn(app, opts){
178
180
  });
179
181
  }
180
182
 
181
- loginPlus.Manager.prototype.init = function init(app,opts){
183
+ loginPlus.Manager.prototype.init = function init(app,opts){ // eslint-disable-line complexity
182
184
  var thisManager = this;
183
185
  if(!this.passport){
184
186
  var router = '_router' in app ? app._router : app.router;
185
- if(!!router){
187
+ if(router){
186
188
  var forbidensMiddlewares=router.stack.filter(function(layer){
187
189
  return layer.name==='cookieParser';
188
190
  });
@@ -198,7 +200,7 @@ loginPlus.Manager.prototype.init = function init(app,opts){
198
200
  this.ensureMiddleware = ensureLoggedIn({baseUrl: opts.baseUrl, redirectTo:opts.noLoggedUrlPath, setReturnTo:Regexplicit.detectNonEmptyUrlWithoutResources});
199
201
  // this.ensureMiddleware = ensureLoggedIn(opts.baseUrl+opts.noLoggedUrlPath);
200
202
  ['auto-login.js', 'strength-pass.js', 'Oxygen480-actions-key-enter.svg.png'].forEach(function(fileName){
201
- app.use(opts.baseUrl+'/'+fileName,
203
+ app.use(opts.baseUrl+'/'+fileName,
202
204
  MiniTools.serveFile(Path.join(opts.loginPagePath,fileName))
203
205
  );
204
206
  });
@@ -236,12 +238,12 @@ loginPlus.Manager.prototype.init = function init(app,opts){
236
238
  checkAlreadyLoggedIn(app, opts);
237
239
  }
238
240
  app.get(opts.baseUrl+opts.loginUrlPath, opts.loginPageServe);
239
- var authenticateOptions={
241
+ var authenticateOptions={
240
242
  failureRedirect: opts.redirBaseUrl+opts.failedLoginUrlPath,
241
243
  failureFlash: true,
242
244
  keepSessionInfo: true,
243
245
  }
244
- authenticateOptions[opts.successReturns?'successReturnToOrRedirect':'successRedirect'] = opts.redirBaseUrl+opts.successRedirect
246
+ authenticateOptions[opts.successReturns?'successReturnToOrRedirect':'successRedirect'] = opts.redirBaseUrl+opts.successRedirect
245
247
  app.post(opts.baseUrl+opts.loginUrlPath,
246
248
  this.passport.authenticate('local', authenticateOptions)
247
249
  );
@@ -264,7 +266,7 @@ loginPlus.Manager.prototype.init = function init(app,opts){
264
266
  }
265
267
  opts.schrödinger();
266
268
  /////// ATENCIÓN NUNCA METER ensureLoggedIn dentro de una cadena de promesas. Necesitamos que se ejecute sí o sí
267
- app.use(opts.baseUrl,this.ensureMiddleware);
269
+ app.use(opts.baseUrl,this.ensureMiddleware);
268
270
  //// NOW is logged in
269
271
  app.post(opts.baseUrl+opts.chPassUrlPath, function(req,res){
270
272
  if(req.body.newPassword!=req.body.repPassword){
@@ -273,9 +275,9 @@ loginPlus.Manager.prototype.init = function init(app,opts){
273
275
  }else if(req.body.newPassword.length>=opts.passMinLength){
274
276
  thisManager.passwordChanger(
275
277
  req,
276
- req.user[opts.userFieldName],
277
- req.body.oldPassword,
278
- req.body.newPassword,
278
+ req.user[opts.userFieldName],
279
+ req.body.oldPassword,
280
+ req.body.newPassword,
279
281
  function(err, ok, flashMessage){
280
282
  if(ok){
281
283
  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.8.1",
4
+ "version": "1.9.0-beta.1",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/login-plus",
@@ -20,36 +20,42 @@
20
20
  "email": "diegoefe@gmail.com"
21
21
  }
22
22
  ],
23
+ "overrides": {
24
+ "diff": ">=8.0.2",
25
+ "serialize-javascript": ">=7.0.0",
26
+ "uuid": ">=14.0.0"
27
+ },
23
28
  "dependencies": {
29
+ "best-globals": "^2.2.2",
24
30
  "connect-flash": "^0.1.1",
31
+ "ensure-login": "0.1.6-beta.1",
25
32
  "express-session": "^1.19.0",
26
- "fs-extra": "^11.3.3",
33
+ "fs-extra": "^11.3.6",
34
+ "mini-tools": "^1.13.7",
27
35
  "passport": "^0.7.0",
28
36
  "passport-local": "^1.0.0",
29
- "session-file-store": "^1.5.0",
30
- "best-globals": "^2.0.7",
31
- "ensure-login": "^0.1.5",
32
- "mini-tools": "^1.13.5",
33
- "regexplicit": "^0.1.3"
37
+ "regexplicit": "^0.1.3",
38
+ "session-file-store": "^1.5.0"
34
39
  },
35
40
  "devDependencies": {
36
- "body-parser": "^2.2.2",
41
+ "ajax-best-promise": "^0.4.3",
42
+ "body-parser": "^2.3.0",
37
43
  "concat-stream": "^2.0.0",
38
44
  "cookie-parser": "^1.4.7",
39
45
  "expect.js": "^0.3.1",
40
46
  "express": "^5.2.1",
41
- "nyc": "^17.1.0",
42
- "pug": "^3.0.3",
43
- "mocha": "^11.7.5",
47
+ "mocha": "^11.7.6",
48
+ "nyc": "^18.0.0",
49
+ "pg-promise-strict": "^1.4.6",
44
50
  "php-session": "^0.1.0",
51
+ "pug": "^3.0.4",
52
+ "qa-control": "^0.7.5",
45
53
  "read-yaml-promise": "^1.0.2",
46
- "sinon": "^21.0.1",
47
- "stylus": "^0.64.0",
48
- "supertest": "^7.2.2",
49
- "ajax-best-promise": "^0.4.3",
50
- "pg-promise-strict": "^1.4.5",
51
54
  "self-explain": "^0.11.0",
52
- "serve-content": "^1.0.2"
55
+ "serve-content": "^1.0.5",
56
+ "sinon": "^22.0.0",
57
+ "stylus": "^0.64.0",
58
+ "supertest": "^7.2.2"
53
59
  },
54
60
  "optionalDependencies": {
55
61
  "php-session": "^0.1.0"
@@ -74,6 +80,7 @@
74
80
  "run-in": "server",
75
81
  "type": "lib",
76
82
  "stage": "stable",
77
- "coverage": 100
83
+ "coverage": 100,
84
+ "gha": "all"
78
85
  }
79
86
  }