From 917673d67ec8863bcc7c593ef2f25a7b98c430cb Mon Sep 17 00:00:00 2001 From: MacAjwani Date: Sat, 28 Oct 2023 15:34:37 -0500 Subject: [PATCH 1/9] Started implementing phone number input --- app/App.tsx | 3 +- app/package-lock.json | 64 ++++++++++++++++++++++++++++++++++++++++++- app/package.json | 3 +- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/app/App.tsx b/app/App.tsx index 0329d0c..95e25cd 100644 --- a/app/App.tsx +++ b/app/App.tsx @@ -1,10 +1,11 @@ import { StatusBar } from 'expo-status-bar'; import { StyleSheet, Text, View } from 'react-native'; +import Example from './components/sign-in'; export default function App() { return ( - Open up App.tsx to start working on your app! + ); diff --git a/app/package-lock.json b/app/package-lock.json index 5a8cb25..3cdde87 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -11,7 +11,8 @@ "expo": "~49.0.13", "expo-status-bar": "~1.6.0", "react": "18.2.0", - "react-native": "0.72.5" + "react-native": "0.72.5", + "react-phone-number-input": "^3.3.7" }, "devDependencies": { "@babel/core": "^7.20.0", @@ -6739,6 +6740,11 @@ "node": ">=8" } }, + "node_modules/classnames": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.3.2.tgz", + "integrity": "sha512-CSbhY4cFEJRe6/GQzIk5qXZ4Jeg5pcsP7b5peFSDpffpe1cqjASH/n9UTjBwOp6XpMSTwQ8Za2K5V02ueA7Tmw==" + }, "node_modules/clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -6996,6 +7002,11 @@ "node": ">=4" } }, + "node_modules/country-flag-icons": { + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/country-flag-icons/-/country-flag-icons-1.5.7.tgz", + "integrity": "sha512-AdvXhMcmSp7nBSkpGfW4qR/luAdRUutJqya9PuwRbsBzuoknThfultbv7Ib6fWsHXC43Es/4QJ8gzQQdBNm75A==" + }, "node_modules/cross-fetch": { "version": "3.1.8", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", @@ -8300,6 +8311,14 @@ "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" }, + "node_modules/input-format": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/input-format/-/input-format-0.3.8.tgz", + "integrity": "sha512-tLR0XRig1xIcG1PtIpMd/uoltvkAI62CN9OIbtj4/tEJAkqTCQLNHUZ9N4M46w0dopny7Rlt/lRH5Xzp7e6F+g==", + "dependencies": { + "prop-types": "^15.8.1" + } + }, "node_modules/internal-ip": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/internal-ip/-/internal-ip-4.3.0.tgz", @@ -9404,6 +9423,11 @@ "node": ">=6" } }, + "node_modules/libphonenumber-js": { + "version": "1.10.49", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.49.tgz", + "integrity": "sha512-gvLtyC3tIuqfPzjvYLH9BmVdqzGDiSi4VjtWe2fAgSdBf0yt8yPmbNnRIHNbR5IdtVkm0ayGuzwQKTWmU0hdjQ==" + }, "node_modules/lightningcss": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.19.0.tgz", @@ -11736,6 +11760,28 @@ } } }, + "node_modules/react-dom": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.0" + }, + "peerDependencies": { + "react": "^18.2.0" + } + }, + "node_modules/react-dom/node_modules/scheduler": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", @@ -11814,6 +11860,22 @@ "async-limiter": "~1.0.0" } }, + "node_modules/react-phone-number-input": { + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/react-phone-number-input/-/react-phone-number-input-3.3.7.tgz", + "integrity": "sha512-/yusEJl2oJA5rTRtny59pf7T1gg/whmfhdZsgrZaL063KEx6FFnmwTskTJ9yR4lYgzj2GyUjXpnA3O9d+ZTHwA==", + "dependencies": { + "classnames": "^2.3.1", + "country-flag-icons": "^1.5.4", + "input-format": "^0.3.8", + "libphonenumber-js": "^1.10.48", + "prop-types": "^15.8.1" + }, + "peerDependencies": { + "react": ">=16.8", + "react-dom": ">=16.8" + } + }, "node_modules/react-refresh": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.4.3.tgz", diff --git a/app/package.json b/app/package.json index 82df200..863c3d6 100644 --- a/app/package.json +++ b/app/package.json @@ -12,7 +12,8 @@ "expo": "~49.0.13", "expo-status-bar": "~1.6.0", "react": "18.2.0", - "react-native": "0.72.5" + "react-native": "0.72.5", + "react-phone-number-input": "^3.3.7" }, "devDependencies": { "@babel/core": "^7.20.0", From 3799a0a1ae022420ff10b334a2d7723c12090d77 Mon Sep 17 00:00:00 2001 From: MacAjwani Date: Sat, 4 Nov 2023 13:25:32 -0500 Subject: [PATCH 2/9] "Fixed server bug" --- app/components/sign-in.tsx | 51 ++++++++++++++++++++++++++++++++++++++ server/index.js | 37 ++++++++++++++------------- 2 files changed, 71 insertions(+), 17 deletions(-) create mode 100644 app/components/sign-in.tsx diff --git a/app/components/sign-in.tsx b/app/components/sign-in.tsx new file mode 100644 index 0000000..ffcc11b --- /dev/null +++ b/app/components/sign-in.tsx @@ -0,0 +1,51 @@ + + +function Example() { + // `value` will be the parsed phone number in E.164 format. + // Example: "+12133734253". + const [value, setValue] = useState("1") + return ( + setValue("2")}/> + ) +} + +export default Example; + + + + + +/* + +// +import {SafeAreaView, StyleSheet, TextInput, Text} from 'react-native'; +const TextInputExample = () => { + const [text, onChangeText] = React.useState('Useless Text'); + const [number, onChangeNumber] = React.useState(''); + + return ( + + Phone Number + + + ); +}; + +const styles = StyleSheet.create({ + input: { + height: 40, + margin: 12, + borderWidth: 1, + padding: 10, + }, +}); +*/ \ No newline at end of file diff --git a/server/index.js b/server/index.js index d634753..49b6957 100644 --- a/server/index.js +++ b/server/index.js @@ -1,27 +1,30 @@ const { MongoClient, ServerApiVersion } = require('mongodb'); require('dotenv').config(); +const express = require('express'); +const routes = require("./routes"); +const cors = require('cors'); +const morgan = require("morgan"); +const { default: mongoose } = require('mongoose'); -const uri = "mongodb+srv://" + process.env.MONGO_ADMIN_USERNAME + ":" + process.env.MONGO_ADMIN_PASSWORD + "@thi-cluster.hppzt17.mongodb.net/?retryWrites=true&w=majority"; -// Create a MongoClient with a MongoClientOptions object to set the Stable API version -const client = new MongoClient(uri, { - serverApi: { - version: ServerApiVersion.v1, - strict: true, - deprecationErrors: true, - } -}); +const uri = "mongodb+srv://" + process.env.MONGO_ADMIN_USERNAME + ":" + process.env.MONGO_ADMIN_PASSWORD + "@thi-cluster.hppzt17.mongodb.net/?retryWrites=true&w=majority"; -async function run() { +async function run() { try { - // Connect the client to the server - await client.connect(); - // Send a ping to confirm a successful connection - await client.db("admin").command({ ping: 1 }); + await mongoose.connect(uri) console.log("Pinged your deployment. You successfully connected to MongoDB!"); - } finally { - // Ensures that the client will close when you finish/error - await client.close(); + const app = express(); + + app.use(express.json()); + app.use(cors()); + app.use(morgan("tiny")); + app.use('/api', routes); + + app.listen(3000, () => { + console.log(`Server started at ${3000}`); + }) + } catch (error) { + console.log(error); } } From 60b33e8e3787c1fe9885b0527907628d6ae99f18 Mon Sep 17 00:00:00 2001 From: trietmchau Date: Sat, 4 Nov 2023 13:41:14 -0500 Subject: [PATCH 3/9] add --- .DS_Store | Bin 0 -> 6148 bytes app/App.tsx | 33 +++++++++---------- app/components/sign-in.tsx | 17 ++++++++++ app/package-lock.json | 64 ++++++++++++++++++++++++++++++++++++- app/package.json | 3 +- 5 files changed, 97 insertions(+), 20 deletions(-) create mode 100644 .DS_Store create mode 100644 app/components/sign-in.tsx diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a47e5ffe0ab12f15902a46f1909f22a598d41a10 GIT binary patch literal 6148 zcmeHK%}T>S5T0$TO({YT3Oz1(E!ZC^7B3;z7cim+m736^!I&*ge-5RPv%Zi|;`2DO zyA^BeRiw_q?6*5RlQ3Vx&JF+wZ_;l7Q~nQ1~nWrX6Kh?3m*>FlusaL7a=gm&LCR-ALJ9*I z!IZ`=$#f;BZ}~16VPpoF0cKzm1NIbk%9}RX#tbk6|C#|hA0#TFYcVsZj}9Dk3xG)1 zNG&+0UV>tzMb~0x5O+|72}Lxa!nPQ~gri+rKi6Vr(1e4q&4;jW7PdnX`tA69sog=i z26PwdAPQO4NH)67tIoeum&g hmtyp#Qd~vVf_6z0MAu?w5G^Qt5zsX7zzqB<10Ou1hfx3k literal 0 HcmV?d00001 diff --git a/app/App.tsx b/app/App.tsx index 498ca44..2bd343d 100644 --- a/app/App.tsx +++ b/app/App.tsx @@ -1,21 +1,18 @@ -import { StatusBar } from 'expo-status-bar'; -import { StyleSheet, Text, View } from 'react-native'; +import { useState } from 'react'; +import PhoneInput from 'react-phone-number-input'; +import 'react-phone-number-input/style.css'; -import WelcomePage from './components/welcome'; - -export default function App() { +function test() { +} +function Example() { + // `value` will be the parsed phone number in E.164 format. + // Example: "+12133734253". + const [value, setValue] = useState() return ( - - - - ); + + ) } - -const styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: '#fff', - alignItems: 'center', - justifyContent: 'center', - }, -}); +export default Example; \ No newline at end of file diff --git a/app/components/sign-in.tsx b/app/components/sign-in.tsx new file mode 100644 index 0000000..617413c --- /dev/null +++ b/app/components/sign-in.tsx @@ -0,0 +1,17 @@ +import { useState } from 'react'; +import PhoneInput from 'react-phone-number-input'; +import 'react-phone-number-input/style.css'; + + +function Example() { + // `value` will be the parsed phone number in E.164 format. + // Example: "+12133734253". + const [value, setValue] = useState() + return ( + + ) +} +export default Example; \ No newline at end of file diff --git a/app/package-lock.json b/app/package-lock.json index 5a8cb25..3cdde87 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -11,7 +11,8 @@ "expo": "~49.0.13", "expo-status-bar": "~1.6.0", "react": "18.2.0", - "react-native": "0.72.5" + "react-native": "0.72.5", + "react-phone-number-input": "^3.3.7" }, "devDependencies": { "@babel/core": "^7.20.0", @@ -6739,6 +6740,11 @@ "node": ">=8" } }, + "node_modules/classnames": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.3.2.tgz", + "integrity": "sha512-CSbhY4cFEJRe6/GQzIk5qXZ4Jeg5pcsP7b5peFSDpffpe1cqjASH/n9UTjBwOp6XpMSTwQ8Za2K5V02ueA7Tmw==" + }, "node_modules/clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -6996,6 +7002,11 @@ "node": ">=4" } }, + "node_modules/country-flag-icons": { + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/country-flag-icons/-/country-flag-icons-1.5.7.tgz", + "integrity": "sha512-AdvXhMcmSp7nBSkpGfW4qR/luAdRUutJqya9PuwRbsBzuoknThfultbv7Ib6fWsHXC43Es/4QJ8gzQQdBNm75A==" + }, "node_modules/cross-fetch": { "version": "3.1.8", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", @@ -8300,6 +8311,14 @@ "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" }, + "node_modules/input-format": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/input-format/-/input-format-0.3.8.tgz", + "integrity": "sha512-tLR0XRig1xIcG1PtIpMd/uoltvkAI62CN9OIbtj4/tEJAkqTCQLNHUZ9N4M46w0dopny7Rlt/lRH5Xzp7e6F+g==", + "dependencies": { + "prop-types": "^15.8.1" + } + }, "node_modules/internal-ip": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/internal-ip/-/internal-ip-4.3.0.tgz", @@ -9404,6 +9423,11 @@ "node": ">=6" } }, + "node_modules/libphonenumber-js": { + "version": "1.10.49", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.10.49.tgz", + "integrity": "sha512-gvLtyC3tIuqfPzjvYLH9BmVdqzGDiSi4VjtWe2fAgSdBf0yt8yPmbNnRIHNbR5IdtVkm0ayGuzwQKTWmU0hdjQ==" + }, "node_modules/lightningcss": { "version": "1.19.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.19.0.tgz", @@ -11736,6 +11760,28 @@ } } }, + "node_modules/react-dom": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", + "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0", + "scheduler": "^0.23.0" + }, + "peerDependencies": { + "react": "^18.2.0" + } + }, + "node_modules/react-dom/node_modules/scheduler": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.0.tgz", + "integrity": "sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", @@ -11814,6 +11860,22 @@ "async-limiter": "~1.0.0" } }, + "node_modules/react-phone-number-input": { + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/react-phone-number-input/-/react-phone-number-input-3.3.7.tgz", + "integrity": "sha512-/yusEJl2oJA5rTRtny59pf7T1gg/whmfhdZsgrZaL063KEx6FFnmwTskTJ9yR4lYgzj2GyUjXpnA3O9d+ZTHwA==", + "dependencies": { + "classnames": "^2.3.1", + "country-flag-icons": "^1.5.4", + "input-format": "^0.3.8", + "libphonenumber-js": "^1.10.48", + "prop-types": "^15.8.1" + }, + "peerDependencies": { + "react": ">=16.8", + "react-dom": ">=16.8" + } + }, "node_modules/react-refresh": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.4.3.tgz", diff --git a/app/package.json b/app/package.json index 82df200..863c3d6 100644 --- a/app/package.json +++ b/app/package.json @@ -12,7 +12,8 @@ "expo": "~49.0.13", "expo-status-bar": "~1.6.0", "react": "18.2.0", - "react-native": "0.72.5" + "react-native": "0.72.5", + "react-phone-number-input": "^3.3.7" }, "devDependencies": { "@babel/core": "^7.20.0", From 0e46630c641af534b915e26d4f5b63b40a5ae294 Mon Sep 17 00:00:00 2001 From: trietmchau Date: Sat, 4 Nov 2023 15:47:59 -0500 Subject: [PATCH 4/9] Create --- server/backend_helper/sms_validation.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 server/backend_helper/sms_validation.js diff --git a/server/backend_helper/sms_validation.js b/server/backend_helper/sms_validation.js new file mode 100644 index 0000000..3eafb4a --- /dev/null +++ b/server/backend_helper/sms_validation.js @@ -0,0 +1,24 @@ +require('dotenv').config; +const accountSid = process.env.TWILIO_ACCOUNT_SID; +console.log("a"); +console.log(accountSid); +console.log("b"); +const authToken = process.env.TWILIO_AUTH_TOKEN; +const client = require('twilio')(accountSid, authToken); + +// client.accounts.v1.authTokenPromotion() +// .update() +// .then(auth_token_promotion => console.log(auth_token_promotion.dateCreated)); + +// client.verify.v2.services('VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') +// .verifications +// .create({to: '+12488479332', channel: 'sms'}) +// .then(verification => console.log(verification.status)); + +client.messages + .create({ + body: 'This is the ship that made the Kessel Run in fourteen parsecs?', + from: '+12488479332', + to: '+12488479332' + }) + .then(message => console.log(message.sid)); \ No newline at end of file From 639abe8ca228aa4e9e8fd1e1cdaaf4b968033696 Mon Sep 17 00:00:00 2001 From: trietmchau Date: Sat, 4 Nov 2023 15:48:59 -0500 Subject: [PATCH 5/9] create --- server/.env | 5 ++++- server/backend_helper/sms_validation.js | 3 --- server/package.json | 3 ++- server/routes/auth.js | 4 ++++ 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 server/routes/auth.js diff --git a/server/.env b/server/.env index 44b9b8c..41a6cb9 100644 --- a/server/.env +++ b/server/.env @@ -1,4 +1,7 @@ MONGO_ADMIN_USERNAME = "thiwalk30-admin" MONGO_ADMIN_PASSWORD = "Nwn3sXmdo9mwEqZx" AWS_ACCESS_KEY = "AKIA3ALRGMM244E2YBZZ" -AWS_SECRET_ACCESS_KEY = "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" \ No newline at end of file +AWS_SECRET_ACCESS_KEY = "uKR37SNf++NH6WN0p+Dxhv5r7+tTUjgRr+QmI9p6" +TWILIO_AUTH_TOKEN = "bb89ebaeed0352ac15d50b26fce3f0ef" +TWILIO_ACCOUNT_SID = "AC5a42a66eeb756958bef574056bc615aa" +TWILIO_FROM_NUMBER = "12488479332" \ No newline at end of file diff --git a/server/backend_helper/sms_validation.js b/server/backend_helper/sms_validation.js index 3eafb4a..5d311ad 100644 --- a/server/backend_helper/sms_validation.js +++ b/server/backend_helper/sms_validation.js @@ -1,8 +1,5 @@ require('dotenv').config; const accountSid = process.env.TWILIO_ACCOUNT_SID; -console.log("a"); -console.log(accountSid); -console.log("b"); const authToken = process.env.TWILIO_AUTH_TOKEN; const client = require('twilio')(accountSid, authToken); diff --git a/server/package.json b/server/package.json index 9ba7fa4..87f4094 100644 --- a/server/package.json +++ b/server/package.json @@ -6,7 +6,8 @@ "mongodb": "^6.2.0", "mongoose": "^7.6.3", "morgan": "^1.10.0", - "nodemon": "^3.0.1" + "nodemon": "^3.0.1", + "twilio": "^4.19.0" }, "scripts": { "start": "nodemon index.js" diff --git a/server/routes/auth.js b/server/routes/auth.js new file mode 100644 index 0000000..a81c1bc --- /dev/null +++ b/server/routes/auth.js @@ -0,0 +1,4 @@ +const express = require("express"); +const router = express.Router(); + + From cc42ae9c9ec59b841595cd43dd3fd3a384dd9f3a Mon Sep 17 00:00:00 2001 From: Triet Chau Date: Sat, 4 Nov 2023 22:44:05 -0500 Subject: [PATCH 6/9] add --- server/.env | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 server/.env diff --git a/server/.env b/server/.env new file mode 100644 index 0000000..44b9b8c --- /dev/null +++ b/server/.env @@ -0,0 +1,4 @@ +MONGO_ADMIN_USERNAME = "thiwalk30-admin" +MONGO_ADMIN_PASSWORD = "Nwn3sXmdo9mwEqZx" +AWS_ACCESS_KEY = "AKIA3ALRGMM244E2YBZZ" +AWS_SECRET_ACCESS_KEY = "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" \ No newline at end of file From 2b10852fd2e13de3f6a850ad80beb7c8e66637c1 Mon Sep 17 00:00:00 2001 From: trietmchau Date: Sat, 11 Nov 2023 15:29:24 -0600 Subject: [PATCH 7/9] add sms verify feature --- server/.env | 7 ---- server/.env.sample | 7 ++++ server/backend_helper/index.js | 3 ++ server/backend_helper/sms_validation.js | 43 ++++++++++++++----------- server/index.js | 21 ------------ server/routes/auth.js | 22 +++++++++++++ server/routes/index.js | 3 ++ 7 files changed, 59 insertions(+), 47 deletions(-) delete mode 100644 server/.env create mode 100644 server/.env.sample create mode 100644 server/backend_helper/index.js diff --git a/server/.env b/server/.env deleted file mode 100644 index 4bb35b9..0000000 --- a/server/.env +++ /dev/null @@ -1,7 +0,0 @@ -MONGO_ADMIN_USERNAME = "thiwalk30-admin" -MONGO_ADMIN_PASSWORD = "Nwn3sXmdo9mwEqZx" -AWS_ACCESS_KEY = "AKIA3ALRGMM244E2YBZZ" -AWS_SECRET_ACCESS_KEY = "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" -TWILIO_AUTH_TOKEN = "bb89ebaeed0352ac15d50b26fce3f0ef" -TWILIO_ACCOUNT_SID = "AC5a42a66eeb756958bef574056bc615aa" -TWILIO_FROM_NUMBER = "12488479332" diff --git a/server/.env.sample b/server/.env.sample new file mode 100644 index 0000000..31510d1 --- /dev/null +++ b/server/.env.sample @@ -0,0 +1,7 @@ +MONGO_ADMIN_USERNAME="username" +MONGO_ADMIN_PASSWORD="password" +AWS_ACCESS_KEY="access_key_pub" +AWS_SECRET_ACCESS_KEY="access_key_priv" +TWILIO_AUTH_TOKEN="token" +TWILIO_ACCOUNT_SID="sid" +TWILIO_SERVICE_SID="service_sid" \ No newline at end of file diff --git a/server/backend_helper/index.js b/server/backend_helper/index.js new file mode 100644 index 0000000..f2b5879 --- /dev/null +++ b/server/backend_helper/index.js @@ -0,0 +1,3 @@ +const smsValidation = require("./sms_validation"); + +module.exports = {smsValidation} \ No newline at end of file diff --git a/server/backend_helper/sms_validation.js b/server/backend_helper/sms_validation.js index 5d311ad..c12b0c0 100644 --- a/server/backend_helper/sms_validation.js +++ b/server/backend_helper/sms_validation.js @@ -1,21 +1,26 @@ -require('dotenv').config; -const accountSid = process.env.TWILIO_ACCOUNT_SID; -const authToken = process.env.TWILIO_AUTH_TOKEN; -const client = require('twilio')(accountSid, authToken); +// Download the helper library from https://www.twilio.com/docs/node/install +// Set environment variables for your credentials +// Read more at http://twil.io/secure +const accountSid = "AC5a42a66eeb756958bef574056bc615aa"; +const authToken = "7599177e84948a4ac62e46f9210ceec6"; +const verifySid = "VAddeb0650e4bdfd3e18ebf64ce6b1d152"; +const client = require("twilio")(accountSid, authToken); -// client.accounts.v1.authTokenPromotion() -// .update() -// .then(auth_token_promotion => console.log(auth_token_promotion.dateCreated)); - -// client.verify.v2.services('VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') -// .verifications -// .create({to: '+12488479332', channel: 'sms'}) -// .then(verification => console.log(verification.status)); +const sendSms = (number, verifySid) => { + client.verify.v2 + .services(verifySid) + .verifications.create({ to: number, channel: "sms" }) + .then((verification) => verification.status); +} -client.messages - .create({ - body: 'This is the ship that made the Kessel Run in fourteen parsecs?', - from: '+12488479332', - to: '+12488479332' - }) - .then(message => console.log(message.sid)); \ No newline at end of file +const verify = (number, verifySid, code) => { + client.verify.v2.services(verifySid) + .verificationChecks + .create({to: number, code: code}) + .then(verification_check => verification_check.status); +} + +module.exports = { + sendSms, + verify +} \ No newline at end of file diff --git a/server/index.js b/server/index.js index c67472d..49b6957 100644 --- a/server/index.js +++ b/server/index.js @@ -4,26 +4,11 @@ const express = require('express'); const routes = require("./routes"); const cors = require('cors'); const morgan = require("morgan"); -<<<<<<< HEAD -======= const { default: mongoose } = require('mongoose'); ->>>>>>> 3799a0a1ae022420ff10b334a2d7723c12090d77 const uri = "mongodb+srv://" + process.env.MONGO_ADMIN_USERNAME + ":" + process.env.MONGO_ADMIN_PASSWORD + "@thi-cluster.hppzt17.mongodb.net/?retryWrites=true&w=majority"; -<<<<<<< HEAD -// Create a MongoClient with a MongoClientOptions object to set the Stable API version -const client = new MongoClient(uri, { - serverApi: { - version: ServerApiVersion.v1, - strict: true, - deprecationErrors: true, - } -}); - -======= ->>>>>>> 3799a0a1ae022420ff10b334a2d7723c12090d77 async function run() { try { await mongoose.connect(uri) @@ -38,14 +23,8 @@ async function run() { app.listen(3000, () => { console.log(`Server started at ${3000}`); }) -<<<<<<< HEAD - } finally { - // Ensures that the client will close when you finish/error - await client.close(); -======= } catch (error) { console.log(error); ->>>>>>> 3799a0a1ae022420ff10b334a2d7723c12090d77 } } diff --git a/server/routes/auth.js b/server/routes/auth.js index a81c1bc..e0856e9 100644 --- a/server/routes/auth.js +++ b/server/routes/auth.js @@ -1,4 +1,26 @@ const express = require("express"); +require("dotenv").config(); const router = express.Router(); +const {smsValidation} = require("../backend_helper"); +const serviceSid = process.env.TWILIO_SERVICE_SID; +router.get("/sendSms", async (req, res, next) => { + try { + const {phoneNumber} = req.body; + const data = await smsValidation.verify(phoneNumber, serviceSid); + res.send(data); + } catch (error) { + res.status(400).json({message:error.message}) + } +}) + +router.get("/verify", async (req, res, next) => { + try { + const {phoneNumber, code} = req.body; + const data = await smsValidation.verify(phoneNumber, serviceSid, code); + res.send(data); + } catch (error) { + res.status(400).json({message:error.message}) + } +}) \ No newline at end of file diff --git a/server/routes/index.js b/server/routes/index.js index 0f23aa2..dbce797 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,9 +1,12 @@ const express = require("express"); const resource = require("./resource"); const organization = require("./organization"); +const auth = require("./organization"); + const router = express.Router(); router.use("/resource", resource); router.use("/organization", organization); +router.use("/auth", auth); module.exports = router; \ No newline at end of file From 2b57ed959c99f12fb73c81ea9104147aecdaf7b5 Mon Sep 17 00:00:00 2001 From: trietmchau Date: Sat, 11 Nov 2023 15:41:41 -0600 Subject: [PATCH 8/9] fix sign in --- server/backend_helper/sms_validation.js | 5 ++--- server/routes/auth.js | 7 +++++-- server/routes/index.js | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server/backend_helper/sms_validation.js b/server/backend_helper/sms_validation.js index c12b0c0..c5d46cc 100644 --- a/server/backend_helper/sms_validation.js +++ b/server/backend_helper/sms_validation.js @@ -1,9 +1,8 @@ // Download the helper library from https://www.twilio.com/docs/node/install // Set environment variables for your credentials // Read more at http://twil.io/secure -const accountSid = "AC5a42a66eeb756958bef574056bc615aa"; -const authToken = "7599177e84948a4ac62e46f9210ceec6"; -const verifySid = "VAddeb0650e4bdfd3e18ebf64ce6b1d152"; +const accountSid = process.env.TWILIO_ACCOUNT_SID; +const authToken = process.env.TWILIO_AUTH_TOKEN; const client = require("twilio")(accountSid, authToken); const sendSms = (number, verifySid) => { diff --git a/server/routes/auth.js b/server/routes/auth.js index e0856e9..c6d07bf 100644 --- a/server/routes/auth.js +++ b/server/routes/auth.js @@ -8,7 +8,8 @@ const serviceSid = process.env.TWILIO_SERVICE_SID; router.get("/sendSms", async (req, res, next) => { try { const {phoneNumber} = req.body; - const data = await smsValidation.verify(phoneNumber, serviceSid); + console.log(serviceSid); + const data = await smsValidation.sendSms(phoneNumber, serviceSid); res.send(data); } catch (error) { res.status(400).json({message:error.message}) @@ -23,4 +24,6 @@ router.get("/verify", async (req, res, next) => { } catch (error) { res.status(400).json({message:error.message}) } -}) \ No newline at end of file +}) + +module.exports = router \ No newline at end of file diff --git a/server/routes/index.js b/server/routes/index.js index dbce797..61913df 100644 --- a/server/routes/index.js +++ b/server/routes/index.js @@ -1,7 +1,7 @@ const express = require("express"); const resource = require("./resource"); const organization = require("./organization"); -const auth = require("./organization"); +const auth = require("./auth"); const router = express.Router(); From 60f80f6603e83b8bb58764921d55e6aa8ded42f2 Mon Sep 17 00:00:00 2001 From: trietmchau Date: Sat, 11 Nov 2023 17:00:30 -0600 Subject: [PATCH 9/9] Add valid SMS check --- server/backend_helper/sms_validation.js | 12 ++++++------ server/routes/auth.js | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/server/backend_helper/sms_validation.js b/server/backend_helper/sms_validation.js index c5d46cc..91c865d 100644 --- a/server/backend_helper/sms_validation.js +++ b/server/backend_helper/sms_validation.js @@ -5,18 +5,18 @@ const accountSid = process.env.TWILIO_ACCOUNT_SID; const authToken = process.env.TWILIO_AUTH_TOKEN; const client = require("twilio")(accountSid, authToken); -const sendSms = (number, verifySid) => { - client.verify.v2 +const sendSms = async (number, verifySid) => { + return client.verify.v2 .services(verifySid) .verifications.create({ to: number, channel: "sms" }) - .then((verification) => verification.status); + .then((verification) => verification); } -const verify = (number, verifySid, code) => { - client.verify.v2.services(verifySid) +const verify = async (number, verifySid, code) => { + return client.verify.v2.services(verifySid) .verificationChecks .create({to: number, code: code}) - .then(verification_check => verification_check.status); + .then(verification_check => verification_check); } module.exports = { diff --git a/server/routes/auth.js b/server/routes/auth.js index c6d07bf..4e28f55 100644 --- a/server/routes/auth.js +++ b/server/routes/auth.js @@ -8,8 +8,7 @@ const serviceSid = process.env.TWILIO_SERVICE_SID; router.get("/sendSms", async (req, res, next) => { try { const {phoneNumber} = req.body; - console.log(serviceSid); - const data = await smsValidation.sendSms(phoneNumber, serviceSid); + const data = await smsValidation.sendSms(phoneNumber, serviceSid) res.send(data); } catch (error) { res.status(400).json({message:error.message}) @@ -20,6 +19,9 @@ router.get("/verify", async (req, res, next) => { try { const {phoneNumber, code} = req.body; const data = await smsValidation.verify(phoneNumber, serviceSid, code); + if (data.valid == false) throw new Error("Wrong SMS Code") + + // Valid SMS, do something... res.send(data); } catch (error) { res.status(400).json({message:error.message})