A Seneca.js user management plugin.
This open source module is sponsored and supported by Voxgig. |
---|
This module is a plugin for
the Seneca framework. It provides a set of
common user management actions (register
, login
etc.).
npm install seneca
npm install seneca-promisify // dependency
npm install seneca-entity // dependency
npm install @seneca/user
Register a user and then create an automatic login for testing.
const Seneca = require('seneca')
var seneca = Seneca()
.use('promisify')
.use('entity')
.use('user')
var out = await seneca.post('sys:user,register:user', {
handle: 'alice'
})
console.log('USER:', out.user)
out = await seneca.post('sys:user,login:user', {
handle: 'alice',
auto: true
})
console.log('LOGIN:', out.login)
Because Seneca treats messages as first-class citizens, 90% of unit testing can be implemented with message scenarios that also provide detailed usage examples:
- adjust:user,sys:user
- auth:user,sys:user
- change:pass,sys:user
- change:handle,sys:user
- change:email,sys:user
- change:password,sys:user
- check:verify,sys:user
- check:exists,sys:user
- cmd:encrypt,hook:password,sys:user
- cmd:pass,hook:password,sys:user
- get:user,sys:user
- list:user,sys:user
- list:login,sys:user
- list:verify,sys:user
- login:user,sys:user
- logout:user,sys:user
- make:verify,sys:user
- register:user,sys:user
- remove:user,sys:user
- sys:user,update:user
Adjust user status idempotently (activated, etc.).
- active : boolean {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if user found',
user: 'user entity'
}
Authenticate a login using token
- token : string {presence:required}
- user_fields : array {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if login is active',
user: 'user entity',
login: 'user entity'
}
Change user password.
- pass : string
- repeat : string {presence:optional}
- verify : string {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if changed',
user: 'user entity'
}
Change user handle.
- new_handle : string
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if changed',
user: 'user entity'
}
Change user email.
- new_email : string
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if changed',
user: 'user entity'
}
Change user password.
- pass : string
- repeat : string {presence:optional}
- verify : string {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if changed',
user: 'user entity'
}
Check a verfication entry.
- kind : string {presence:optional}
- code : string {presence:optional}
- now : number {presence:optional}
- expiry : boolean {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if valid',
why: 'string coded reason if not valid'
}
Check user exists.
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if user exists',
user: 'user entity'
}
Encrypt a plain text password string.
cmd:encrypt,hook:password,sys:user,pass:foofoobarbar
- Result: {ok:true, pass:encrypted-string, salt:string}
- salt : string {presence:optional}
- pass : string {presence:optional}
- password : string {presence:optional}
- rounds : number {presence:optional}
{
ok: '_true_ if encryption succeeded',
pass: 'encrypted password string',
salt: 'salt value string'
}
Validate a plain text password string.
cmd:pass,hook:password,sys:user,pass:goodpassword
- Result: {ok:true}
- salt : string
- pass : string
- proposed : string
- rounds : number {presence:optional}
{
ok: '_true_ if password is valid',
why: 'string coded reason if not valid'
}
Get user details
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if user found',
user: 'user entity'
}
List users
- active : boolean {presence:optional}
- q : object {presence:optional}
{
ok: '_true_ if user found',
items: 'user entity item list'
}
List logins for a user
- active : boolean {presence:optional}
- login_q : object {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if user found',
items: 'user entity item list'
}
Create a verification entry (multiple use cases).
- kind : string
- code : string {presence:optional}
- once : boolean {presence:optional}
- valid : boolean {presence:optional}
- custom : object {presence:optional}
- expire_point : number {presence:optional}
- expire_duration : number {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if user found',
verify: 'verify entity'
}
Login user
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
- auto : boolean {presence:optional}
- pass : string {presence:optional}
{
ok: '_true_ if user logged in',
user: 'user entity',
login: 'login entity'
}
Login user
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
- token : string {presence:optional}
- login_in : string {presence:optional}
- login_q : object {presence:optional,default:{}}
- load_logins : boolean {presence:optional}
{
ok: '_true_ if user logged in',
count: 'number of logouts'
}
Create a verification entry (multiple use cases).
- kind : string
- code : string {presence:optional}
- once : boolean {presence:optional}
- valid : boolean {presence:optional}
- custom : object {presence:optional}
- expire_point : number {presence:optional}
- expire_duration : number {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if user found',
verify: 'verify entity'
}
Register a new user
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- user : object {unknown:true}
- user_data : object {unknown:true}
{
ok: '_true_ if user registration succeeded',
user: 'user entity'
}
Remove a user
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if user removed',
user: 'user entity'
}
Update a user
- user : object {presence:optional}
- id : string {presence:optional}
- user_id : string {presence:optional}
- email : string {presence:optional}
- handle : string {presence:optional}
- nick : string {presence:optional}
- q : object {presence:optional}
- fields : array {presence:optional}
{
ok: '_true_ if user updated',
user: 'user entity'
}
Copyright (c) 2010-2020, Richard Rodger and other contributors. Licensed under MIT.