-
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
Showing
9 changed files
with
89 additions
and
140 deletions.
There are no files selected for viewing
Submodule Orbital
added at
13e1ab
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 |
---|---|---|
@@ -1,65 +1,57 @@ | ||
const express = require('express'); | ||
const planetscale = require('./config/planetscale') | ||
const cors = require('cors') | ||
const planetscale = require('./config/planetscale'); | ||
const cors = require('cors'); | ||
|
||
const app = express(); | ||
|
||
const PORT = 3002; | ||
app.use(cors()); | ||
app.use(express.json()) | ||
|
||
app.use(express.json()); | ||
|
||
// Route for creating the user | ||
app.post('/api/signup', (req,res)=> { | ||
|
||
const email = req.body.email; | ||
const username = req.body.username; | ||
const password = req.body.password; | ||
const query = "INSERT INTO users (email, username, password_hash) VALUES (?,?,?)"; | ||
|
||
console.log(email, username, password); | ||
|
||
planetscale.query(query,[email, username, password], ( err, result ) => { | ||
if(err) { | ||
console.log(err); | ||
} | ||
console.log(result); | ||
}); | ||
app.post('/api/signup', (req, res) => { | ||
const email = req.body.email; | ||
const username = req.body.username; | ||
const password = req.body.password; | ||
const query = "INSERT INTO users (email, username, password_hash) VALUES (?,?,?)"; | ||
|
||
planetscale.query(query, [email, username, password], (err, result) => { | ||
if (err) { | ||
return res.status(500).json({ error: 'Account already exists' }); | ||
} | ||
return res.status(200).json({ message: 'Signup successful' }); | ||
}); | ||
}); | ||
|
||
// Route for login | ||
app.get('/api/login/:email', (req, res) => { | ||
|
||
const email = req.params.email; | ||
const query = `SELECT * FROM users where email = ?`; | ||
|
||
planetscale.query(query, email, (err, data) => { | ||
// const p = data.params.password; | ||
// if (err) return res.json({ error: err.message }); | ||
// else if (p != password) return res.send(false); | ||
res.send(data); | ||
}); | ||
// Route for login | ||
app.post('/api/login', (req, res) => { | ||
const email = req.body.email; | ||
const password = req.body.password; | ||
const query = `SELECT * FROM users WHERE email = ?`; | ||
|
||
planetscale.query(query, email, (err, result) => { | ||
if (!data || data.length === 0) { | ||
return res.status(404).json({ error: 'Invalid email or password' }); | ||
} else if (result[0].password_hash !== password) { | ||
return res.status(401).json({ error: 'Invalid email or password' }); | ||
} | ||
return res.status(200).json({ message: 'Login successful' }); | ||
}); | ||
}); | ||
|
||
// Route for deleting account | ||
app.post('/api/delete', (req,res)=> { | ||
|
||
const email = req.body.email; | ||
const username = req.body.username; | ||
const password = req.body.password; | ||
const query = `DELETE FROM users WHERE email = ?`; | ||
|
||
console.log(email, username, password); | ||
|
||
planetscale.query(query, email, ( err, result ) => { | ||
if(err) { | ||
console.log(err); | ||
} | ||
console.log(result); | ||
}); | ||
app.post('/api/delete-account', (req, res) => { | ||
const email = req.body.email; | ||
const query = `DELETE FROM users WHERE email = ?`; | ||
|
||
planetscale.query(query, email, (err, result) => { | ||
if (err) { | ||
return res.status(500).json({ error: 'An error occurred while deleting the account' }); | ||
} | ||
return res.status(200).json({ message: 'Account deleted successfully' }); | ||
}); | ||
}); | ||
|
||
|
||
app.listen(PORT, ()=>{ | ||
console.log(`Server is running on ${PORT}`) | ||
}) | ||
app.listen(PORT, () => { | ||
console.log(`Server is running on ${PORT}`); | ||
}); |
File renamed without changes
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,37 @@ | ||
import axios from 'axios'; | ||
|
||
// create new account | ||
const addNewUser = async (email, username, password) => { | ||
try { | ||
const resp = await axios.post('http://localhost:3002/api/signup', { email: email, username: username, password: password }); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
}; | ||
|
||
// login | ||
const checkLoginDetails = async (email, password) => { | ||
try { | ||
const resp = await axios.get(`http://localhost:3002/api/login`, { email: email, password: password }); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
}; | ||
|
||
// delete account | ||
const deleteAccount = async (email, password) => { | ||
try { | ||
const resp = await axios.get(`http://localhost:3002/api/delete-account`, { email: email, password: password }); | ||
return true; | ||
} catch (err) { | ||
return false; | ||
} | ||
}; | ||
|
||
export { | ||
addNewUser, | ||
checkLoginDetails, | ||
deleteAccount, | ||
}; |
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
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
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
58 changes: 0 additions & 58 deletions
58
project/my-project-name/frontend/src/components/Storage.js
This file was deleted.
Oops, something went wrong.
18 changes: 4 additions & 14 deletions
18
project/my-project-name/frontend/src/components/UserProfile.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.