-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c7469d4
Showing
44 changed files
with
3,341 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'secret': 'eypZAZy0CY^g9%KreypZAZy0CY^g9%Kr' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'SUBSCRIPTION_KEY':'55667dc2a47e4fda856758f900465d5e' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'url': 'mongodb://dennisobel:[email protected]:35036/ibookdb' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'secret':'SleepyeyeS2017' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.