Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

life_star-auth

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

life_star-auth - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

code-pump.js

52

lib/http-handler.js

@@ -21,2 +21,3 @@ /*global require,process,setTimeout*/

usersDefaultWorld: "/users/%USERNAME%/start.html",
requireLogin: true,
paths: {

@@ -189,24 +190,35 @@ login: '/login',

// make sure those functions cannot be overriden in case the path is /login
app.use(this.config.paths.login, function(req, res, next) {
var data = req.body;
handler.userDB.findUserByCookie(req.livelySession, function(err, user) {
if (err || !user || (data && (data.password || data.passwordHash))) {
if (req.method == 'GET')
return LoginPage.renderLogin(handler, req, res, next);
else if (req.method == 'POST')
return handler.tryLogin(req, res, next);
}
next();
var login = this.config.paths.login,
register = this.config.paths.register,
logout = this.config.paths.logout,
currentUser = this.config.paths.currentUser,
checkPassword = this.config.paths.checkPassword,
userExists = this.config.paths.userExists,
listUsers = this.config.paths.listUsers;
if (login) {
// make sure those functions cannot be overriden in case the path is /login
app.use(login, function(req, res, next) {
var data = req.body;
handler.userDB.findUserByCookie(req.livelySession, function(err, user) {
if (err || !user || (data && (data.password || data.passwordHash))) {
if (req.method == 'GET')
return LoginPage.renderLogin(handler, req, res, next);
else if (req.method == 'POST')
return handler.tryLogin(req, res, next);
}
next();
});
});
});
}
app.get(this.config.paths.register, LoginPage.renderRegister.bind(LoginPage, handler));
app.post(this.config.paths.register, handler.tryRegister.bind(handler));
app.all(this.config.paths.logout, handler.logout.bind(handler));
app.get(this.config.paths.currentUser, handler.renderCurrentUserInfo.bind(handler));
app.post(this.config.paths.currentUser, handler.modifyCurrentUserInfo.bind(handler));
app.post(this.config.paths.checkPassword, handler.checkPassword.bind(handler));
app.post(this.config.paths.userExists, handler.userExists.bind(handler));
app.get(this.config.paths.listUsers, handler.listUsers.bind(handler));
register && app.get(register, LoginPage.renderRegister.bind(LoginPage, handler));
register && app.post(register, handler.tryRegister.bind(handler));
logout && app.all(logout, handler.logout.bind(handler));
currentUser && app.get(currentUser, handler.renderCurrentUserInfo.bind(handler));
currentUser && app.post(currentUser, handler.modifyCurrentUserInfo.bind(handler));
checkPassword && app.post(checkPassword, handler.checkPassword.bind(handler));
userExists && app.post(userExists, handler.userExists.bind(handler));
listUsers && app.get(listUsers, handler.listUsers.bind(handler));

@@ -213,0 +225,0 @@ UserDatabase.fromFile(this.config.usersFile, function(err, db) {

{
"name": "life_star-auth",
"version": "0.1.2",
"version": "0.1.3",
"author": "Robert Krahn <robert.krahn@gmail.com>",

@@ -10,3 +10,4 @@ "description": "Authentication and authorization for Lively Web servers",

"event-stream": "^3.1.7",
"underscore": "^1.7.0"
"underscore": "^1.7.0",
"lively.lang": "*"
},

@@ -13,0 +14,0 @@ "devDependencies": {

@@ -6,6 +6,6 @@ /*global module, console, setTimeout, __dirname*/

var path = require("path"),
async = require('async'),
util = require('util'),
fs = require('fs'),
var path = require("path"),
async = require('async'),
util = require('util'),
fs = require('fs'),
testHelper = require('life_star/tests/test-helper'),

@@ -16,16 +16,17 @@ lifeStarTest = require('life_star/tests/life_star-test-support'),

serverConf = {
fsNode: path.join(__dirname, "test-dir")
},
livelyConfig = {
userAuthEnabled: true,
cookieField: "test-auth-cookie",
usersFile: authConfFile,
authPaths: {
login: '/test-login',
register: '/test-register',
logout: '/test-logout',
currentUser: '/test-current-user',
checkPassword: '/test-check-password',
userExists: '/test-users-exists',
listUsers: '/test-list-users'
fsNode: path.join(__dirname, "test-dir"),
authConf: {
enabled: true,
cookieField: "test-auth-cookie",
usersFile: authConfFile,
requireLogin: true,
paths: {
login: '/test-login',
register: '/test-register',
logout: '/test-logout',
currentUser: '/test-current-user',
checkPassword: '/test-check-password',
userExists: '/test-users-exists',
listUsers: '/test-list-users'
}
}

@@ -39,4 +40,2 @@ };

"test-dir": {"bar.js": "content 123", "foo.html": "<h1>hello world</h1>"}});
global.lively = { Config: livelyConfig };
global.lively.Config.get = function(item) { return this[item]; }
helper.createUserAuthConf(authConfFile, {

@@ -60,3 +59,3 @@ "users": [

test.equals(302, res.statusCode);
test.equals('Moved Temporarily. Redirecting to /test-login?redirect=%252Ffoo.html', res.body);
test.ok(String(res.body).match(/Redirecting to \/test-login\?redirect=%252Ffoo.html/), "Redirect response: " + String(res.body));
test.done();

@@ -75,3 +74,3 @@ });

function(res) {
test.equals('Moved Temporarily. Redirecting to /test-login?note=Login%2520failed!', res.body);
test.ok(String(res.body).match(/Redirecting to \/test-login\?note=Login%2520failed\!/, res.body));
test.deepEqual({}, helper.cookieFromResponse(res));

@@ -86,3 +85,3 @@ next();

function(res) {
test.equals('Moved Temporarily. Redirecting to /foo.html', res.body);
test.ok(String(res.body).match(/Redirecting to \/foo.html/, res.body));
test.deepEqual({

@@ -110,3 +109,3 @@ 'test-auth-cookie': {

function(res) {
test.equals('Moved Temporarily. Redirecting to /test-register?note=Error:%20Invalid%20email:%20thisisnoemail', res.body);
test.ok(String(res.body).match(/Redirecting to \/test-register\?note=Error:%20Invalid%20email:%20thisisnoemail/, res.body));
next();

@@ -121,3 +120,3 @@ });

function(res) {
test.equals('Moved Temporarily. Redirecting to /welcome.html', res.body);
test.ok(String(res.body).match(/Redirecting to \/welcome.html/, res.body));
var cookie = helper.cookieFromResponse(res)["test-auth-cookie"];

@@ -124,0 +123,0 @@ test.equals("user3", cookie && cookie.username);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc