userific

User registration and authentication server

Userific

User registration and authentication interface. Any userific backend should follow work with the examples below

Installation

npm install -S userfic

Features

Any module that implements the userific interface must support the following

  • Registration
  • Authentication
  • Change Email
  • Change Password
var inspect = require('eyespect').inspector()
var userific = require('userific')
var userData = {
  email: 'foo@example.com',
  password: 'barPassword'
}
 
userific.register(userData, function(erruserModel) {
  if (err)  {
    inspect(err, 'error registering user')
    return
  }
  inspect(userModel, 'user registered')
})

The register function should return an error object as the first parameter of the callback if the registration fails. A user object is passed as the second parameter if the registration succeeds

To authenticate a user follow the code below. For example you could use this in a login route post handler to allow users to login to a website

var inspect = require('eyespect').inspector()
var userific = require('userific')
var userData = {
  email: 'foo@example.com',
  password: 'barPassword'
}
 
userific.authenticate(userData, function(erruserModel) {
  if (err)  {
    inspect(err, 'error registering user')
    return
  }
  inspect(userModel, 'user authenticated')
})

To change the email for a user follow the code below. Note that you must pass both email and newEmail

var inspect = require('eyespect').inspector()
var userific = require('userific')
var userData = {
  currentEmail: 'foo@example.com',
  newEmail: 'bar@example.com'
}
 
userific.changeEmail(userData, function(erruserModel) {
  if (err)  {
    inspect(err, 'error registering user')
    return
  }
  inspect(userModel, 'user email changed')
})

To change the password for a user follow the code below. Note that you must pass both password and newPassword

var inspect = require('eyespect').inspector()
var userific = require('userific')
var userData = {
  currentEmail: 'foo@example.com',
  newEmail: 'bar@example.com'
}
 
userific.changeEmail(userData, function(erruserModel) {
  if (err)  {
    inspect(err, 'error registering user')
    return
  }
  inspect(userModel, 'user email changed')
})