Skip to content

Commit

Permalink
Agrego el parámetro baseUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilio authored and Emilio committed Mar 10, 2016
1 parent 19032cc commit ba24810
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 136 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "0.12"
- "4.2"
- "5.0"
- "4.4.0"
- "5.8.0"
matrix:
fast_finish: true
script: "npm run-script test-ci"
Expand Down
2 changes: 2 additions & 0 deletions LEEME.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ opts | predeterminado | uso
unloggedPath | `../unlogged` | carpeta en el servidor a la que apuntará la ruta /unlogged
loginPagePath | `/../unlogged/login` | dirección al archivo .jade que tiene el dibujo de la pantalla de login
loginPageServe | motor de jade | función que sirve la página de login (usar esta función cuando no se desea un archivo .jade)
baseUrl | `/` | dirección base de todas las URL
successRedirect | `/index` | dirección a donde debe redirigir la aplicación cuando hay un loggin exitoso
loginUrlPath | `/login` | dirección donde se muestra la página de login
noLoggedUrlPath | `/login` | dirección de la página que se muestra cuando no está logueado si intenta acceder a una página donde se requiere autenticación
Expand All @@ -112,6 +113,7 @@ opts | default opts | use
unloggedPath | `../unlogged` | server directory to which the path /unlogged points
loginPagePath | `/../unlogged/login` | path to the .jade file that contains the login screen
loginPageServe | motor de jade | function that serves the login page (use this function when a .jade file is not desired)
baseUrl | `/` | base URL for all other URLs
successRedirect | `/index` | successful login path
loginUrlPath | `/login` | URL to the login page
noLoggedUrlPath | `/login` | URL to the unlogged page where the authentification is required when trying to log in
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ opts | default opts | use
unloggedPath | `../unlogged` | server directory to which the path /unlogged points
loginPagePath | `/../unlogged/login` | path to the .jade file that contains the login screen
loginPageServe | motor de jade | function that serves the login page (use this function when a .jade file is not desired)
baseUrl | `/` | base URL for all other URLs
successRedirect | `/index` | successful login path
loginUrlPath | `/login` | URL to the login page
noLoggedUrlPath | `/login` | URL to the unlogged page where the authentification is required when trying to log in
Expand Down
18 changes: 10 additions & 8 deletions lib/login-plus.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ loginPlus.Manager = function LoginPlusManager(){
'jpg','png','gif',
'css','js','manifest'
];
this.secret = 'keyboard cat';
this.secret = 'keyboard cat '+Math.random();
this.savedUser = {};
};

Expand All @@ -34,11 +34,13 @@ loginPlus.Manager.prototype.init = function init(app,opts){
opts.unloggedPath = opts.unloggedPath || __dirname+'/../unlogged';
opts.loginPagePath = opts.loginPagePath || __dirname+'/../unlogged/login';
opts.loginPageServe = opts.loginPageServe || MiniTools.serveJade(opts.loginPagePath,false);
opts.baseUrl = opts.baseUrl || '';
opts.baseUrl = opts.baseUrl.replace(/\/$/g,'');
opts.successRedirect = opts.successRedirect || '/index';
opts.loginUrlPath = opts.loginUrlPath || '/login';
opts.noLoggedUrlPath = opts.noLoggedUrlPath || opts.loginUrlPath;
opts.failedLoginUrlPath = opts.failedLoginUrlPath || opts.loginUrlPath;
app.use('/unlogged',extensionServeStatic(opts.unloggedPath, {
app.use(opts.baseUrl+'/unlogged',extensionServeStatic(opts.unloggedPath, {
index: [''],
extensions:[''],
staticExtensions:this.validExts
Expand All @@ -55,16 +57,16 @@ loginPlus.Manager.prototype.init = function init(app,opts){
throw Error('login-plus.init fail "'+fileNameLogin+'" does not exists');
}
});
app.get(opts.loginUrlPath, function(req,res,next){
app.get(opts.baseUrl+opts.loginUrlPath, function(req,res,next){
req.logout();
next();
});
app.get(opts.loginUrlPath, opts.loginPageServe);
app.get(opts.baseUrl+opts.loginUrlPath, opts.loginPageServe);

app.post(opts.loginUrlPath,
app.post(opts.baseUrl+opts.loginUrlPath,
passport.authenticate('local', {
successRedirect: opts.successRedirect,
failureRedirect: opts.failedLoginUrlPath,
successRedirect: opts.baseUrl+opts.successRedirect,
failureRedirect: opts.baseUrl+opts.failedLoginUrlPath,
failureFlash: true
})
);
Expand All @@ -81,7 +83,7 @@ loginPlus.Manager.prototype.init = function init(app,opts){
});

/////// ATENCIÓN NUNCA MENTER ensureLoggedIn dentro de una cadena de promesas. Necesitamos que se ejecute sí o sí
app.use(ensureLoggedIn(opts.noLoggedUrlPath));
app.use(opts.baseUrl,ensureLoggedIn(opts.baseUrl+opts.noLoggedUrlPath));

return promiseChain;
};
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "login-plus",
"description": "login service for express",
"version": "0.3.0",
"version": "0.3.1",
"author": "Codenautas <codenautas@googlegroups.com>",
"license": "MIT",
"repository": "codenautas/login-plus",
Expand All @@ -15,26 +15,26 @@
"connect-ensure-login": "0.1.1",
"connect-flash": "0.1.1",
"express-session": "1.13.0",
"lodash": "4.3.0",
"moment": "2.11.2",
"lodash": "4.6.1",
"moment": "2.12.0",
"passport": "0.3.2",
"passport-local": "1.0.0",

"extension-serve-static": "0.1.6",
"mini-tools": "0.1.4",
"mini-tools": "0.2.3",
"promise-plus": "0.0.6"
},
"devDependencies": {
"body-parser": "1.15.0",
"cookie-parser": "1.4.1",
"expect.js": "0.3.1",
"express": "4.13.4",
"fs-promise": "0.4.1",
"fs-promise": "0.5.0",
"istanbul": "0.4.2",
"jade": "1.11.0",
"mocha": "2.4.5",
"read-yaml-promise": "1.0.2",
"stylus": "0.53.0",
"stylus": "0.54.0",
"supertest": "1.2.0",

"ajax-best-promise": "0.0.7",
Expand Down

0 comments on commit ba24810

Please sign in to comment.