npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

keystone-greeter

v0.3.5

Published

Stand-alone signin and registration module for Keystone; built with ReactJS

Downloads

10

Readme

Keystone Greeter

A KeystoneJS signin / registration form (ReactJS)

Install

npm install keystone-greeter

//or add to package.json
"dependencies": {
	"keystone-greeter": "~0.3.3"
}

screenshot screenshot screenshot

The compiled client ReactJS file is located at:

node_modules/keystone_greeter/public/snowpi/js/lib/react/build/greeter.js

The client jsx is included at:

node_modules/keystone_greeter/public/snowpi/js/lib/react/jsx/greeter.js

Setup

var keystone = require('keystone');
var greeter = require('keystone-greeter');

// add the greeter in your routes file
keystone.set('routes', function(app) {
	
	/**
	* set the 2nd parameter true to add statics without using keystone.set('static').
	* You must do this to run .init in Keystone's route setup.
	*
	* Set to false if you set init right sfter Keystone.init
	* if false we grab the statics with `keystone.get('static')`
	* convert it to an Array and push our static routes on.
	*
	* DEFAULT: false
	*
	* **/
	
	greeter.init({ keystone: keystone }, true);
	
	greeter.add('/greeter');
	
	// change the first login field
	greeter.setField('login', 'text', 'A-username', {
		label: 'username',
		field: 'username',
		//regex: ["^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$", "gi"],
		model: {
			field: 'email',
			unique: true
		},
		required: true
	});
});

Configuration

Locales

The locales file will be created on first run. You can create additional locales without them being overwritten. Copy the en.json file and replace the values.

node_modules/keystone_greeter/locales
-- node_modules/keystone_greeter/locales/en.json

Debugging

greeter.set('debug', true);
Most items need to be set before calling greeter.add:

The User Model defaults to keystone.get('user model'). Override with:

greeter.set('user model','myUsers')

The greeter uri defaults to /greeter and can be set 3 ways in overriding order:

keystone.set('sign url','/greeter') 

greeter.set('greeter','/greeter') //this overrides keystone.set

//set the page on add
greeter.add('/greeter') //this overrides everything

The success redirect page is inherited from Keystone

//set the redirect 
keystone.set('signin redirect','/')

Set the redirect timer for successful login or registration in milliseconds

greeter.set('redirect timer',0) //default = 5000 (5 seconds)

Style Sheets

Control the stylesheets

greeter.set('greeter style',true), // include default css
greeter.set('keystone style',true), // include /styles/site.min.css
greeter.set('custom style','/styles/custom.css'), // include custom css

The default is to include default greeter css first and /styles/site.min.css second so that your css automatically overrides the greeter out of the box. Custom styles is false unless explicitly set.

Registration

User registration can be toggled before calling greeter.add:

//these are the default values
greeter.set('allow register', true),
greeter.set('new user can admin', false),

Default Fields

this.setField('login', 'text', 'A-username', {
	label: Text('email'),
	field: 'email',
	regex: ["^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$", "gi"],
	model: {
		field: 'email',
		unique: false
	},
	required: true
});
this.setField('login', 'password', 'B-password', {
	label: Text('password'),
	field: 'password',
	regex: ["^(?=.*[0-9]+.*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{6,}$", "g"],
	required: true
});

this.setField('register', 'text', 'A-username', {
	label: Text('email'),
	field: 'email',
	regex: ["^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$", "gi"],
	required: true,
	model: {
		field: 'email',
		unique: true
	},
});
this.setField('register', 'password', 'B-password', {
	label: Text('password'),
	field: 'password',
	required: true,
	regex: ["^(?=.*[0-9]+.*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{6,}$", "g"]
});
this.setField('register', 'password', 'C-confirm', {
	label: Text('confirm'),
	field: 'confirm',
	required: true,
	dependsOn: 'B-password' 
});

this.setField('register', 'text','D-name', {
	label: Text('name'),
	'field': 'name',
	modify: ['first','last'],
	modifyParameter: ' ',
	placeholder: 'first last'
});

Add or change fields

The order is determined by the third parameter.

The first signin form field is username. We will use this to check signins.

	greeter.setField('login', 'text', 'A-username', {
		label: 'username',
		field: 'username',
		//regex: ["^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$", "gi"],
		model: {
			field: 'email',
		},
		required: true
	});
	greeter.setField('register', 'text', 'A-username', {
		label: 'username',
		field: 'username',
		//regex: ["^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$", "gi"],
		required: true,
		model: {
			field: 'email',
			unique: true
		},
	});
    

It can accept a modify Array to split a text field into an Object for registration:

this.setField('register', 'text','D-name', {
	label: Text('name'),
	'field': 'name',
	modify: ['first','last'],
	modifyParameter: ' ',
	placeholder: 'first last'
});

code

function modify(value, modify ) {
				
	if(!value) return false;
	if(!modify.modify) return false;
	
	var save = {};									
	var modifiers = modify.modify;
	var modifyParameter = modify.modifyParameter || ' ';
	
	if(modifiers instanceof Array && modifiers.length > 1) {
		
		var splitName = value.split(' ');
												
		save[modifiers[0]] = splitName[0];
		var cname;
		if(splitName.length > 2) {
			
			for(var i=1;i<=splitName.length;i++) {
				cname+=' ' + (splitName[i] || '');
			}
			
		} else {
			cname = splitName[1] || '';
		}
		save[modifiers[1]] = cname;
	
	} else if(modifiers instanceof Array){
		
		save[modifiers[0]] = req.body.name;
		
	} else if(typeof modifiers === 'string'){
		
		save[modifiers] = req.body.name;
		
	} else {
		
		save = req.body.name;
		
	}
	return save;
}

Return Messages

Change the return message contents

	greeter.set('message valid credentials', 'a valid username and password are required');
	greeter.set('message welcome', 'Welcome back {user}. ');
	greeter.set('message welcome login', 'Welcome back.  Please signin');
	greeter.set('message registration closed', 'registration is currently closed');
	greeter.set('message current user', 'You are currently signed in.  Do you want to <a href="/keystone/signout">sign out</a>? ');
	greeter.set('message bad token', 'bad request token.  <a href="javascript:location.reload()">refresh</a>');
	greeter.set('message username taken', 'the username requested is not available');
	greeter.set('message failed register', 'there was a problem creating your new account.');
	greeter.set('message register all fields', 'please fill in username, password and password again...');

This will overwrite the built in i18n locales text. To continue using locales do something similiar:

var Text = i18n.__;
i18n.configure({
	locales:['en'],
	directory: __dirname + '/locales'
});
greeter.set('message valid credentials', Text('a valid username and password are required'));