Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisobel committed Sep 7, 2019
0 parents commit c7469d4
Show file tree
Hide file tree
Showing 44 changed files with 3,341 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm start
3 changes: 3 additions & 0 deletions app/configuration/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'secret': 'eypZAZy0CY^g9%KreypZAZy0CY^g9%Kr'
}
3 changes: 3 additions & 0 deletions app/configuration/bing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'SUBSCRIPTION_KEY':'55667dc2a47e4fda856758f900465d5e'
}
3 changes: 3 additions & 0 deletions app/configuration/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'url': 'mongodb://dennisobel:[email protected]:35036/ibookdb'
}
3 changes: 3 additions & 0 deletions app/configuration/otp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'secret':'SleepyeyeS2017'
}
160 changes: 160 additions & 0 deletions app/controllers/authController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
const helper = require('./../helpers')
const db = require("./../models");
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const otpSecret = require("./../configuration/otp");
const otplib = require('otplib');




// Pass Hash
const authConfig = require('../configuration/auth');

generateToken = (user) =>{
return jwt.sign(user, authConfig.secret, {
expiresIn: 10080
});
}

setUserInfo = (request) => {
console.log("request",request)
return {
passcode:request.passcode,
idnumber:request.idnumber,
phonenumber:request.phonenumber
}
}

// EOF Pass Hash

const iBookSignup = {}
const iBookLogin = {}
const iBookOTP = {}

// SMS PARAMETRES
const smsuser = 'KBSACCO'
const smspassword = 'KBSACCO1';
const smsclientsmsid = 'YOURREFERENCENUMBER';
const smssenderid='KBSACCO';
const smsunicode=0;
// EOF SMS PARAMS

iBookSignup.post = (req,res) => {
console.log("INCOMING SIGNUP DATA:", req.body)

const saltRounds = 10;

// PREP DATA FOR DB
const {
userName,
phoneNumber,
password,
otp
} = req.body;

bcrypt.genSalt(saltRounds).then(salt => {
return bcrypt.hash(req.body.data.password,salt)
}).then(hash => {
db.UserSchema.findOne({
userName: req.body.data.userName
},(err,doc)=>{
console.log(doc)
if(doc){
console.log("USER WITH THAT PHONE NUMBER EXISTS")
// HANDLE USER EXISTS - REDIRECT TO LOGIN

res.status(200).json({
success: true,
exist: true
})
} else {
console.log("USER DON'T EXIST",doc)
// HANDLE DATA UPLOAD TO DB
let OTP = otplib.authenticator.generate(otpSecret.secret)
console.log("OTP:",OTP)

let newUser = db.UserSchema({
userName:req.body.data.userName,
phoneNumber:req.body.data.phoneNumber,
password:hash,
otp:OTP
},()=>console.log("newUser: ",newUser))
.save()
.then((newUser)=>{
let sms = `Hi, thank you for joining Goose Links, your One Time Password is ${OTP}`;
let URL = `http://messaging.openocean.co.ke/sendsms.jsp?user=${smsuser}&password=${smspassword}&mobiles=${req.body.data.phoneNumber}&sms=${sms}&clientsmsid=${smsclientsmsid}&senderid=${smssenderid}`

helper.sendMessage(URL)
res.status(200).json({
success:true,
doc:newUser,
exist:false
})
})
}
})
})
}

iBookLogin.post = (req,res) => {
console.log("INCOMING LOGIN DATA:", req.body)
db.UserSchema.findOne({
userName:req.body.data.userName
},(err,docs) => {
if(docs){
bcrypt.compare(req.body.data.password,docs.password,(err,response) => {
if(response){
return res.status(200).json({
success: true,
data: docs
})
}else if(err){
throw new Error;
}
})
}
})
}

iBookOTP.post = (req,res) => {
console.log("INCOMING OTP DATA:", req.body)
let data = {
otp:req.body.val2.onetimepassword,
phoneNumber: req.body.val1.data.doc.phoneNumber
}

console.log(data)

db.UserSchema.findOneAndUpdate({
phoneNumber:data.phoneNumber
},{
verified: true
}).then(()=>{
db.UserSchema.find({
phoneNumber: req.body.val1.data.doc.phoneNumber,
verified:true
},(err,docs)=>{
if (err) throw Error;
if(docs){
res.status(200).json({
success:true,
docs:docs
})
} else if(!docs){
res.status(200).json({
success:false
})
}
})
})
// COMPARE OTP
// IF MATCH MARK USER AS VERIFIED
}


module.exports = {
iBookSignup,
iBookLogin,
iBookOTP
}
25 changes: 25 additions & 0 deletions app/controllers/friendsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const db = require("./../models");

const getFriend = {}

getFriend.get = (req,res) => {
console.log("INCOMING FRIEND REQ:",req.params)

db.UserSchema.find({
phoneNumber:req.params.phoneNumber
},(err,doc) => {
console.log("DOC:",doc)
if(doc){
res.status(200).json({
success: true,
user:doc
})
}else{
res.status(404).send('Sorry, User not found!')
}
})
}

module.exports = {
getFriend
}
Empty file.
9 changes: 9 additions & 0 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const AuthCtrl = require('../controllers/authController');
const GiftCtrl = require('../controllers/giftController');
const SubscriptionCtrl = require('../controllers/subscriptionController');

module.exports = {
AuthCtrl,
GiftCtrl,
SubscriptionCtrl
}
Empty file.
31 changes: 31 additions & 0 deletions app/controllers/mpesaController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// let helper = require('./../Helpers')
// let mpesa = require('../mpesa')
// var moment = require('moment');
let mpesa = require('../helpers/mpesa/ApiHelpers')

const db = require("./../models");

const sendMpesa = {}

sendMpesa.post = (req,res) => {
console.log("INSIDE MPESA:")
mpesa.genOAuth().then(body => {
console.log("inside genOauth")
let _body = JSON.parse(body);
let oauth_token = _body.access_token;
let auth = "Bearer " + oauth_token;

console.log("auth:",auth)

mpesa.lipaNaMpesa(auth).then(body => {
console.log("inside lipanampesa")
console.log("Body :",body)
}).catch(error => {
console.log("Error :",error)
})
})
}

module.exports = {
sendMpesa
}
26 changes: 26 additions & 0 deletions app/controllers/nifty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var spawn = require('child_process').spawn;

makePayment = function(_data){
console.log("incoming: ",_data)

var scriptExecution = spawn("python", ["./nifty.py"]);

// Handle normal output
scriptExecution.stdout.on('data', (data) => {
console.log("python output",String.fromCharCode.apply(null, data));
});

var data = JSON.stringify([_data.phoneNumber,parseInt(_data.amount),'kbsacco','f861c6cc-4efa-4306-8eee-08f035b03772']);
console.log("datas: ",data)
// Write data (remember to send only strings or numbers, otherwhise python wont understand)
scriptExecution.stdin.write(data);
// End data write
scriptExecution.stdin.end();
}

var data = {
phoneNumber:254727677068,
amount:10
}

makePayment(data)
Loading

0 comments on commit c7469d4

Please sign in to comment.