npm.io
1.7.6 • Published 4 years ago

express-udb

Licence
—
Version
1.7.6
Deps
7
Size
255 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

about

express-udb is a user data base for node that is more focused on the client side of things
it has messenger capabilities and live functions that can update your page, making it an super easy back end for a messenger that even beginners can use :)

express-udb version:1.7.5 usage

!!please note all live functions do not work with user privacy settings yet, they are not secured with authtokens yet, but they do work and will get fixed soon, the in-box functionality is also still in development, and will get fixed soon!!

basic server side example and explanation (copy and paste should work)

•if you do copy and paste please make all necessary html files, and use the correct values

const express = require('express');// import express
const app = express();//create app
const $udb = require('express-udb');//import express-udb
const http = require('http');//import http or https
const server = http.createServer(app);//create server
const { Server } = require('socket.io');// import socket io
const io = new Server(server);//create io server
app.use($udb) // make express use udb
io.on('connection',function(socket){
  io.use($udb.io(socket,io))//make socket io use udb
})
app.get('/',(req,res,next)=>{//root
  if(udb.ifLogedIn() === true){ // if user is loged in (also authenticates)
    udb.Authenticate({ // Authenticate user
      success:function(){ // if Authenticate success
        res.redirect('/home')//send user to home
      },err:function(){// if Authenticate console.error();
        udb.logout();//force logout for atackers
        res.redirect('/login')//take to login
      }
    }
  )
  }else{//if user not loged in
    res.redirect('/login')// take user to login
  }
})
app.get('/login',(req,res,next)=>{//login page
  if(udb.ifLogedIn() === true){// if user is loged in (also authenticates)
    res.redirect('/home')//take back home
  }else{// if user not loged in
    res.sendFile(__dirname+'/html/login.html')// send login.html
  }
})
app.post('/login',(req,res,next)=>{//login back end
  if(udb.ifLogedIn() === true){// if user is loged in (also authenticates)
    res.redirect('/home')//take back home
  }else{// if user not loged in
    if(udb.checkLogin({// check if login stat
        email:req.body.email,// login email
        password:req.body.password//login password
        })===true){//if login ok
          udb.login({//try login
            email:req.body.email,//login email
            password:req.body.password,//login password
            timeout:4800000//session timeout (if not set there is no timeout)
          });
          res.redirect('/home')//take user home
      }else if(udb.checkLogin({// check if login stat
          email:req.body.email,// login email
          password:req.body.password//login password
      })===false){// if login password bad
       res.redirect('/login?stat=badpassword')//send back to login with message
     }else if(udb.checkLogin({// check if login stat
       email:req.body.email,// login email
       password:req.body.password//login password
     })===null){//if email bad
      res.redirect('/login?stat=bademail')//send back to login with message
     }else{// if no stat
     res.redirect('/login')//send back to login
    }
}
})
app.get('/sighnup',(req,res,next)=>{//sighn up page
  if(udb.ifLogedIn() === true){// if user is loged in (also authenticates)
    res.redirect('/home')//take back home
  }else{// if user not loged in
    res.sendFile(__dirname+'/html/sighnup.html')// send sighnup.html
  }
})
app.post('/sighnup',(req,res,next)=>{//sighnup back end
  if(udb.ifLogedIn() === true){//if user is loged in
    res.redirect('/home')//take user back home
  }else{//if user not loged in
    if(udb.checkSighnUp({//check if sighn up okey
      email:req.body.email // new email
    }) == true){//if sighnup ok
      udb.sighnup.awaitConfirmEmail({//send confirmation email
        RootData:{//root email data (the email that confirmation email is sent from)
          service:'gmail',//email service
          email:"youremail@whatever.com",//your email
          password:"yourkey"//email password or key
        },
        ClientData:{//new client data
          email:req.body.email,//set new email
          password:req.body.password,//set new password
          username:req.body.username//set new username
        },
        //email html temlate
        Email:function(key){return `
          

hello ${req.body.username} your one time key is ${key} .

`}, timeout:4800000 // set 8 min timeout }) res.redirect('/sighnup%20confirm?email='+req.body.email)//send to confirm page }else{ res.redirect('/sighnup?stat=accExist') //send user back with message } } }) app.get('/sighnup%20confirm',(req,res,next)=>{//sighn up confirm page if(udb.ifLogedIn() === true){// if user is loged in (also authenticates) res.redirect('/home')//take back home }else{// if user not loged in res.sendFile(__dirname+'/html/sighnup-confirm.html')// send sighnup confirm.html } }) app.post('/sighnup%20confirm',(req,res,next)=>{// sighnup confirm back end if(udb.ifLogedIn() === true){// if user loged in res.redirect('/home')//take user back home }else{//if user not loged in try{//try if(udb.sighnup.confirmEmail({//try confirm email email:req.body.email,//requested email for confirm key:req.body.key,//key for confirm }) == true){// if key is true res.redirect('/login?stat=newAccMade')//send to login with message }else{//if key is false res.redirect('/sighnup%20confirm?email='+req.body.email+'&stat=badKey')//return with bad key message } }catch(e){// if error res.redirect('/sighnup%20confirm?email='+req.body.email+'&stat=bademail')//return with bad email message } } })

app.get('/home',(req,res,next)=>{ if(udb.ifLogedIn() === true){//if user is loged in (also authenticates) udb.Authenticate({//Authenticate user success:function(){//if authetication ok res.sendFile(__dirname+'/html/home.html')//send home page }, err:function(){//if authetication not ok res.redirect('/login')//take to login } }) }else{//if user not loged in res.redirect('/login')//take user to login page } }) server.listen(8080)//start server

client side scripting

import into html


//for socket io (optional)
 // for udb script (use only on pages that user is loged in)

•all user commands start with $.udb , importing the udb.js script also enables jQuery on your page

list of commands with explanations


// geting this user data
$.udb.GetUserCookie((userdata)=>{// userdata is now this user json data
consoel.log(userdata) // logs this user data array
})
$.udb.getContacts((contacts)=>{//gets contacts
//returns contacts in array with only userids
})
$.udb.getBlockedContacts((contacts)=>{//gets blocked contacts
//returns blocked contacts in array with only userids
})

// changeing this user data $.udb.ChangeUser.name("new name",()=>{//changes this user user name //do something when done }) $.udb.ChangeUser.status("new status",()=>{//changes this user status //do something when done }) $.udb.ChangeUser.profilePhoto("new profile photo url",()=>{//changes this user profile photo url //do something when done }) $.udb.ChangeUser.settings({somerandomething:"blahblah"},()=>{//changes user settings, this is a json array for user settings //do something when done })

//get other user data $.udb.GetClientUserData("userid",(clientdata)=>{//gets other client data console.log(clientdata)//logs client data array })

//handeling Contacts $.udb.addContact('userid',(result)=>{ // add contact, result will be true if ok, false if user doesnt exist }) $.udb.removeContact('userid',(result)=>{ // add remove, result will be true if ok, false if user doesnt exist }) $.udb.blockContact('userid',(result)=>{ //blockes contact to send inbox, message and online data,result will be true if ok and false if user does not exist })

$.udb.unblockContact('userid',(result)=>{ //unblockes contact to send inbox, message and online data,result will be true if ok and false if user does not exist })

//chating usage $.udb.sendMessage("userid","message content",()=>{ //do something when done }) $.udb.getChatData("userid",(chatdata)=>{ //returns chatdata with user in array form /*example { to:"who the message is too", from:"who the message is from", content:"the message content"
} */ }) //LIVE FUNCTIONS //emit that user is online $.udb.live.emitOnline()

// active listen for functions $.udb.live.active({ onOnline:(id)=>{//if user goes online do something with id

}, onOffline:(id)=>{//if user goes offline do something with id

}, onMessage:(data)=>{//if this user gets message, message returns the same way a chat message does

}, })

//enable authetication loop example function autoReAuthenticateUser(){ setTimeout(()=>{ $.udb.authUpdate(()=>{//command for re establishing authtoken autoReAuthenticateUser()//recall })},4100000)// 7:50 timeout for reauth } autoReAuthenticateUser()

advanced back end functions


//still in development explanations will come soon