How to use keystone - 10 common examples

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 danielpquinn / keystone-rest / test / models / users.js View on Github external
var keystone = require('keystone'),
  Types = keystone.Field.Types;

var User = new keystone.List('User');

User.add({
  name: { type: Types.Text, required: true, initial: true },
  token: { type: Types.Text, restEditable: false },
  password: { type: Types.Password, required: true, initial: true, restSelected: false },
  posts: { type: Types.Relationship, ref: 'Post', many: true }
});


// Register User
User.register();

module.exports = exports = User;
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 skagitpublishing / connextCMS / keystone-files / keystone.js View on Github external
fs.readFile('public/js/publicsettings.json', 'utf8', function(err, data) {
  //debugger;

  if(err) {
    console.log('Error in keystone.js while trying to read publicsettings.json file.');
    console.log(err);
  } else {

    var publicSettings = JSON.parse(data);

    if(typeof(publicSettings.superUsers) == "string") {
      keystone.set('superusers', [publicSettings.superUsers]);
    } else {
      keystone.set('superusers', publicSettings.superUsers);
    }

    if(typeof(publicSettings.adminUsers) == "string") {
      keystone.set('admins', [publicSettings.adminUsers]);
    } else {
      keystone.set('admins', publicSettings.adminUsers);
    }

    // Start Keystone to connect to your database and initialise the web server
    // Need to be inside the readFile function handler.
    keystone.start();
  }
});
github RyanCCollins / ryancollinsio-v2 / routes / index.js View on Github external
const mainHash = 'ad807fa5016f97e62e7d';
const vendorHash = '158ebf10428e11d2ccc7';

import React from 'react';
import { renderToString } from 'react-dom/server';
import { match, RouterContext } from 'react-router';
import { Provider } from 'react-redux';
import store from '../app/src/store/store.js';
import { routes } from '../app/src/utils/routes.jsx';

const serverApiRoutes = {
  api: importRoutes('./api')
};

if (isDeveloping) {
  keystone.pre('routes', webpackMiddleware(compiler, {
    noInfo: true,
    publicPath: config.output.publicPath
  }));

  keystone.pre('routes', webpackHotMiddleware(compiler, {
    log: console.log // eslint-disable-line
  }));
}

exports = module.exports = function (app) {
  app.use(webpackMiddleware(compiler, {
    noInfo: true,
    publicPath: config.output.publicPath
  }));

  app.use(webpackHotMiddleware(compiler, {
github FlintMade / react-keystone-boilerplate / source / server / server.js View on Github external
onMount: () => {
    console.info('----\n==> ✅  %s is running with Keystone.', config.app.title);
    console.info('==> 💻  Open http://localhost:%s in a browser to view the app.', config.port);

    const app = Keystone.app;

    app.use(compression());
    app.use(favicon(path.join(__dirname, '../../', 'static', 'favicon.ico')));

    app.use(require('serve-static')(path.join(__dirname, '../../', 'static')));

    app.use(cookieParser(process.env.COOKIE_SECRET));

    app.use((req, res) => {
      if (__DEVELOPMENT__) {
        // Do not cache webpack stats: the script file would change since
        // hot module replacement is enabled in the development env
        webpackIsomorphicTools.refresh();
        res.header('Access-Control-Allow-Origin', '*');
      }
      const client = new ApiClient(req);
github keycircle / keyuxt / server / index.js View on Github external
import keystone from 'keystone'
import _ from 'lodash'
import server from './server'

keystone.init({
  name: 'Keystone Boilerplate',
  brand: 'Keystone Boilerplate',
  static: 'public',
  logger: ':method :url :status :response-time ms - :res[content-length]',
  'auto update': false,
  session: true,
  auth: true,
  'user model': 'User',
  compress: true,
  headless: false // true to disable admin
})

keystone.import('../server/models')

keystone.set('locals', {
  _,
github FlintMade / react-keystone-boilerplate / source / server / server.js View on Github external
// Keystone import
import Keystone from 'keystone';
import cookieParser from 'cookie-parser';

import { ReduxRouter } from 'redux-router';
import createHistory from 'history/lib/createMemoryHistory';
import { reduxReactRouter, match } from 'redux-router/server';
import { Provider } from 'react-redux';
import qs from 'query-string';
import getRoutes from '../routes';
import getStatusFromRoutes from '../helpers/getStatusFromRoutes';

const pretty = new PrettyError();

Keystone.init({
  'name': config.app.title,
  'brand': config.app.title,
  'signin logo': ['/logo.jpg', 100, 100],
  'view engine': 'jade',
  'emails': 'templates/emails',
  'session': false,
  'updates': 'updates',
  'auth': true,
  'user model': 'User',
  'auto update': true,
  'cookie secret': process.env.COOKIE_SECRET,
  'headless': process.env.DISABLE_KEYSTONE
});
Keystone.set('routes', require('./routes'));
Keystone.set('port', config.port);
Keystone.import('models');
github internetErik / keystone4-universal-react / server / index.js View on Github external
if(process.env.NODE_ENV === 'production') {
  // keystoneInit['ssl port'] = process.env.SSL_PORT || 443;
  // keystoneInit['ssl'] = 'force';
  // keystoneInit['ssl key'] = process.env.SSL_KEY || '/etc/letsencrypt/live/test.org/privkey.pem';
  // keystoneInit['ssl cert'] = process.env.SSL_CERT || '/etc/letsencrypt/live/test.org/fullchain.pem';

  // This automatic letsencrypt isn't working right now for me
  // keystoneInit['letsencrypt'] = {
  //   email: 'email@test.com',
  //   domains: ['www.test.com', 'test.com'],
  //   register: true,
  //   tos: true,
  // };
}

keystone.init(keystoneInit);

// Load your project's Models
keystone.import('models');

// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js
keystone.set('locals', {
  _: require('lodash'),
  env: keystone.get('env'),
  utils: keystone.utils,
  editable: keystone.content.editable,
});

// Load your project's Routes
keystone.set('routes', require('./routes'));
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: {