@alu0100792218/auth
v1.0.2
Published
A package for register and authorize users
Downloads
10
Readme
Description
JavaScript module for protect data with a simple middleware that control the authentication.
Instalation and use
To install:
npm install @alu0100792218/auth
To use it:
Install express dependencies and create a server. You can see a working example below:
const ip = require("ip");
const express = require('express');
const app = express();
const session = require('express-session');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const auth = require('@alu0100792218/auth');
app.set('views', __dirname + '/node_modules/@alu0100792218/auth/views/'); //Configuramos el directorio de vistas
app.set('view engine', 'ejs');
app.use(cookieParser());
app.use(bodyParser.urlencoded({extended : false})); //Para recuperar parámetros de peticiones post
app.use(session({
secret: '2C44-4D44-WppQ38S',
resave: true,
saveUninitialized: true
}));
app.use('/', auth({ passwordFile: './users.json',
pathToProtect: './src',
loginView: 'formulariologin',
fullLoginView: 'logincompleto',
logoutView: 'logout',
errorLoginView: 'errorlogin',
registerFormView: 'formularioregistro',
errorRegisterView: 'errorregister',
registeredView: 'registrado',
}));
app.use('/scripts', express.static(__dirname + '/node_modules/xregexp/'));
app.use('/script', express.static(__dirname + '/node_modules/@ull-esit-pl/uninums'));
app.get('/', function(req,res){
res.render('index');
});
// listen on all addresses
const server = app.listen(8080, '0.0.0.0', function () {
const port = server.address().port;
console.log('Servidor escuchando en el puerto: ' + port);
});