npm-login-register is handle all user related basic operations such as user registration,user login,check user token, change user password and forgot password functionality in relative database.
This plugin is develop to cut development task for all above basic functionalities. And for all, you need to just install npm package and implement followings methods as per your need.
Currently this package is only for MongoDB users.
npm install npm-login-register
Change DB Host and credentials and sendEmail and sendPass as per yours in
node_modules/npm-login-register/config/default.json
/*
dbName => database name
tableName => table / collection name
dbType => 'mongodb' / 'mysql'
*/
const LoginRegister=require('npm-login-register');
var dbName="mydb";
var tableName="user";
var dbType="mongodb";
var handler=new LoginRegister(dbName,tableName,dbType);
userData={
email:'youremail@host.com',
name:"aka",
password:123456,
......,
......
}
handler.userRegister(userData,function(result){
console.log(result);
});
[1/0,'message']
result[0] == 0 => error occur
result[0] == 1 => success
//for login
handler.userLogin(email,password,function(result){
console.log(result);
});
[1/0,'message']
result[0] == 0 => error occur
result[0] == 1 => success
//check for token
handler.checkToken(userid,usertoken,function(result){
console.log(result);
});
[1/0,'message']
result[0] == 0 => error occur
result[0] == 1 => success
result[1] => reponse msg
result[2] => user data if result[0]==1
//forgotPassword
handler.forgotPassword(email,function(result){
console.log(result);
});
[1/0,'message']
result[0] == 0 => error occur
result[0] == 1 => success
//change password
handler.changePassword(email,oldpass,newpass,function(result){
console.log(result);
});
[1/0,'message']
result[0] == 0 => error occur
result[0] == 1 => success