Skip to content

Instantly share code, notes, and snippets.

View VinayaSathyanarayana's full-sized avatar

Vinaya Sathyanarayana VinayaSathyanarayana

View GitHub Profile
@VinayaSathyanarayana
VinayaSathyanarayana / keystone.js
Created November 15, 2017 17:40 — forked from riyadhalnur/keystone.js
Add more options to the express app when using KeystoneJS
var keystone = require('keystone');
var express = require('express');
var body = require('body-parser');
var helmet = require('helmet');
var app = express();
app.use(body.urlencoded({ extended: false }));
app.use(body.json());
app.use(helmet());
@VinayaSathyanarayana
VinayaSathyanarayana / signup.jade
Created November 15, 2017 17:40 — forked from robksawyer/signup.jade
A pretty basic registration form for KeystoneJS.
// @file signup.jade
// @path /templates/views/user/signup.jade
// @description Form that user sees when signing up.
//
extends ../../layouts/default
block intro
.container
h1= 'Sign up for Little B.O.M'
@VinayaSathyanarayana
VinayaSathyanarayana / notes.md
Created November 15, 2017 17:38 — forked from JedWatson/notes.md
Notes on how to create a new field type for Keystone

Creating new Field Types for KeystoneJS

We're currently working on making it easier to add new field types to KeystoneJS as plugins.

In the meantime, if you'd like to work on your own field type, hopefully this guide will point you in the right direction.

Keystone fields require the following:

  • a {fieldType}.js file in ./lib/fieldTypes that controls the field and encapsulates options support, underscore functions, validation and updating
  • the {fieldType}.js file needs to be included by ./lib/fieldTypes/index.js

keystonejs notes

Creating custom keystone Lists (models)

  • keystone lists or models basically map back to mongodb collections
  • each property you add into the model object will become a field in the keystone admin UI. The model itself will become a mongo collection in the db and the fields will also be stored under the collection.
  • each property you define in the model needs to have a type. Types are defined by the keystone api. There are many types that are built into keystone a list of them can be found Here

How to create a new list

How to set up a NodeJS website with Authentication and Back office (and Blog)

In this tutorial we're going to build a NodeJS website with the following features:

  • User authentication
  • Back office
  • Blog (optional)

The first to parts of the tutorial are meant to quickly set you up and running. The third part is a more in depth explanation of some points I find important, so feel free to read them later as you need.

Keystone Roles & Permissions Support

The following documents the user permission support in keystone based on the support being added via PR #2111. Permissions are based on roles. If a user has a role and the list also specifies that role for any of its CRUD operations then it is permissive for the user to perform whichever CRUD operation matches the role. All users must define, at least, one role. The following are guidelines for adding role/permission support to your application:

Define a Role List Model:

@VinayaSathyanarayana
VinayaSathyanarayana / Readme.md
Created November 15, 2017 17:33 — forked from jeffreypriebe/Readme.md
Keystone Admin User Role Permissions

The admin-user-roles-permissions has basic support for handling user permissions in the Keystone admin area.

It is comprised of basic parts:

  1. Additional fields on the user model (mentioned in steps below and also the User.js file)

    • isUserAdmin, isSuperAdmin and isPWD (the last one has permissions to edit any other user always)
    • Simply, each user has the ability to edit self and all users with fewer permissions.
  2. Exposure of these values (via virtuals) to the React admin/src/views/item.js route and to the server side jade templates and express routes.

To implement API authentication in KeystoneJS, you need the following:

For key based authentication

  • Middleware that validates the key in the request body or a header

For session based authentication

  • An endpoint that handles signin
  • An endpoint that handles signout
@VinayaSathyanarayana
VinayaSathyanarayana / main.js
Created July 25, 2017 15:27 — forked from lukemelia/main.js
letsencrypt with node and heroku
var LE = require('letsencrypt');
var pem = require('pem');
var RSVP = require('rsvp');
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var domains, herokuAppName, duplicate;
if (process.env.YAPP_ENV === 'qa') {
domains = ['heroku.yappqa.us', 'my.yappqa.us', 'api.yappqa.us', 'support.yappqa.us' ];
@VinayaSathyanarayana
VinayaSathyanarayana / passport_node_acl_example.js
Created July 18, 2017 17:55 — forked from danwit/passport_node_acl_example.js
Authentication and authorization with passportjs + node_acl + mongo + express
/**
* Simple authentication and authorization example with passport, node_acl,
* MongoDB and expressjs
*
* The example shown here uses local userdata and sessions to remember a
* logged in user. Roles are persistent all the way and applied to user
* after logging in.
*
* Usage:
* 1. Start this as server