Giter Club home page Giter Club logo

cars360's Introduction

Car360 is a platform that helps users to rent cars online. Write an endpoint that has the features listed below. Authentication and authorization should be handled with Oauth2 using Authorization code grant types, MongodB to store users' data and PostgreSQL to store other data.

Host your Postgres database on Heroku.

Features to build:

1.Authenticate users with Oauth2 and social login (Facebook) 2.Create an endpoint to upload new available cars for anyone with “ROLE_ADMIN” 3.Create an endpoint to fetch available cars from the database only 5 per time (Add 20 dummy data to test) 4. Create an endpoint to make payment for the car bookings and pay using Paystack.

On successful payment, generate your own personal receipt and put all details (Should be pdf). Calculate total price using number of days and amount

Data to take for cars are name, year, manufacturer, 4 images (nothing less), number of days and amount to rent it out for per day

So we are going to start with baby steps:

i. Setting up Node.js

ii. Installing the needed Node.js packages for the project

iii. Setting up the MongoDB database model using mongoose

iv. Building our own paystack payment module

v. Setting up express server: app.js

a. Views using pug template engine
b. Creating endpoints for payment and confirmation
c. Testing Rents

Stacks: express, sequelize, request, body-parser, ejs, mongoose, pg

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

exports.loginAuth = (req, res) => { res.send(<html> <body> <a href="https://www.facebook.com/v6.0/dialog/oauth?client_id=${process.env.FACEBOOK_APP_ID}&r edirect_uri=${encodeURIComponent('http://localhost:3479/index')}"> Log In With Facebook </a> </body> </html>); };

// Route 2: Exchange auth code for access token exports.loginVerify= async (req, res) => { try { const authCode = req.query.code;

const accessTokenUrl = 'https://graph.facebook.com/v6.0/oauth/access_token?' +
  `client_id=${process.env.FACEBOOK_APP_ID}&` +
  `client_secret=${process.env.FACEBOOK_SECRET_KEY}&` +
  `redirect_uri=${encodeURIComponent('http://localhost:3479/oauth-redirect')}&` +
  `code=${encodeURIComponent(authCode)}`;

const accessToken = await axios.get(accessTokenUrl).then(res => res.data['access_token']);

// Store the access token in MongoDB, skip the userId for now
await User.create({ _id: accessToken });

res.cookie('accessToken', accessToken, { maxAge: 900000, httpOnly: true });
res.redirect(`/me?accessToken=${encodeURIComponent(accessToken)}`);

} catch (err) { console.log(err); return res.status(500).json({ message: err.response.data || err.message }); } };

// Route 3: Make requests to FB on behalf of the user exports.userRequest = async (req, res) => { try { const accessToken = String(req.cookies.accessToken); // Make sure the token is in the database const tokenFromDb = await User.findOne({ _id: accessToken }); if (tokenFromDb == null) { throw new Error(Invalid access token "${accessToken}"); }

const data = await axios.get(`https://graph.facebook.com/me?access_token=${encodeURIComponent(accessToken)}`).
  then(res => res.data);

return res.send(`
  <html>
    <body>Your name is ${data.name}</body>
  </html>
`);

} catch (err) { console.log(err); return res.status(500).json({ message: err.response.data || err.message }); } };

///////////////////////////////////////////////////////// How to generate code ////////////////////////////////////////////////////////// let codeGenerate = Math.random().toString(36).substring(2,7);

cars360's People

Contributors

arosebine avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.