Skip to content

Commit

Permalink
added verify for postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
zepvalue committed Jul 8, 2019
1 parent 074979f commit fa40be6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
3 changes: 1 addition & 2 deletions functions/databases/mongoose/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ function verify(userID, code) {
)
);

return this.client.verify
.services(sid)
return this.client.verify.services(sid)
.verificationChecks.create({
to: phone,
code
Expand Down
56 changes: 33 additions & 23 deletions functions/databases/postgres/verify.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
module.exports = function(userID, code) {
const { client, pgConnect } = this;
const { pgConnect } = this;
return new Promise((resolve, reject) => {
pgConnect()
.then(({ database, done }) => {
//Query to just check if the user was created
const query = "SELECT userid FROM twoauthusers WHERE userid=$1";
const query = "SELECT * FROM twoauthusers WHERE userid=$1";
const values = [String(userID)];

database.query(query, values).then(res => {
const { sid, phone } = res.rows[0];
database
.query(query, values)
.then(res => {
const { sid, phone } = res.rows[0];

if (!sid)
reject(new Error("SID Error: No SID exists for this user."));
if (!phone)
reject(
new Error(
"Phone Number Error: No phone number exists for this user."
)
);
if (!sid)
reject(new Error("SID Error: No SID exists for this user."));
if (!phone)
reject(
new Error(
"Phone Number Error: No phone number exists for this user."
)
);

return this.client.verify
.services(sid)
.verificationChecks.create({
to: phone,
code
})
.then(verification => {
if (verification.status === "approved") resolve(true);
resolve(false);
});
});
return this.client.verify
.services(sid)
.verificationChecks.create({
to: phone,
code
})
.then(verification => {
if (verification.status === "approved") resolve(true);
resolve(false);
})
.catch(err => {
done();
resolve(false)
});
})
.catch(err => {
done();
reject(new Error("Could not find Database at Connection URI."));
});
})
.catch(err => {
done();
Expand Down
8 changes: 5 additions & 3 deletions tests/create.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const client = require("../index")(process.env.SID, process.env.AUTH, {
isPostgres: true,
connectionURI: "postgres://student:ilovetesting@localhost/twoauthtests"
appName:'DATABASE two-factor',
connectionURI: "postgres://zepvalue:linux@localhost/twoauthtests"
});

client.create("ian", "+17604207520");

//client.create("ian", "+17604207520");
//client.send("ian")
client.verify("ian", '851701')
// console.log("client is", Client);

// Client.create("ian", "17604207520")
Expand Down

0 comments on commit fa40be6

Please sign in to comment.