How to use the keystone.list 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 / lib / auth / google.js View on Github external
var async = require('async'),
	_ = require('underscore');

var passport = require('passport'),
	passportGoogleStrategy = require('passport-google-oauth').OAuth2Strategy;

var keystone = require('keystone'),
	User = keystone.list('User');

var credentials = {
	clientID: process.env.GOOGLE_CLIENT_ID,
	clientSecret: process.env.GOOGLE_CLIENT_SECRET,
	callbackURL: process.env.GOOGLE_CALLBACK_URL,
	
	scope: 'profile email'
};

exports.authenticateUser = function(req, res, next)
{
	// Begin process
	console.log('============================================================');
	console.log('[services.google] - Triggered authentication process...');
	console.log('------------------------------------------------------------');
github JedWatson / keystone-forum / models / Topic.js View on Github external
var topic = this;

	if (!topic._bubbleUpdate) {
		return;
	}
	
	if (topic.author) {
		keystone.list('User').model.findById(topic.author).exec(function(err, user) {
			return user && user.wasActive().save();
		});
	}

	// touch the topic's tags to make them update their topic count
	if (topic.tags) {
		keystone.list('Tag').model.find().where('_id').in(topic.tags).exec(function(err, tags) {
			if (err) {
				console.error(err)	
			} else {
				tags.forEach(function(tag) {
					tag.save();
				});
			}
		});
	}

	// archive the topic's replies when it's archived
	if (topic.state == 'archived') {
		keystone.list('Reply').model.find().where( 'topic', topic.id ).exec(function(err, results) {
			if (err) {
				console.error(err)	
			} else {
github JedWatson / keystone-forum / models / Reply.js View on Github external
Reply.schema.methods.notifyTopicWatchers = function(req, res, next) {
	
	var reply = this;
	var data = {};
	
	
	// TODO find a better way to populate/get the reply author
	
	keystone.list('Reply').model.findById(reply.id).populate('author', 'name').exec(function(err, result) {
		if (err || !result) return next(err);
		data.author = result.author;
	});
	
	keystone.list('Topic').model.findById(reply.topic).populate('watchedBy').exec(function(err, topic) {
		
		if (err || !topic.watchedBy.length) return next(err);
		
		topic.watchedBy.forEach(function(watcher) {
			new keystone.Email('new-reply').send({
				subject: 'Re: ' + topic.name,
				topic: topic,
				reply: reply,
				baseURL: req.protocol + '://' + req.get('host'),
				to: watcher.email,
				from: {
github JedWatson / sydjs-site / lib / auth / google.js View on Github external
var _ = require('lodash');
var async = require('async');
var keystone = require('keystone');
var passport = require('passport');
var passportGoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
var User = keystone.list('User');

var credentials = {
	clientID: process.env.GOOGLE_CLIENT_ID,
	clientSecret: process.env.GOOGLE_CLIENT_SECRET,
	callbackURL: process.env.GOOGLE_CALLBACK_URL,

	scope: 'profile email'
};

exports.authenticateUser = function(req, res, next) {
	var self = this;

	var redirect = '/auth/confirm';
	if (req.cookies.target && req.cookies.target == 'app') redirect = '/auth/app';

	// Begin process
github JedWatson / sydjs-site / models / Meetup.js View on Github external
Meetup.schema.methods.notifyAttendees = function(req, res, next) {
	var meetup = this;
	keystone.list('User').model.find().where('notifications.meetups', true).exec(function(err, attendees) {
		if (err) return next(err);
		if (!attendees.length) {
			next();
		} else {
			attendees.forEach(function(attendee) {
				new Email('new-meetup', { transport: 'mandrill', engine: 'jade', root: 'templates/emails' }).send({
					attendee: attendee,
					meetup: meetup,
					host: 'http://www.sydjs.com',
				}, {
					subject: 'New meetup: ' + meetup.name,
					to: attendee.email,
					from: {
						name: 'SydJS',
						email: 'hello@sydjs.com'
					}
github zapkub / cu-vivid-museum-wiki / legacy / server / updates / 0.0.5-plants.js View on Github external
module.exports = (done) => {
  const Plant = keystone.list('Plant')
  const plants = require('../../seed/json/plant.json')
  Plant.model.create(plants, (err) => {
    if (err) done(err)
    done()
  })
}
github JedWatson / sydjs-site / routes / middleware.js View on Github external
exports.loadSponsors = function(req, res, next) {
	keystone.list('Organisation').model.find().sort('name').exec(function(err, sponsors) {
		if (err) return next(err);
		req.sponsors = sponsors;
		res.locals.sponsors = sponsors;
		next();
	});
}