diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..a47e5ff Binary files /dev/null and b/.DS_Store differ diff --git a/app/App.tsx b/app/App.tsx index 498ca44..399aea8 100644 --- a/app/App.tsx +++ b/app/App.tsx @@ -1,21 +1,32 @@ +<<<<<<< HEAD +import { useState } from 'react'; +import PhoneInput from 'react-phone-number-input'; +import 'react-phone-number-input/style.css'; + +function test() { +======= import { StatusBar } from 'expo-status-bar'; import { StyleSheet, Text, View } from 'react-native'; - -import WelcomePage from './components/welcome'; +import Example from './components/sign-in'; export default function App() { return ( - + + ); +>>>>>>> 3799a0a1ae022420ff10b334a2d7723c12090d77 } - -const styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: '#fff', - alignItems: 'center', - justifyContent: 'center', - }, -}); +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/components/sign-in.tsx b/app/components/sign-in.tsx new file mode 100644 index 0000000..36cf35b --- /dev/null +++ b/app/components/sign-in.tsx @@ -0,0 +1,68 @@ +<<<<<<< HEAD +import { useState } from 'react'; +import PhoneInput from 'react-phone-number-input'; +import 'react-phone-number-input/style.css'; +======= +>>>>>>> 3799a0a1ae022420ff10b334a2d7723c12090d77 + + +function Example() { + // `value` will be the parsed phone number in E.164 format. + // Example: "+12133734253". +<<<<<<< HEAD + const [value, setValue] = useState() +======= + const [value, setValue] = useState("1") +>>>>>>> 3799a0a1ae022420ff10b334a2d7723c12090d77 + return ( + + ) +} +export default Example; +======= + onChange={() =>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, + }, +}); +*/ +>>>>>>> 3799a0a1ae022420ff10b334a2d7723c12090d77 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", diff --git a/server/.env b/server/.env deleted file mode 100644 index 44b9b8c..0000000 --- a/server/.env +++ /dev/null @@ -1,4 +0,0 @@ -MONGO_ADMIN_USERNAME = "thiwalk30-admin" -MONGO_ADMIN_PASSWORD = "Nwn3sXmdo9mwEqZx" -AWS_ACCESS_KEY = "AKIA3ALRGMM244E2YBZZ" -AWS_SECRET_ACCESS_KEY = "uKR37SNf++NH6WN0p+Dxhv5r7+tTUjgRr+QmI9p6" \ No newline at end of file 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 new file mode 100644 index 0000000..91c865d --- /dev/null +++ b/server/backend_helper/sms_validation.js @@ -0,0 +1,25 @@ +// 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 = process.env.TWILIO_ACCOUNT_SID; +const authToken = process.env.TWILIO_AUTH_TOKEN; +const client = require("twilio")(accountSid, authToken); + +const sendSms = async (number, verifySid) => { + return client.verify.v2 + .services(verifySid) + .verifications.create({ to: number, channel: "sms" }) + .then((verification) => verification); +} + +const verify = async (number, verifySid, code) => { + return client.verify.v2.services(verifySid) + .verificationChecks + .create({to: number, code: code}) + .then(verification_check => verification_check); +} + +module.exports = { + sendSms, + verify +} \ No newline at end of file diff --git a/server/index.js b/server/index.js index 11dc253..49b6957 100644 --- a/server/index.js +++ b/server/index.js @@ -4,25 +4,14 @@ 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, - } -}); - 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!"); const app = express(); @@ -34,9 +23,8 @@ async function run() { app.listen(3000, () => { console.log(`Server started at ${3000}`); }) - } finally { - // Ensures that the client will close when you finish/error - await client.close(); + } catch (error) { + console.log(error); } } 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..4e28f55 --- /dev/null +++ b/server/routes/auth.js @@ -0,0 +1,31 @@ +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.sendSms(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); + 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}) + } +}) + +module.exports = router \ No newline at end of file diff --git a/server/routes/index.js b/server/routes/index.js index 0f23aa2..61913df 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("./auth"); + 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