├── backend ├── .gitignore ├── .env.sample ├── .vscode │ └── settings.json ├── deno.json ├── env.ts ├── import_map.json ├── database.ts └── index.ts ├── frontend └── text └── README.md /backend/.gitignore: -------------------------------------------------------------------------------- 1 | .env -------------------------------------------------------------------------------- /frontend/text: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /backend/.env.sample: -------------------------------------------------------------------------------- 1 | MONGO_URL= 2 | DUMMY_EMAIL= 3 | DUMMY_PASSWORD= -------------------------------------------------------------------------------- /backend/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "deno.enable": true 3 | } -------------------------------------------------------------------------------- /backend/deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "importMap": "./import_map.json", 3 | "tasks": { 4 | "start": "deno run --allow-net --allow-read --allow-env index.ts" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /backend/env.ts: -------------------------------------------------------------------------------- 1 | import { config } from "dotenv"; 2 | import { cleanEnv, url, str } from "envalid"; 3 | 4 | await config({ export: true }); 5 | 6 | export default cleanEnv(Deno.env.toObject(), { 7 | MONGO_URL: url(), 8 | DUMMY_EMAIL: str(), 9 | DUMMY_PASSWORD: str(), 10 | }); 11 | -------------------------------------------------------------------------------- /backend/import_map.json: -------------------------------------------------------------------------------- 1 | { 2 | "imports": { 3 | "dotenv": "https://deno.land/std@0.154.0/dotenv/mod.ts", 4 | "envalid": "https://deno.land/x/envalid@0.1.2/mod.ts", 5 | "oak": "https://deno.land/x/oak@v11.1.0/mod.ts", 6 | "mongo": "https://deno.land/x/mongo@v0.31.1/mod.ts" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Define24 2 | The template repository for definehack2024 3 | 4 | ![DefineHack2024](https://github.com/Definehack/Define24/assets/79042374/4d6c229a-5048-4ac9-bba6-c0e835e22097) 5 | 6 | ## Project Name 7 | Tell us about your project here 8 | 9 | ### Team Members 10 | [1. Aditya S](https://github.com/xditya) 11 | [2. Abdul Razaq A](https://github.com/xmcfrt) 12 | [3. Rohin Sabu](enter_github_id_here) 13 | [4. Abid Noushad Humam](enter_github_id_here) 14 | 15 | ### Link to Project 16 | [Embed the live link of project](live_link) 17 | 18 | ### How it Works ? 19 | Explaining the working of project 20 | Embed video of project demo 21 | 22 | ### Technologies used 23 | > React 24 | > Vite 25 | > MongoDB 26 | > Bootstrtap 27 | > Deno 28 | > Typescript 29 | > Javascript 30 | 31 | ### How to configure 32 | - Get a mongodb url from [mongodb](https://mongodb.com) 33 | - Setup the .env file by editing and renaming [.env.sample](./backend/env.ts) 34 | 35 | ### How to Run 36 | - Deploy [backend](./backend/). 37 | - Deploy [frontend](./frontend/). 38 | 39 | ### Other Links 40 | Provide any other links ( for eg. Wireframe , UI, Abstract, Presentation ) 41 | -------------------------------------------------------------------------------- /backend/database.ts: -------------------------------------------------------------------------------- 1 | import { MongoClient, ObjectId } from "mongo"; 2 | 3 | import config from "./env.ts"; 4 | 5 | console.log("Connecting to MongoDB..."); 6 | const client = new MongoClient(); 7 | const MONGO_URL = new URL(config.MONGO_URL); 8 | if (!MONGO_URL.searchParams.has("authMechanism")) { 9 | MONGO_URL.searchParams.set("authMechanism", "SCRAM-SHA-1"); 10 | } 11 | try { 12 | await client.connect(MONGO_URL.href); 13 | } catch (err) { 14 | console.error("Error connecting to MongoDB", err); 15 | throw err; 16 | } 17 | 18 | const db = client.database("RebootRescue"); 19 | 20 | interface AccountSchema { 21 | _id: ObjectId; 22 | name: string; 23 | email: string; 24 | password: string; 25 | loc: string; 26 | year: number; 27 | } 28 | 29 | const usersDb = db.collection("users"); 30 | 31 | export async function createUser( 32 | name: string, 33 | email: string, 34 | password: string, 35 | loc: string, 36 | year: number 37 | ) { 38 | if (await usersDb.findOne({ email })) { 39 | throw new Error("User already exists"); 40 | } else { 41 | return await usersDb.insertOne({ 42 | name, 43 | email, 44 | password, 45 | loc, 46 | year, 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /backend/index.ts: -------------------------------------------------------------------------------- 1 | import config from "./env.ts"; 2 | import { Application, Router } from "oak"; 3 | import { createUser } from "./database.ts"; 4 | 5 | const router = new Router(); 6 | 7 | router.post("/login", async (ctx) => { 8 | const params = await ctx.request.body().value; 9 | if (!params) { 10 | return (ctx.response.body = { error: "No params provided." }); 11 | } 12 | if (!params.email || !params.password) { 13 | return (ctx.response.body = { error: "Authentication Failed." }); 14 | } 15 | 16 | if ( 17 | params.email != config.DUMMY_EMAIL || 18 | params.password != config.DUMMY_PASSWORD 19 | ) { 20 | return (ctx.response.body = { error: "Authentication Failed." }); 21 | } else { 22 | ctx.response.body = { success: true }; 23 | } 24 | }); 25 | 26 | router.post("/register", async (ctx) => { 27 | const params = await ctx.request.body().value; 28 | if (!params) { 29 | return (ctx.response.body = { error: "No params provided." }); 30 | } 31 | if ( 32 | !params.email || 33 | !params.password || 34 | !params.name || 35 | !params.loc || 36 | !params.year 37 | ) { 38 | return (ctx.response.body = { error: "Registration Failed." }); 39 | } 40 | 41 | try { 42 | await createUser( 43 | params.name, 44 | params.email, 45 | params.password, 46 | params.loc, 47 | params.year 48 | ); 49 | } catch { 50 | return (ctx.response.body = { error: "Registration Failed." }); 51 | } 52 | ctx.response.body = { success: true }; 53 | }); 54 | 55 | const app = new Application(); 56 | app.use(async (ctx, next) => { 57 | ctx.response.headers.set("Access-Control-Allow-Origin", "*"); 58 | ctx.response.headers.set( 59 | "Access-Control-Allow-Headers", 60 | "Origin, X-Requested-With, Content-Type, Accept, Authorization" 61 | ); 62 | ctx.response.headers.set( 63 | "Access-Control-Allow-Methods", 64 | "GET, POST, PUT, DELETE, OPTIONS" 65 | ); 66 | await next(); 67 | }); 68 | 69 | app.use(router.routes()); 70 | app.use(router.allowedMethods()); 71 | 72 | app.addEventListener("error", (e) => console.log(e)); 73 | 74 | console.log("> Started listeneing on PORT 8000!"); 75 | 76 | await app.listen({ port: 8000 }); 77 | --------------------------------------------------------------------------------