-
Notifications
You must be signed in to change notification settings - Fork 29
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
eGo #53
Open
vittoriamatteoli
wants to merge
280
commits into
Technigo:main
Choose a base branch
from
vittoriamatteoli:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
eGo #53
Changes from 250 commits
Commits
Show all changes
280 commits
Select commit
Hold shift + click to select a range
0996700
added points model and added user as required for the travel model
kathinka c68c869
Merge pull request #5 from kathinka/update-points
El1an3 25d899b
added endpoint to update user points in user model
kathinka bf60836
Merge pull request #6 from vittoriamatteoli/error-messages
kathinka cf25df0
Merge branch 'main' of https://github.com/vittoriamatteoli/project-final
kathinka 6db7677
added loading spinner
El1an3 94fc3d9
Added styled button, replaced buttons in login, logour and register. …
kathinka 8168e02
changes server endpoints to retrieve id
vittoriamatteoli 5060b23
functionality to fetch and display energy level
vittoriamatteoli 4e2f5d0
removed authorizeUser from patch request /energy
vittoriamatteoli 9de2c9e
added some styling energycard
vittoriamatteoli 1e468d2
set up energy level section + functionality
vittoriamatteoli 324c837
Energyslider:
kathinka 6a78352
Merge branch 'pointsmodel'
kathinka 88c180d
update[Backend] add default avatar array & random avatar function & a…
Yifan-858 aea1f7f
update[Frontend] add logic in Avatar component to fetch avatar img
Yifan-858 39b0360
updated /user/:id
vittoriamatteoli 2328ce5
debugging
vittoriamatteoli 2eee407
debugging
vittoriamatteoli d5d332f
debugging-can't retrieve id from the response
vittoriamatteoli 3f02b31
mobile styling login ann register
kathinka 6c553b8
Add required field for user in travel model, update login page to nav…
kathinka 9a6229c
Merge branch 'energy-slider'
kathinka 0b72bc0
debugging
vittoriamatteoli c99a094
fixed energy retrieve and update- removed buggy API
vittoriamatteoli 87daf38
styling sidebar + retrieve username + updated logo
vittoriamatteoli 592f03f
created and styled about page
vittoriamatteoli ca27468
added world
vittoriamatteoli 69d906a
update[FE]setup logic for fetching the avatar image in Avatar component
Yifan-858 be7d36d
finished design mobile about page
vittoriamatteoli bdf78cd
Merge pull request #9 from kathinka/button
vittoriamatteoli 67cab7e
Merge pull request #7 from vittoriamatteoli/pointsmodel
vittoriamatteoli 227a919
Merge pull request #8 from vittoriamatteoli/loading-spinner
vittoriamatteoli 312ec8d
added global styles and styled login and register page. added favic…
kathinka 56f4b0a
build
kathinka 03f8344
add images to public folder
kathinka 1f8c634
Merge branch 'style-login-register-page'
kathinka d91a184
merge styling with main - fresh build
kathinka ee43b62
install mui/icons-material
Yifan-858 7c33091
add mui dependencies
Yifan-858 596b791
Merge pull request #14 from vittoriamatteoli/cloudinary-setup
Yifan-858 f85e854
Merge branch 'main' into aboutpage
vittoriamatteoli a9e90a9
Merge pull request #15 from vittoriamatteoli/aboutpage
vittoriamatteoli 08d7212
Merge branch 'main' into sidebar
vittoriamatteoli 8470ac0
Merge pull request #13 from vittoriamatteoli/sidebar
vittoriamatteoli ad7a8e6
chore: Refactor BatterySlider component and update Button component
kathinka c6350ba
moved button from components to reusables
kathinka d194c3b
merge sidebar
vittoriamatteoli f247d09
Merge branch 'main' into energy-be
vittoriamatteoli 42ab8fe
Merge pull request #12 from vittoriamatteoli/energy-be
vittoriamatteoli a8ddfdc
merge energy card
vittoriamatteoli d7e974f
fixed routes for avatar and energyslider (and upcoming components), a…
kathinka 2d09f75
Fix routes so we can have multiple components on the same page using …
kathinka ee6a9fe
format
kathinka bebacd5
Fix routes so we can have multiple components on the same page using …
kathinka 701d631
fresh build
kathinka d4dd817
Refactor BatterySlider component, update Button component, and handle…
kathinka 6429ad7
Merge branch 'main' of https://github.com/kathinka/project-final into…
kathinka 4147815
Merge branch 'main' into style-login-register-page
Yifan-858 746ed37
Merge pull request #16 from kathinka/style-login-register-page
Yifan-858 062a984
Merge branch 'main' into routes-avatar
Yifan-858 b81cf3f
Merge pull request #17 from vittoriamatteoli/routes-avatar
Yifan-858 998334d
fix closing tag
Yifan-858 6e42e43
solved conflicts
vittoriamatteoli c1e7636
styled sidebar and changed structure according to new components
vittoriamatteoli 001f169
Merge remote-tracking branch 'origin/main' into Google-API-setup
Yifan-858 23e9913
Merge pull request #18 from vittoriamatteoli/sidebarStyle
Yifan-858 e9b31d3
Merge remote-tracking branch 'origin/main' into Google-API-setup
Yifan-858 dcde759
add basic structure to TravelCard
Yifan-858 eead102
started dashboard styling +points card
vittoriamatteoli 1e59f04
Merge pull request #19 from vittoriamatteoli/Google-API-setup
vittoriamatteoli 8a8ea31
Merge branch 'main' into dashboardStyle
vittoriamatteoli 2e5082c
Merge pull request #20 from vittoriamatteoli/dashboardStyle
vittoriamatteoli 1e15d20
styling dashboard
vittoriamatteoli 30de23a
add google route API & google-autocomplete search boxes & travel mode…
Yifan-858 cf7c1b9
Merge branch 'main' of https://github.com/kathinka/project-final into…
kathinka 68bf927
adjusted design to new figmafile and fixed conflicts
kathinka 7ae5f5c
Merge branch 'main' of https://github.com/vittoriamatteoli/project-fi…
kathinka 33a89db
format
kathinka 057dd6d
add handleConfirm to replace useEffect & update logic+style of autoco…
Yifan-858 dff9e2b
created pointsCard & battery-popup & fixed styling
vittoriamatteoli 013ad01
adjusted route for button in logout page
vittoriamatteoli b3946c8
add react-google-autocomplete in FE package.json
Yifan-858 2583aa6
Refactor BatterySlider component, update Button component, and handle…
kathinka 3b6fa0f
fresh build
kathinka da73ffc
update package and build
kathinka cbc849b
typo fix
kathinka 04d725e
added typo in import url
kathinka f73829f
ugh- temoved the mui icons as its import keeps breaking the deploy
kathinka 96a86b9
chore: Import IconButton from MUI for TravelForm component
kathinka 943230f
removed brackets from import as its a default export
kathinka 787b5fe
styled top and middle section, responsive
El1an3 e6f7c67
Merge branch 'style-login-register-page' into main
kathinka 043ccc6
styled bottom section
El1an3 2b78f1c
fixed bottom part and sign up button
El1an3 393367c
fix für 320px width
El1an3 5d9ef3b
fixed styling battery
vittoriamatteoli 697b382
Merge pull request #26 from vittoriamatteoli/dashboardStyle1
vittoriamatteoli 445b2df
update styling with grids grids grids to support move devices
kathinka d298927
added touch even listeners to battery slider
vittoriamatteoli c44336b
Merge branch 'main' into Google-API-setup
vittoriamatteoli d23f9c2
Merge pull request #24 from vittoriamatteoli/Google-API-setup
vittoriamatteoli 8b75deb
Merge branch 'main' into landing-page
vittoriamatteoli 759674e
Merge pull request #25 from vittoriamatteoli/landing-page
vittoriamatteoli 2e76db3
Merge pull request #27 from vittoriamatteoli/dashboardStyle1
vittoriamatteoli f3732ce
Merge branch 'main' of https://github.com/vittoriamatteoli/project-fi…
kathinka b69eecd
removed duplicates and unused files
kathinka 1b34576
formatting and removed duplicate files
kathinka 52bc751
fixed button logic for disabeling button on login
kathinka c6f42fb
fixed new ref to new globe
kathinka d559dee
added travelform again as it seems to be in use
kathinka 5aeedb3
Merge pull request #28 from kathinka/freshpull
kathinka 6557b81
styled responsiveness and added link to back arrow
El1an3 ef8904f
BE updated travel model and added new routes
vittoriamatteoli 45ca42b
loader button styling tweak
kathinka 690554c
small adjustments on the size of the globe
kathinka 1482038
Merge pull request #32 from vittoriamatteoli/freshpull
kathinka 8a8af69
fixed overflow issue on landingpage (new globe new issues)
kathinka f0bed79
Merge pull request #33 from vittoriamatteoli/freshpull
kathinka 9c3b319
add postTravelData & change travelPoint to direct display without con…
Yifan-858 bfa6bf7
fixed about us route, and duplicate avatar name
kathinka 5898f65
Merge pull request #34 from vittoriamatteoli/freshpull
kathinka e96707b
added import of about page
kathinka d9f7b12
Merge pull request #35 from vittoriamatteoli/freshpull
kathinka 111636a
Merge branch 'main' into travel-routes
Yifan-858 b9ca5a4
Merge pull request #31 from vittoriamatteoli/travel-routes
Yifan-858 d707423
merge origin
Yifan-858 9aa5633
updated postTravelData request body according to new routes
Yifan-858 4c736fe
Made a backarrow component who will take the user back one page in hi…
kathinka 5cbb3d8
Merge branch 'main' of https://github.com/vittoriamatteoli/project-fi…
kathinka b67cd0c
Merge pull request #36 from vittoriamatteoli/freshpull
kathinka ebda2a7
Merge branch 'main' into about-page
El1an3 743fbb1
Merge pull request #30 from vittoriamatteoli/about-page
El1an3 09610b0
add Distance display
Yifan-858 5147f00
Merge remote-tracking branch 'origin/main' into store-travel-data-FE
Yifan-858 d6f3852
add notes
Yifan-858 a1bb4d5
installed google autocomplete
vittoriamatteoli e5ca8b9
updated Readme file
vittoriamatteoli ec54089
add animation on the travel confirm button
Yifan-858 11de4f2
linked logo and fixed button text
El1an3 6a053ba
linked logo on register
El1an3 e74aa5b
linked logo in sidebar
El1an3 343b56a
chart for travel history
vittoriamatteoli 8d49ac4
get back MUI Button and unified the button style in both cards
Yifan-858 d5b9e1f
Merge pull request #37 from vittoriamatteoli/store-travel-data-FE
Yifan-858 07feec0
update the style for the search boxes
Yifan-858 d7c0424
added logo in points card and linked it to landing
El1an3 c26fb2a
update reponsiveness on font-size in both cards
Yifan-858 3046761
Update button text in Login page to "Sign in" instead of "Sign up". …
kathinka 079b03f
pull
Yifan-858 314859e
Merge pull request #39 from vittoriamatteoli/logo-functionality
vittoriamatteoli 19f886a
created mobile header
vittoriamatteoli 7733212
Merge pull request #38 from vittoriamatteoli/chart
vittoriamatteoli bc73da5
adjusted cards on dashboard
vittoriamatteoli 2adfd0f
Merge branch 'main' of https://github.com/vittoriamatteoli/project-final
kathinka d49e758
fixed small typo
kathinka 81aed2a
Merge pull request #41 from vittoriamatteoli/header-mobile
vittoriamatteoli df50e08
fixed buttons on landing, added rippleeffect, updated styles.
kathinka 03c298a
Update button styles and typography in Login and Register pages
kathinka f972c0c
Update button styles and typography in Login and Register pages - fix…
kathinka 3488022
fresh build
kathinka f1770e5
fresh pull from team main
kathinka 1db564c
Merge pull request #40 from vittoriamatteoli/dashcontext-and-calculat…
kathinka 5c53447
Revert "its all connected: read the description 👇🏼"
vittoriamatteoli 80176c0
Merge pull request #42 from vittoriamatteoli/revert-40-dashcontext-an…
vittoriamatteoli 7aeb17a
pushing changes from PR40 but not the styling
vittoriamatteoli df6e339
Merge pull request #43 from vittoriamatteoli/point-calc-kathinka
vittoriamatteoli 2b260fd
commented out Ripple
vittoriamatteoli 8db0585
Merge remote-tracking branch 'origin/main' into button-animation
Yifan-858 8896194
pulled and cleaned up
Yifan-858 004c032
size adjustment
Yifan-858 0bd9222
pulled changes and merged
vittoriamatteoli 19f2c37
add aria-label to buttons
Yifan-858 5d42f5f
responsiveness dashboard
vittoriamatteoli d6e8661
Merge pull request #45 from vittoriamatteoli/dashboard-responsiveness
vittoriamatteoli 12edb4a
Merge branch 'main' into button-animation
vittoriamatteoli e2875ce
Merge pull request #44 from vittoriamatteoli/button-animation
vittoriamatteoli 078f501
tweaks
kathinka 827d7db
small typo
kathinka a29f1f8
small adjustment to cards to adjust size due added text
vittoriamatteoli 766a21e
adjusted style on graph + minor errors
vittoriamatteoli cffff62
fixed button on landing page
kathinka 450e533
Merge pull request #46 from vittoriamatteoli/cards-style
Yifan-858 5f2b5eb
Merge pull request #47 from vittoriamatteoli/graph
Yifan-858 405d070
buttonupdate hover styles
kathinka 904911e
add missing token in BatterySlider
Yifan-858 3379d4b
add a confirm indicator in BatterySlider
Yifan-858 6667668
fixed some minor errors
Yifan-858 12afadc
adjust the travel icons and the texts in TravelForm
Yifan-858 8f89210
fix extra s
Yifan-858 2f5dcce
Merge pull request #48 from vittoriamatteoli/battery-update-effect
Yifan-858 4075a1f
Merge pull request #49 from vittoriamatteoli/travel-mode-icon-flow
Yifan-858 d21457e
no select on middle section, fixed overlap, deleted logo link
El1an3 0d404db
deleted outcommented code
El1an3 d924a14
adding UserFlowArrow, only rendered on Desktop/Tablet
El1an3 c29ca87
fix size globe, fonts, beige shadow, and select none on globe login/r…
El1an3 3642f9c
fixed battery dragging
vittoriamatteoli ecc1e8b
Merge pull request #50 from vittoriamatteoli/landing-fixes
vittoriamatteoli 2d7050a
Merge pull request #51 from vittoriamatteoli/userflow-arrow
vittoriamatteoli 90b03f6
Merge pull request #52 from vittoriamatteoli/login-register-fixes
vittoriamatteoli 6fbefe5
center globe on landing
El1an3 990ff2e
made background scrollable on about us. fixed globe to the bottom of …
El1an3 34d83e5
Update README.md
vittoriamatteoli 21b5e61
Update button styles and typography in Login and Register pages
kathinka 906b89d
styling fixes for very small screen iphone 5s/se
El1an3 646f085
Merge branch 'main' of https://github.com/vittoriamatteoli/project-fi…
kathinka 6d49b98
styling fixes
El1an3 5f930f6
Merge pull request #54 from vittoriamatteoli/styling
El1an3 c96e6f5
animation for points update
El1an3 f326656
styled username and sidebar for mobile, tablet, desktop
El1an3 649c85f
styled pointscard for mob/tablet/desk
El1an3 4c61763
styled energy card
El1an3 7ac117c
styled travel card, centered arrow
El1an3 eecc424
sidebar smaller to make sure travelform is not cut
El1an3 892e4a7
styled chart
El1an3 22497c0
Merge pull request #53 from vittoriamatteoli/battery-drag
vittoriamatteoli 4308b0d
Merge pull request #55 from vittoriamatteoli/dashboard-update-animation
vittoriamatteoli 83a9489
Merge pull request #56 from vittoriamatteoli/styling-dashboard
vittoriamatteoli a7f5ab3
mobile-graph with popup
vittoriamatteoli 2c73c7b
fixed popup for graph
vittoriamatteoli b522c1b
Merge pull request #57 from vittoriamatteoli/graph-fixing
vittoriamatteoli 0435316
set up pop-up default closed
vittoriamatteoli 51c683d
added accessibility
vittoriamatteoli beeff05
Merge pull request #58 from vittoriamatteoli/accessibility
vittoriamatteoli f2b3f53
deleted unused files, structured svg in folders, rerouted
El1an3 4e4cbf9
added tonl file
vittoriamatteoli a502e11
Merge pull request #59 from vittoriamatteoli/code-cleaning
El1an3 7a0d032
updated the readme file
vittoriamatteoli b701e6d
removed consol-logs
vittoriamatteoli 7b8c9e0
switched png to svg, adjusted alignment graph
vittoriamatteoli 253d2b9
Merge pull request #60 from vittoriamatteoli/console-log
El1an3 e470fe1
Merge pull request #61 from vittoriamatteoli/fixes
El1an3 5049e50
fixed position of BatteryUpdateIcon
El1an3 3b112b0
Merge pull request #62 from vittoriamatteoli/battery
El1an3 f17b9db
Merge branch 'main' of https://github.com/vittoriamatteoli/project-fi…
kathinka 38d10b2
admin styles
kathinka 6d89ea0
Merge branch 'styling-admin' into update
kathinka c95e3bd
removed issue with extra </link>
kathinka 5b791f9
Update Dashboard.jsx
kathinka 2512873
Update Landing.jsx
kathinka 5244fb0
Update BatterySlider.jsx
kathinka 0e38703
Update Button.jsx
kathinka 89cae54
Update Sidebar.jsx
kathinka 2b910e2
Merge pull request #63 from kathinka/update
vittoriamatteoli 8620ee5
fixed issue with admin dash due to password validation failing becaus…
kathinka f6e9545
Merge branch 'update' of https://github.com/kathinka/project-final in…
kathinka 1bb2142
cleanup - added reset of formfields and removed unused code
kathinka 03df9a2
Merge pull request #64 from kathinka/update
kathinka 98cbf1c
fixed logo & graph on dashboard
vittoriamatteoli d882a31
Merge pull request #65 from vittoriamatteoli/chart-loading
vittoriamatteoli 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.tabSize": 2 | ||
} |
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,13 +1,61 @@ | ||
# Final Project | ||
<h1 align="center">Welcome to eGo 👋</h1> | ||
<p> | ||
<a href="https://project-final-1-4w43.onrender.com" target="_blank"> | ||
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" /> | ||
</a> | ||
</p> | ||
|
||
Replace this readme with your own information about your project. | ||
> eGo is a mobile app that rewards eco-friendly travel choices. Integrated with the Google Routing API, it suggests low-emission routes for walking, cycling, public transport, and carpooling. Users earn "Green Points" for sustainable travel. | ||
> Developed with React, MongoDB, and styled-components, eGo tracks carbon footprint reduction and helps users set sustainability goals. | ||
|
||
Start by briefly describing the assignment in a sentence or two. Keep it short and to the point. | ||
### ✨ [Demo](https://ego-app.netlify.app/) | ||
|
||
## The problem | ||
## Tech stack | ||
<ul> | ||
<li>Styled-components</li> | ||
<li>Material UI </li> | ||
<li>Cloudinary</li> | ||
<li>Chart.js</li> | ||
<li>React-google-autocomplete</li> | ||
<li>React-joyride</li> | ||
</ul> | ||
|
||
Describe how you approached to problem, and what tools and techniques you used to solve it. How did you plan? What technologies did you use? If you had more time, what would be next? | ||
## Development process | ||
|
||
## View it live | ||
## 1 Step | ||
We designed the interface in Figma, established the primary database models, and set up the main server routes. | ||
## 2 Step | ||
We set up all the backend endpoints for user registration and login, and on the frontend, we implemented the forms and main component. | ||
## 3 Step | ||
We implemented a model for travels and stored points in the backend. On the frontend, we integrated all necessary travel forms, graphs, and components. | ||
## 4 Step | ||
We integrated the admin functionality and its dashboard and worked on the final documentation.To make the whole app more user-friendly we integrated a walkthrough. | ||
|
||
Every project should be deployed somewhere. Be sure to include the link to the deployed project so that the viewer can click around and see what it's all about. | ||
## Extra features | ||
If we had more time we would start integrate the following features: | ||
- Rewards for points | ||
- Weather data | ||
- Add a function for display the password to the user when they log in | ||
- AI coach integration. | ||
- Add function for the user to upload their profile image to Cloudinary. | ||
- Integrate carbon footprints API. | ||
|
||
## Install | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
npm run dev | ||
``` | ||
|
||
## Author | ||
|
||
👤 ** [Yifan](https://github.com/Yifan-858) - [Kathinka](https://github.com/kathinka) - [Eliane ](https://github.com/El1an3 ) - [Vittoria](https://github.com/vittoriamatteoli)** | ||
|
||
## Show your support | ||
|
||
Give a ⭐️ if this project helped you! |
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,15 @@ | ||
node_modules | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
build | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
package-lock.json |
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,73 @@ | ||
import User from "../models/user-model.js" | ||
import dotenv from "dotenv" | ||
import jwt from "jsonwebtoken" | ||
|
||
dotenv.config() | ||
const SECRET = process.env.SECRET || "toast is the best secret" | ||
|
||
const authenticateUser = async (req, res, next) => { | ||
try { | ||
const authHeader = req.header("Authorization") | ||
if (!authHeader) { | ||
return res.status(401).json({ | ||
loggedOut: true, | ||
message: "Authorization header is missing", | ||
}) | ||
} | ||
|
||
const parts = authHeader.split(" ") | ||
if (parts.length !== 2 || parts[0] !== "Bearer") { | ||
return res.status(401).json({ | ||
loggedOut: true, | ||
message: "Invalid authorization format. Expected 'Bearer <token>'", | ||
}) | ||
} | ||
|
||
const accessToken = parts[1] | ||
req.accessToken = accessToken // add the token to the request object in case we need it for later use in other middlewares.. | ||
|
||
const decoded = jwt.verify(accessToken, SECRET) | ||
if (!decoded) { | ||
return res.status(403).json({ | ||
message: "Invalid access token", | ||
}) | ||
} | ||
const user = await User.findOne({ _id: decoded.id , role:decoded.role}); | ||
if (!user) { | ||
return res.status(404).json({ | ||
message: "User not found", | ||
}) | ||
} | ||
req.user = user | ||
next() | ||
} catch (error) { | ||
res.status(403).json({ message: "Access forbidden", error: error.message }) | ||
} | ||
} | ||
|
||
// add authorization to the routes that need it, if we want to make an GUI for the admins who can see all users and their data and preform operations on the data - or if we want some kind of superusers (paid access for instance - but then we need to add "roles" to the user model) | ||
|
||
const authorizeUser = (role) => { | ||
return (req, res, next) => { | ||
if (!role.includes(req.user.role)) { | ||
return res.status(403).json({ message: "Access forbidden" }); | ||
} | ||
next() | ||
} | ||
} | ||
|
||
// log out the user (and lets remmeberdelete the session token) | ||
const signOut = async (req, res) => { | ||
try { | ||
const user = req.user | ||
// option to add the used token to a blacklist if we want to set that up | ||
//option to add a refresh token if we want the service to "remember" the user and keep the user logged in for a longer period of time. | ||
//user.refreshToken = null; | ||
//await user.save(); | ||
res.json({ message: "User logged out successfully" }) | ||
} catch (error) { | ||
res.status(500).json({ message: "Error logging out", error: error.message }) | ||
} | ||
} | ||
|
||
export { authenticateUser, authorizeUser, signOut } |
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,26 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const pointsSchema = new mongoose.Schema({ | ||
points: { | ||
type: Number, | ||
required: [true, "Points is required"], | ||
min: [0, "Points cannot be negative"], | ||
}, | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User', | ||
requred: [true, "User is required"], | ||
}, | ||
travel: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'Travel', | ||
required: [true, "Travel is required"], | ||
}, | ||
date:{ | ||
type: Date, | ||
required: [true, "Date is required"], | ||
default: Date.now, | ||
}, | ||
}); | ||
|
||
export default mongoose.model('Points', pointsSchema); |
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,52 @@ | ||
import mongoose from "mongoose"; | ||
import { updatePoints } from "../utils/updatePoints"; | ||
|
||
const travelSchema = new mongoose.Schema({ | ||
distance: { | ||
type: Number, | ||
required: [true, "Distance is required"], | ||
min: [0, "Distance cannot be negative"], | ||
}, | ||
mode: { | ||
type: String, | ||
enum: ["DRIVE", "BICYCLE", "WALK", "TRANSIT"], | ||
required: [true, "Way of travel is required"], | ||
}, | ||
date: { | ||
type: Date, | ||
default: () => Date.now(), | ||
}, | ||
origin: { | ||
type: String, | ||
required: [true, "Start location is required"], | ||
}, | ||
destination: { | ||
type: String, | ||
required: [true, "End location is required"], | ||
}, | ||
user: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "User", | ||
required: [true, "User is required"], | ||
}, | ||
travelPoints: { | ||
type: Number, | ||
required: [true, "Travel points are required"], | ||
}, | ||
}); | ||
|
||
// Update user's points after saving a travel | ||
travelSchema.post("save", function (doc, next) { | ||
const userId = doc.user; | ||
const travelId = doc._id; | ||
const travelPoints = doc.travelPoints; | ||
console.log("calculated points by travelschema:", travelPoints); | ||
console.log("userId by travelschema:", userId); | ||
console.log("travelId by travelschema:", travelId); | ||
|
||
updatePoints(userId, travelId, travelPoints) | ||
.then(() => next()) | ||
.catch((err) => next(err)); | ||
}); | ||
|
||
export default mongoose.model("Travel", travelSchema); |
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,86 @@ | ||
import mongoose from "mongoose"; | ||
import bcryptjs from "bcryptjs"; | ||
import { getRandomAvatarUrl } from "../utils/avatarUtils.js"; | ||
|
||
const SALT_ROUNDS = 12; // make this configurable so we can adjust the security level if needed | ||
|
||
const userSchema = new mongoose.Schema({ | ||
username: { | ||
type: String, | ||
required: [true, "Username is required"], | ||
minlength: [3, "Username must be at least 3 characters long"], | ||
maxlength: [30, "Username must be at most 30 characters long"], | ||
unique: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: [true, "Email is required"], | ||
unique: true, | ||
match: [/\S+@\S+\.\S+/, "Email is invalid"], | ||
}, | ||
password: { | ||
type: String, | ||
required: [true, "Password is required"], | ||
minlength: [6, "Password must be at least 6 characters long"], | ||
}, | ||
role: { | ||
type: String, | ||
default: "user", | ||
}, | ||
// optional field for a refresh token if we want to keep the user logged in for a longer period of time | ||
//refreshToken: { | ||
// type: String, | ||
// default: null, | ||
// }, | ||
|
||
points: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
energyLevel: { | ||
type: Number, | ||
default: 5, | ||
}, | ||
avatarUrl: { | ||
type: String, | ||
default: function () { | ||
return getRandomAvatarUrl(); | ||
}, | ||
}, | ||
}); | ||
//update the users travelpoints after saving a travel | ||
userSchema.methods.incrementPoints = function (points) { | ||
return this.model("User") | ||
.updateOne({ _id: this._id }, { $inc: { points: points } }) | ||
.then(() => { | ||
console.log( | ||
`Points incremented by ${points}. New points: ${this.points + points}` | ||
); | ||
}) | ||
.catch((error) => { | ||
console.error(`Error incrementing points: ${error}`); | ||
}); | ||
}; | ||
|
||
//this uses matchPassword method to compare the entered password with the hashed password in the database | ||
userSchema.methods.matchPassword = async function (enteredPassword) { | ||
return await bcryptjs.compare(enteredPassword, this.password); | ||
}; | ||
//This adds a pre-save (pre) hook to hash the password *before* saving it to the database so we don't store the password in plain text | ||
userSchema.pre("save", async function (next) { | ||
// we only hash the password if it has been modified (or is new) | ||
if (!this.isModified("password")) { | ||
return next(); | ||
} | ||
|
||
this.password = await bcryptjs.hash(this.password, SALT_ROUNDS); | ||
|
||
// set a random avatar URL for new users | ||
if (this.isNew) { | ||
this.avatarUrl = this.avatarUrl || getRandomAvatarUrl(); | ||
} | ||
|
||
next(); | ||
}); | ||
|
||
export default mongoose.model("User", userSchema); |
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
Oops, something went wrong.
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.
please add this to .gitignore and delete the folder 🧹