Skip to content

Commit

Permalink
Merge branch 'Main' of https://github.com/aksharma27/farmup into Main
Browse files Browse the repository at this point in the history
  • Loading branch information
Apple authored and Apple committed Jan 13, 2023
2 parents 5643fbf + 47e5e98 commit 3db3c6e
Show file tree
Hide file tree
Showing 11 changed files with 1,463 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The motto of this web app is to bring growth in agricultural field

### Team Members
- [Abhishek Kumar Sharma](https://www.github.com/aksharma27)(Back-end, Front-end, Database).
- [Akash Parida](https://wwww.github.com/Akash-akp) (Front-end).
- [Akash Parida](https://github.com/Akash-akp) (Front-end).
- Shubhankar Patel(Front-end, UI/UX).
- Devdutt Mohapatra(Project Maintainer).

Expand Down
31 changes: 27 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
var passport = require("passport"),
LocalStrategy = require("passport-local"),
passportLocalMongoose = require("passport-local-mongoose");

dotenv.config({path: "./config.env"});
const PORT = process.env.PORT || 3000;
const DB = process.env.DB;
// const DB = process.env.DB;
const dbconn = require("./config/db");
// const passport = require("passport");




// dbconn();
dbconn();
const app = express();

//passports

//middlewares
app.use(express.json());
app.use(cors());
// app.use(express.urlencoded("extended: true"));
app.set('view engine', 'ejs');
app.use(express.static("public"));


app.get('/api/test', (req, res)=> {
app.get('/home', (req, res)=> {
res.render('index')
});


app.get('/signup-farmer', (req, res)=> {
res.render("signup-admin");
});
app.get('/login-farmer', (req, res)=>{
res.render('');
});

app.get('/api/home', (req, res)=> {
res.render("index");
});
Expand All @@ -38,10 +56,15 @@ app.get('/signup-admin', (req, res)=>{
res.render('signupadmin');
});

app.get('/signup-user', (req, res) => {
res.rednder("signup-buyer");
});

app.post




app.listen(3000 , ()=> {
app.listen(PORT , ()=> {
console.log(`listening on ${PORT}`);
});
Empty file added controllers/admin-signup.js
Empty file.
1 change: 1 addition & 0 deletions controllers/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const AdminModel = require("../models/admin-model");
85 changes: 85 additions & 0 deletions controllers/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const User = require('../models/User');
const jwt = require('jsonwebtoken');
const bcrypt = require('bcrypt');
const {
createJWT,
} = require('../utils/auth');
const { use } = require('passport');

exports.signup = (req, res, next) => {
let {name, email, password_confirmation} = req.body;
User.findOne({email: email})
.then(user => {
if(user){
return res.status(422).json({errors: [{user: "email already exists"}]});
}
else{
const user = new User({
name: name,
email: email,
password: password,
});

bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(password, salt, (err, hash)=> {
if(err) throw err;
user.password = hash;
user.save().then(response => {
res.status(200).json({
success: true,
result: response
})
}).catch(err => {
res.status(500).json({
errors: [{error: err}]
});
});
});
});
}
}).catch(err => {
res.status(500).json({
errors: [{error: 'Something went wrong'}]
})
})
}

exports.signin = (req, res) => {
let {email, password} = req.body;

User.findOne({email: email}).then(user=> {
if(!user){
return res.status(404).json({
errors: [{user: "not found"}],
});
} else{
bcrypt.compare(password, user.password).then(isMatch => {
if(!isMatch){
return res.status(400).json({errors: [{password: "incorrect"}]});
}

let access_token = createJWT(
user.email,
user._id,
3600
);
jwt.verify(access_token, process.env.TOKEN_SECRET, (err, decoded) => {
if(err) {
res.status(500).json({errors: err});
}
if(decoded){
return res.status(200).json({
success: true,
token: access_token,
message: user
});
}
});
}).catch(err => {
res.status(500).json({errors: err});
});
}
}).catch(err => {
res.status(500).json({errors: err});
});
}
3 changes: 1 addition & 2 deletions models/admin-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ const adminSchema = new mongoose.Schema({

const Admin = new mongoose.Model("Admin", adminSchema);

module.exports = Admin;

module.exports = Admin;
7 changes: 2 additions & 5 deletions models/user-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ const userSchema = new mongoose.Schema({
password: {
type: String,
required: true,
},
bid_price: {
type: Number,
},
});
}
}, {timestamps: 'createdAt', updatedAt: 'updatedAt', collection: 'users'});

const User = new mongoose.model("User", userSchema);

Expand Down
Loading

0 comments on commit 3db3c6e

Please sign in to comment.