Skip to content

Commit 4c29c6e

Browse files
Merge pull request #173 from lakshyabatman/development
The backend Logic for profile picture is added
2 parents bb3f444 + 3ca2f26 commit 4c29c6e

File tree

10 files changed

+192
-29
lines changed

10 files changed

+192
-29
lines changed

config/local.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const passport = require('passport');
22
const LocalStrategy = require('passport-local');
33
const User = require('../schema/user');
4+
const path=require('path')
45

56
passport.serializeUser(function(user, done) {
67
done(null, user.id);
@@ -28,7 +29,14 @@ passport.use(
2829
if (user) {
2930
return done(null, false);
3031
}
31-
32+
33+
upload(req,res,(err)=>{
34+
if(err){
35+
let img="oldMan.jpeg"
36+
}else{
37+
let img=req.file.filename
38+
}
39+
})
3240
let newUser = new User();
3341
newUser.fname = req.body.fname;
3442
newUser.lname = req.body.lname;
@@ -41,6 +49,7 @@ passport.use(
4149
newUser.following = 0;
4250
newUser.status = 'idle';
4351
newUser.Eid = newUser.id;
52+
newUser.profilePicture=img;
4453

4554
newUser.save(err => {
4655
if (err) {

package-lock.json

Lines changed: 121 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"mongo": "^0.1.0",
2323
"mongodb": "^3.1.0",
2424
"mongoose": "^5.1.7",
25+
"multer": "^1.4.1",
2526
"node": "^10.5.0",
2627
"node-memwatch": "^1.0.1",
2728
"nodemon": "^1.18.8",

routes/login.routes.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ const url = bodyparser.urlencoded({ extended: false });
44
const passport = require('passport');
55
const user = require('../schema/user.js');
66
const route = express.Router();
7+
const multer=require('multer')
8+
const path=require('path')
9+
//MULTER
10+
const storage=multer.diskStorage({
11+
destination: (req, file, cb) => {
12+
cb(null, './views/uploads/profilePics')
13+
},
14+
filename:function(req,file,cb){
15+
cb(null,file.fieldname+"-"+Date.now()+path.extname(file.originalname))
16+
}
17+
})
18+
const upload=multer({
19+
storage:storage
20+
});
21+
722

823
//get request
924

@@ -33,10 +48,19 @@ route.get(
3348
res.redirect('/profile/profile/:id');
3449
}
3550
);
51+
route.get('/signup',url,function(req,res){
52+
res.render('user.ejs')
53+
})
3654

3755
//post request
38-
39-
route.post('/userlogin', url, function(req, res) {
56+
//SIGNUP ROUTE
57+
route.post('/userlogin',upload.single('profilepic'), function(req, res) {
58+
let img=""
59+
if(req.file){
60+
img=req.file.filename
61+
}else{
62+
img="oldMan.jpeg"
63+
}
4064
new user({
4165
fname: req.body.fname,
4266
lname: req.body.lname,
@@ -48,14 +72,21 @@ route.post('/userlogin', url, function(req, res) {
4872
follower: 0,
4973
following: 0,
5074
status: 'idle',
51-
Eid: Math.floor(Math.random() * 1000000)
75+
Eid: Math.floor(Math.random() * 1000000),
76+
profilePicture:img,
77+
5278
})
5379
.save()
80+
.catch((err)=>{
81+
res.send("ERROR")
82+
})
5483
.then(function(use) {
55-
res.render('user', { user: use });
84+
//Right now it render index page because no login page is created yet so
85+
res.send(use)
86+
//res.send("WELCOME TO CODEUINO, you can now login")
5687
});
5788
});
58-
89+
//LOGIN ROUTE
5990
route.post('/login', url, function(req, res) {
6091
user
6192
.findOne({ email: req.body.email })
@@ -68,6 +99,7 @@ route.post('/login', url, function(req, res) {
6899
}
69100
});
70101
});
102+
71103
route.get('/logout', function(req, res) {
72104
req.logout();
73105
res.redirect('/');

schema/user.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ const user = new Schema({
8888
},
8989
blockedUser : {
9090
type : [Number]
91+
},
92+
profilePicture:{
93+
type: String
9194
}
9295
});
9396

server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const loged = [];
2828

2929
app.set('view engine', 'ejs');
3030
app.use(express.static(path.join(__dirname, 'views')));
31+
app.set('views',path.join(__dirname+"/views"));
3132
app.use(methodOverride('_method'));
3233

3334
app.use(

views/all.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<div class="container d-flex flex-column justify-content-center w-75">
8989
<a href="/auth/github" class="btn btn-dark js-scroll-trigger mb-2">Sign Up Using <i class="fab fa-github" style="font-size: 24px;"></i></a>
9090
<a href="/auth/google" class="btn btn-danger js-scroll-trigger mb-2">Sign Up Using <i class="fab fa-google" style="font-size: 24px;"></i></a>
91-
<a href="#" class="btn btn-primary js-scroll-trigger">Sign Up Using <i class="fas fa-envelope" style="font-size: 24px;"></i></a>
91+
<a href="/auth/signup" class="btn btn-primary js-scroll-trigger">Sign Up Using <i class="fas fa-envelope" style="font-size: 24px;"></i></a>
9292
</div>
9393
</div>
9494
<div class="modal-footer">

views/index.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<div class="container d-flex flex-column justify-content-center w-75">
8282
<a href="/auth/github" class="btn btn-dark js-scroll-trigger mb-2">Sign Up Using <i class="fab fa-github" style="font-size: 24px;"></i></a>
8383
<a href="/auth/google" class="btn btn-danger js-scroll-trigger mb-2">Sign Up Using <i class="fab fa-google" style="font-size: 24px;"></i></a>
84-
<a href="#" class="btn btn-primary js-scroll-trigger">Sign Up Using <i class="fas fa-envelope" style="font-size: 24px;"></i></a>
84+
<a href="/auth/signup" class="btn btn-primary js-scroll-trigger">Sign Up Using <i class="fas fa-envelope" style="font-size: 24px;"></i></a>
8585
</div>
8686
</div>
8787
<div class="modal-footer">
3.68 KB
Loading

0 commit comments

Comments
 (0)