Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow formage to work (authenticate users) without sessions #91

Open
Antonded opened this issue May 5, 2014 · 1 comment
Open

Allow formage to work (authenticate users) without sessions #91

Antonded opened this issue May 5, 2014 · 1 comment
Assignees
Milestone

Comments

@Antonded
Copy link

Antonded commented May 5, 2014

I'm trying to run formage and get this error (When accessing /admin). I can login going to admin/login but after submitting credentials i get TypeError: Cannot set property '_FormageUser' of undefined

TypeError: Cannot set property '_loginReferrer' of undefined
    at /Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/formage/lib/controllers.js:540:52
    at callbacks (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:164:37)
    at param (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:138:11)
    at pass (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:173:5)
    at Object.router (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:33:10)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.json [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/json.js:53:37)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.urlencoded [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/urlencoded.js:51:37)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at b (domain.js:183:18)
    at Domain.run (domain.js:123:23)
    at Object.DomainsMiddleware [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/formage/node_modules/nodestrum/index.js:54:7)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.expressInit [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/middleware.js:30:5)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.query [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:198:3)
    at Object.fn [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/application.js:120:11)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:165:78)
    at resume (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/static.js:60:7)
    at SendStream.error (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/static.js:73:37)
    at SendStream.EventEmitter.emit (events.js:95:17)
    at SendStream.error (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/send/lib/send.js:147:51)
    at SendStream.onStatError (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/send/lib/send.js:248:48)
    at /Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/send/lib/send.js:320:26
    at Object.oncomplete (fs.js:107:15)
GET /admin 500 13ms - 16b
TypeError: Cannot set property '_loginReferrer' of undefined
    at /Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/formage/lib/controllers.js:540:52
    at callbacks (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:164:37)
    at param (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:138:11)
    at pass (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:173:5)
    at Object.router (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/router/index.js:33:10)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.json [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/json.js:53:37)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.urlencoded [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/urlencoded.js:51:37)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at b (domain.js:183:18)
    at Domain.run (domain.js:123:23)
    at Object.DomainsMiddleware [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/formage/node_modules/nodestrum/index.js:54:7)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.expressInit [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/middleware.js:30:5)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.query [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Function.app.handle (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:198:3)
    at Object.fn [as handle] (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/lib/application.js:120:11)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at next (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/proto.js:165:78)
    at resume (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/static.js:60:7)
    at SendStream.error (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/connect/lib/middleware/static.js:73:37)
    at SendStream.EventEmitter.emit (events.js:95:17)
    at SendStream.error (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/send/lib/send.js:147:51)
    at SendStream.onStatError (/Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/send/lib/send.js:248:48)
    at /Users/antonded/Projects/КупиНомер/kupinomer-server/node_modules/express/node_modules/send/lib/send.js:320:26
    at Object.oncomplete (fs.js:107:15)

My code is:

var express         = require('express');
var path            = require('path');
var passport        = require('passport');
var config          = require('./libs/config');
var log             = require('./libs/log')(module);
var oauth2          = require('./libs/oauth2');
var async           = require('./node_modules/async');
var parser          = require('./parser');
var apns            = require('./libs/apns');
var mongoose    = require('mongoose');

require('./libs/auth');
var app = express();

var AdvertisementModel = require('./libs/mongoose').AdvertisementModel;
var UnregisteredUserModel = require('./libs/mongoose').UnregisteredUserModel;

app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(passport.initialize());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, "public")));

require('formage').init(app, express, mongoose.models, {
    title: 'Admin',
    root: '/admin',
    default_section: 'main',
    username: 'admin',
    password: 'admin',
    admin_users_gui: true
});

app.use(function(req, res, next){
    res.status(404);
    log.debug('Not found URL: %s',req.url);
    res.send({ error: 'Not found' });
    return;
});

app.use(function(err, req, res, next){
    res.status(err.status || 500);
    log.error('Internal error(%d): %s',res.statusCode,err.message);
    res.send({ error: err.message });
    return;
});
@refack
Copy link
Member

refack commented May 5, 2014

For ver 2.x.x formage user authentication is based on sessions.
Simplest solution is to add the cookieParser and cookieSession middlewares to your app

...
app.use(express.cookieParser('magical secret admin'));
app.use(express.cookieSession({cookie: { maxAge: 1000 * 60 * 60 *  24 }}));
...

@refack refack changed the title TypeError: Cannot set property '_loginReferrer' of undefined Allow formage to work (authenticate users) without sessions May 5, 2014
@refack refack added this to the 3.0.0 milestone May 5, 2014
@refack refack self-assigned this May 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants