forked from CodeYourFuture/cyf-final-project-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#33 - Display GitHub input when the user is Graduate - Sabella #36
Merged
+115
−90
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,68 @@ | ||
main { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 100vh; | ||
background-color: #FFFFFF; | ||
font-family: Arial, sans-serif; | ||
color: #333333; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 100vh; | ||
background-color: #ffffff; | ||
font-family: Arial, sans-serif; | ||
color: #333333; | ||
} | ||
|
||
main > div { | ||
text-align: center; | ||
margin-bottom: 20px; | ||
text-align: center; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.logo { | ||
width: 100px; | ||
height: 100px; | ||
margin-bottom: 20px; | ||
width: 100px; | ||
height: 100px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.message { | ||
font-size: 24px; | ||
font-weight: bold; | ||
margin-bottom: 20px; | ||
font-size: 24px; | ||
font-weight: bold; | ||
margin-bottom: 20px; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
color: #EE4434; | ||
font-size: 18px; | ||
margin: 0 10px; | ||
transition: color 0.3s ease; | ||
text-decoration: none; | ||
color: #ee4434; | ||
font-size: 18px; | ||
margin: 0 10px; | ||
transition: color 0.3s ease; | ||
} | ||
|
||
a:hover { | ||
color: #b4001b; | ||
color: #b4001b; | ||
} | ||
|
||
p > a { | ||
font-size: 20px; | ||
font-weight: bold; | ||
background-color: #EE4434; | ||
color: white; | ||
padding: 10px 20px; | ||
border-radius: 5px; | ||
transition: background-color 0.3s ease, color 0.3s ease; | ||
font-size: 20px; | ||
font-weight: bold; | ||
background-color: #ee4434; | ||
color: white; | ||
padding: 10px 20px; | ||
border-radius: 5px; | ||
transition: | ||
background-color 0.3s ease, | ||
color 0.3s ease; | ||
} | ||
|
||
p > a:hover { | ||
background-color: #b4001b; | ||
background-color: #b4001b; | ||
} | ||
|
||
.border-color-1 { | ||
border-color: #E3E3E3; } | ||
border-color: #e3e3e3; | ||
} | ||
|
||
.border-color-2 { | ||
border-color: #A9A9A9; | ||
border-color: #a9a9a9; | ||
} | ||
|
||
.error-message { | ||
color: #FF0000; | ||
font-weight: bold; | ||
color: #ff0000; | ||
font-weight: bold; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,8 @@ router.get("/", (_, res) => { | |
res.json({ message: "Hello, world!" }); | ||
}); | ||
|
||
|
||
|
||
|
||
router.post("/users", async (req, res) => { | ||
const { username, passwordHash, userType } = req.body; | ||
router.post("/users", async (req, res) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be signup by name not users |
||
const { username, passwordHash, userType, userGithub } = req.body; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kindly use bcrypt to hash the password from the backend, not the frontend |
||
|
||
if (!username) { | ||
return res.status(422).json({ message: "Username field is required" }); | ||
|
@@ -31,50 +28,58 @@ router.post("/users", async (req, res) => { | |
|
||
try { | ||
const result = await db.query( | ||
"INSERT INTO users (username, password_hash, user_type) VALUES ($1, $2, $3) RETURNING id", | ||
"INSERT INTO users (username, password_hash, user_type) VALUES ($1, $2, $3) RETURNING id ", | ||
[username, passwordHash, userType] | ||
); | ||
|
||
const newUserID = result.rows[0].id; | ||
|
||
if (userType === "graduate" && userGithub) { | ||
await db.query( | ||
"INSERT INTO portfolios (user_id, github_username) VALUES ($1, $2)", | ||
[newUserID, userGithub] | ||
); | ||
} | ||
|
||
res.status(200).json({ success: true, data: { id: newUserID } }); | ||
} catch (error) { | ||
|
||
if (error.code === "23505") { | ||
return res | ||
.status(409) | ||
.json({ success: false, error: "Username already exists" }); | ||
} | ||
res | ||
.status(500) | ||
.json({ success: false, error: "Failed to create a new User into database" }); | ||
} | ||
res.status(500).json({ | ||
success: false, | ||
error: "Failed to create a new User into database", | ||
}); | ||
} | ||
}); | ||
|
||
|
||
router.get("/users/:id", roleBasedAuth("graduate", "mentor", "recruiter"), async (req, res) => { | ||
const userId = req.params.id; | ||
try { | ||
const result = await db.query("SELECT * FROM users WHERE id = $1", [ | ||
userId, | ||
]); | ||
|
||
if (result.rows.length === 0) { | ||
return res | ||
.status(404) | ||
.json({ success: false, message: "User not found" }); | ||
} | ||
|
||
res.status(200).json({ success: true, data: result.rows[0] }); | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ | ||
router.get( | ||
"/users/:id", | ||
roleBasedAuth("graduate", "mentor", "recruiter"), | ||
async (req, res) => { | ||
const userId = req.params.id; | ||
try { | ||
const result = await db.query("SELECT * FROM users WHERE id = $1", [ | ||
userId, | ||
]); | ||
|
||
if (result.rows.length === 0) { | ||
return res | ||
.status(404) | ||
.json({ success: false, message: "User not found" }); | ||
} | ||
|
||
res.status(200).json({ success: true, data: result.rows[0] }); | ||
} catch (error) { | ||
res.status(500).json({ | ||
success: false, | ||
error: "Failed to fetch User from the database", | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
); | ||
|
||
router.delete("/users/:id", async (req, res) => { | ||
const userId = req.params.id; | ||
|
@@ -93,12 +98,10 @@ router.delete("/users/:id", async (req, res) => { | |
|
||
res.status(200).json({ success: true, data: { id: result.rows[0].id } }); | ||
} catch (error) { | ||
res | ||
.status(500) | ||
.json({ | ||
success: false, | ||
error: "Failed to delete User from the database", | ||
}); | ||
res.status(500).json({ | ||
success: false, | ||
error: "Failed to delete User from the database", | ||
}); | ||
} | ||
}); | ||
|
||
|
@@ -112,11 +115,9 @@ router.post("/sign-in", async (req, res) => { | |
} | ||
|
||
try { | ||
const result = await db.query( | ||
"SELECT * FROM users WHERE username = $1", | ||
[username] | ||
); | ||
|
||
const result = await db.query("SELECT * FROM users WHERE username = $1", [ | ||
username, | ||
]); | ||
|
||
if (result.rows.length === 0) { | ||
return res | ||
|
@@ -139,7 +140,7 @@ router.post("/sign-in", async (req, res) => { | |
); | ||
|
||
user.token = token; | ||
res.status(200).json({ success: true, data: { "user": user } }); | ||
res.status(200).json({ success: true, data: { user: user } }); | ||
} catch (error) { | ||
res.status(500).json({ success: false, error: "Failed to log in" }); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job done