How to use the keystone.session function in keystone

To help you get started, we’ve selected a few keystone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JedWatson / keystone-forum / routes / auth / google.js View on Github external
function(cb) {
			
			// TODO: Work out in what cases we may actually want to sign out the user
			return cb();
			
			if (!req.user) return cb();
			
			keystone.session.signout(req, res, function() {
				return cb();
			});
			
		}
github JedWatson / keystone-forum / routes / auth / twitter.js View on Github external
function(cb) {
			
			// TODO: Work out in what cases we may actually want to sign out the user
			return cb();
			
			if (!req.user) return cb();
			
			keystone.session.signout(req, res, function() {
				return cb();
			});
			
		}
github keystonejs / keystone-test-project / express.js View on Github external
keystone.init(config.options);
keystone.import('models');
keystone.set('locals', config.locals);
keystone.set('routes', require('./routes'));
keystone.set('nav', config.nav);

keystone.initDatabaseConfig();
keystone.initExpressSession();

app.use(compression());
app.use('/keystone', keystone.Admin.Server.createStaticRouter(keystone));
app.use(express.static('public'));

app.use(keystone.get('session options').cookieParser);
app.use(keystone.expressSession);
app.use(keystone.session.persist);
app.use(require('connect-flash')());

app.use(morgan('tiny'));
app.use('/keystone', keystone.Admin.Server.createDynamicRouter(keystone));

app.use(function (req, res) {
	res.redirect('/keystone');
});

keystone.openDatabaseConnection(function () {
	var server = app.listen(process.env.PORT || 3001, function () {
		console.log('-------------------------------');
		console.log('Express server ready on port %d', server.address().port);
		console.log('-------------------------------');
	});
});
github JedWatson / keystone-forum / routes / auth / confirm.js View on Github external
console.log('------------------------------------------------------------');
		
		var onSuccess = function(user) {
			console.log('[auth.confirm] - Successfully signed in.');
			console.log('------------------------------------------------------------');
			return res.redirect('/settings');
		}
		
		var onFail = function(err) {
			console.log('[auth.confirm] - Failed signing in.', err);
			console.log('------------------------------------------------------------');
			req.flash('error', 'Sorry, there was an issue signing you in, please try again.');
			return res.redirect('/login');
		}
		
		keystone.session.signin(String(locals.existingUser._id), req, res, onSuccess, onFail);
	
	}
github JedWatson / sydjs-site / lib / services / twitter.js View on Github external
console.log('------------------------------------------------------------');
			
			return callback();
		
		}
		
		var onFail = function(err) {
			
			console.log("[services.twitter] - Failed signing in.");
			console.log('------------------------------------------------------------');
			
			return callback(true);
			
		}
		
		keystone.session.signin( String(data.sydjsUser._id), req, res, onSuccess, onFail);
	
	}
github JedWatson / sydjs-site / routes / api / app / signin-service.js View on Github external
date: new Date().getTime(),
				userId: user.id
			});
		}
		
		var onFail = function(err) {
			console.log('[api.app.service]  - Failed signing in.', err);
			console.log('------------------------------------------------------------');
			return res.apiResponse({
				success: false,
				session: false,
				message: (err && err.message ? err.message : false) || 'Sorry, there was an issue signing you in, please try again.'
			});
		}
		
		keystone.session.signin(String(locals.existingUser._id), req, res, onSuccess, onFail);
	
	}
github JedWatson / sydjs-site / routes / auth / confirm.js View on Github external
console.log('------------------------------------------------------------');
		
		var onSuccess = function(user) {
			console.log('[auth.confirm] - Successfully signed in.');
			console.log('------------------------------------------------------------');
			return res.redirect(req.cookies.target || '/me');
		}
		
		var onFail = function(err) {
			console.log('[auth.confirm] - Failed signing in.', err);
			console.log('------------------------------------------------------------');
			req.flash('error', 'Sorry, there was an issue signing you in, please try again.');
			return res.redirect('/signin');
		}
		
		keystone.session.signin(String(locals.existingUser._id), req, res, onSuccess, onFail);
	
	}
github JedWatson / sydjs-site / routes / views / session / join.js View on Github external
], function(err){
			
			if (err) return next();
			
			var onSuccess = function() {
				return res.redirect('/me');
			}
			
			var onFail = function(e) {
				req.flash('error', 'There was a problem signing you in, please try again.');
				return next();
			}
			
			keystone.session.signin({ email: req.body.join_email, password: req.body.join_password }, req, res, onSuccess, onFail);
			
		});
github justinhelmer / universal-javascript-vue / server / routes / api / user.js View on Github external
app.post(base + '/user/logout', (req, res) => {
    keystone.session.signout(req, res, function(err) {
      uidCookie.remove(req, res);
      responseHandler(res, err, {});
    });
  });
github JedWatson / keystone-forum / routes / views / signin.js View on Github external
var onSuccess = function() {
			if (locals.journeyOrigin) {
				res.redirect(locals.journeyOrigin + (locals.journeyOrigin.match('/topic/') ? '?performFunction=focusOnCommentField' : ''));
				req.session.journeyOrigin = null;
			} else {
				res.redirect('/settings');
			}
		}
		
		var onFail = function() {
			req.flash('error', 'Your username or password were incorrect, please try again.');
			return next();
		}
		
		keystone.session.signin({ email: req.body.signin_email, password: req.body.signin_password }, req, res, onSuccess, onFail);
		
	});