Skip to content

tarea completada #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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
This is a fork of the original project. It's intended to set as a codebase for the final task for the students of the course 4 of Pilar Tecno.

## **[You're now facing the Final Task](https://www.youtube.com/watch?v=Jxk9DqdYsJ4)**



You have the freedom to use any free or open API for your project. You may use as many as you need/want.

Some suggestions are:

- [NASA API](https://api.nasa.gov/)
- [The Audio DB](https://www.theaudiodb.com/api_guide.php)
- [The cat facts](https://alexwohlbruck.github.io/cat-facts/docs/)
- [API del Servicio de Normalización de Datos Geográficos de
Argentina](https://datosgobar.github.io/georef-ar-api/)

You can browse more API's [here](https://public-apis.io/).

Keep in mind some API's will need some registration and/or are free for trial purposes only.

**The final task consists in you making three or more endpoints that must consume one external service API (like the ones listed before).**

**It is required that you pay special attention to the structure used for the endpoint.** Make sure to use:

* Routes.

* Controllers.

* Services.

* Environment variables for sensitive data (like API keys or DB access).

**In one of the three endpoints you code, it is required that you save the response to a Mongodb collection.** You can use MongoDB Atlas for easy setup, or a local instance if you want.

**It is required that the endpoints are protected with a JWT Token.** The endpoints should only allow users with the role "user" to use the endpoint.

# Node.js JWT Refresh Token with MongoDB example
JWT Refresh Token Implementation with Node.js Express and MongoDB. You can know how to expire the JWT, then renew the Access Token with Refresh Token.

Expand Down
8 changes: 3 additions & 5 deletions app/config/auth.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module.exports = {
secret: "bezkoder-secret-key",
// jwtExpiration: 3600, // 1 hour
// jwtRefreshExpiration: 86400, // 24 hours
jwtExpiration: 3600,
jwtRefreshExpiration: 86400,


/* for test */
jwtExpiration: 60, // 1 minute
jwtRefreshExpiration: 120, // 2 minutes
};
13 changes: 9 additions & 4 deletions app/config/db.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const dbUser = process.env.DB_USER;
const dbPass = process.env.DB_PASSWORD;
const dbName = 'Pilar-Tecno-LR'
const dbUri = `mongodb+srv://${dbUser}:${dbPass}@cluster0.qtcrz.mongodb.net/${dbName}?retryWrites=true&w=majority`;
const mongooseOptions = {useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true};


module.exports = {
HOST: "localhost",
PORT: 27017,
DB: "bezkoder_db"
};
dbUri, mongooseOptions
}
2 changes: 1 addition & 1 deletion app/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ exports.signin = (req, res) => {
if (!passwordIsValid) {
return res.status(401).send({
accessToken: null,
message: "Invalid Password!",
message: "Incorrecto Password!",
});
}

Expand Down
12 changes: 6 additions & 6 deletions app/middlewares/authJwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ const isAdmin = (req, res, next) => {
}

for (let i = 0; i < roles.length; i++) {
if (roles[i].name === "admin") {
if (roles[i].name === "admi") {
next();
return;
}
}

res.status(403).send({ message: "Require Admin Role!" });
res.status(403).send({ message: "Require Admi Role!" });
return;
}
);
});
};

const isModerator = (req, res, next) => {
const isModerador = (req, res, next) => {
User.findById(req.userId).exec((err, user) => {
if (err) {
res.status(500).send({ message: err });
Expand All @@ -79,13 +79,13 @@ const isModerator = (req, res, next) => {
}

for (let i = 0; i < roles.length; i++) {
if (roles[i].name === "moderator") {
if (roles[i].name === "moderador") {
next();
return;
}
}

res.status(403).send({ message: "Require Moderator Role!" });
res.status(403).send({ message: "Require Moderador Rol!" });
return;
}
);
Expand All @@ -95,6 +95,6 @@ const isModerator = (req, res, next) => {
const authJwt = {
verifyToken,
isAdmin,
isModerator
isModerador
};
module.exports = authJwt;
4 changes: 2 additions & 2 deletions app/middlewares/verifySignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const ROLES = db.ROLES;
const User = db.user;

checkDuplicateUsernameOrEmail = (req, res, next) => {
// Username

User.findOne({
username: req.body.username
}).exec((err, user) => {
Expand All @@ -17,7 +17,7 @@ checkDuplicateUsernameOrEmail = (req, res, next) => {
return;
}

// Email

User.findOne({
email: req.body.email
}).exec((err, user) => {
Expand Down
33 changes: 33 additions & 0 deletions final-task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## **[You're now facing the Final Task](https://www.youtube.com/watch?v=Jxk9DqdYsJ4)**



You have the freedom to use any free or open API for your project. You may use as many as you need/want.

Some suggestions are:

- [NASA API](https://api.nasa.gov/)
- [The Audio DB](https://www.theaudiodb.com/api_guide.php)
- [The cat facts](https://alexwohlbruck.github.io/cat-facts/docs/)
- [API del Servicio de Normalización de Datos Geográficos de
Argentina](https://datosgobar.github.io/georef-ar-api/)

You can browse more API's [here](https://public-apis.io/).

Keep in mind some API's will need some registration and/or are free for trial purposes only.

**The final task consists in you making three or more endpoints that must consume one external service API (like the ones listed before).**

**It is required that you pay special attention to the structure used for the endpoint.** Make sure to use:

* Routes.

* Controllers.

* Services.

* Environment variables for sensitive data (like API keys or DB access).

**In one of the three endpoints you code, it is required that you save the response to a Mongodb collection.** You can use MongoDB Atlas for easy setup, or a local instance if you want.

**It is required that the endpoints are protected with a JWT Token.** The endpoints should only allow users with the role "user" to use the endpoint.
Loading