Skip to content

Commit 42b5104

Browse files
committed
form builder adding
2 parents 366459a + 08e47d8 commit 42b5104

60 files changed

Lines changed: 97 additions & 810 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules/
2+
server/solutions/
3+
judge0/result/

a.out

-8.41 KB
Binary file not shown.

judge0/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if (cluster.isMaster) {
5353
const solutions = require('./routes/solution');
5454
app.use('/',solutions)
5555

56-
const port = process.env.PORT || 3000;
56+
const port = process.env.PORT || 3001;
5757
app.listen(port);
5858
console.log('magic is started at ' + port +'****worker :- ' +cluster.worker.id)
5959

judge0/result/Solution.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#include<bits/stdc++.h>
2-
using namespace std;
1+
var MongoClient = require('mongodb').MongoClient;
2+
var url = "mongodb://localhost:27017/";
33

4-
int main(){
5-
string sum;
6-
cin>>sum;
7-
cout<<sum<<"\n";
8-
9-
}
4+
MongoClient.connect(url, function(err, db) {
5+
if (err) throw err;
6+
var dbo = db.db("MyDb");
7+
dbo.collection("ToDos").find({}, { _id: 0 }).toArray(function(err, result) {
8+
if (err) throw err;
9+
console.log(result);
10+
db.close();
11+
});
12+
});

server/models/solution/solution.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ const mongoose = require('mongoose')
22
const SolutionJson = require('./solution.json')
33

44
const SolutionSchema = new mongoose.Schema(SolutionJson);
5-
module.exports= mongoose.model('Solution',SolutionSchema)
5+
6+
7+
SolutionSchema.statics.getObjCount =function (username,code){
8+
var Solution = this;
9+
return Solution.count({$and:[{'username':username},{'code':code}]});
10+
}
11+
12+
module.exports= mongoose.model('Solution',SolutionSchema);

server/models/solution/solution.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"id":{
33
"type":"string"
44
},
5+
"code":{
6+
"type":"string"
7+
},
58
"username":{
69
"type":"string"
710
},

server/routes/solution.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,44 @@ var upload = multer({dest:'solutions/'})
1616
var originalname = 'solution';
1717
router.post('/',upload.single(originalname),async (req,res)=>{
1818
if (req.file) {
19-
var count =await Solution.getObjcount(req.body.username,req.body.code);
19+
var count =await Solution.getObjCount(req.body.username,req.body.code)+1;
20+
console.log(count)
2021
var solution = new Solution({
2122
code:req.body.code,
2223
username:req.body.username,
2324
id:req.body.code+req.body.username+count,
2425
language:req.body.language.toLowerCase(),
2526
description:new Buffer(fs.readFileSync(req.file.path)).toString('base64'),
26-
submitted_on:new Date()
27+
submitted_on:new Date()
2728
});
2829
solution.save().then((sol) => {
2930
const agentOptions = new Object();
3031
agentOptions.keepAliveMsecs = 6000;
3132
agentOptions.maxSockets = 5;
3233
agentOptions.maxFreeSockets = 5;
3334
const httpAgent = new http.Agent(agentOptions);
34-
var opt ={uri:`http://localhost:3002/${sol.id}`,
35+
var opt ={uri:`http://localhost:3001/${sol.id}`,
3536
agent:httpAgent,
3637
json:true
3738
};
3839
rp(opt).then((body)=>{
3940
console.log(body)
4041
judge=3;
41-
res.send(body)
42+
res.json({
43+
"success":true,
44+
"msg":body
45+
})
4246
}).catch((e)=>{
4347
console.log(e);
44-
res.send(e)
48+
res.json({
49+
"success":false
50+
})
4551
})
4652
}).catch((e)=>{
4753
//console.log(e);
48-
res.send(e)
54+
res.json({
55+
"success":false
56+
})
4957
})
5058
}
5159
})

server/routes/users.js

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,97 @@ const router = express.Router();
1010

1111
router.post('/signup',(req,res)=>{
1212
const body = _.pick(req.body,['username','email_id','name','college','password','dob','gender','city','joinedOn','bio']);
13-
User.findOne({'username':body.username},function(err,user){
13+
User.findOne({'username':body.username,'email_id':body.email_id},function(err,user){
1414
if(err){
1515
res.status(404).send(err)
1616
rs}else if(user){
17-
res.status(404).send('User with Username Exists')
17+
res.status(404).json({
18+
'success':false,
19+
'msg':'User with Username Exists'
20+
})
1821
}else{
1922
var user = new User(body);
2023
user.save().then((user) => {
2124
var token = jwt.sign({ username: user.username},'secret', {
2225
expiresIn: 86400 // expires in 24 hours
2326
});
27+
<<<<<<< HEAD
2428
res.json({ success: true, message: 'Acount registered!' });
29+
=======
30+
res.status(200).json({
31+
'success':true,
32+
'msg':'Registration successful , Now you can Login',
33+
'token':token
34+
})
35+
>>>>>>> 08e47d897437c805e78a5f0730556facf6bb31a6
2536
}, (e) => {
26-
res.status(400).send(e)
37+
res.status(400).json({
38+
'success':false,
39+
'msg':e
40+
})
2741
})
2842
}
2943
})
3044

3145
});
3246

33-
router.get('/me', VerifyToken, function(req, res) {
47+
48+
49+
router.get('/profile', VerifyToken, function(req, res) {
50+
51+
User.findOne({username:req.username}, function (err, user) {
52+
if (err) return res.status(500).send(err);
53+
if (!user) return res.status(404).send("No user found.");
54+
res.status(200).json({
55+
'success':true,
56+
'msg':user
57+
});
58+
});
59+
60+
});
61+
62+
63+
router.get('/profile/me', VerifyToken, function(req, res) {
3464

3565
User.findOne({username:req.username}, function (err, user) {
3666
if (err) return res.status(500).send(err);
3767
if (!user) return res.status(404).send("No user found.");
38-
res.status(200).send(user);
68+
res.status(200).json({
69+
'success':true,
70+
'msg':user,
71+
'abd':'gdhd'
72+
});
3973
});
4074

4175
});
4276

43-
router.post('/login',(req,res)=>{
77+
router.post('/signin',(req,res)=>{
4478
const body = _.pick(req.body,['username','email_id','password']);
4579
console.log(`***${body.password} *** ${body.username}`);
4680

4781
User.findByUsername(body.username,body.password,(err,user)=>{
4882
if(err){
49-
res.status(404).send(err)
83+
res.status(404).json({
84+
'success':false,
85+
'msg':err
86+
})
5087
}else if(!user){
51-
res.status(404).send('User Not Found')
88+
res.status(404).json({
89+
'success':false,
90+
'msg':'User not found'
91+
})
5292
}else if(user){
5393
var token = jwt.sign({ username: user.username },'secret', {
5494
expiresIn: 86400 // expires in 24 hours
5595
});
56-
res.send(user)
96+
res.json({
97+
'success':true,
98+
'msg':'User with Username Exists'
99+
})
57100
}
58101
})
59102
})
60103

61104

62-
function isLoggedIn(req, res, next) {
63-
64-
if (req.isAuthenticated())
65-
return next();
66-
67-
res.redirect('/');
68-
}
69-
70-
function requiresLogin(req, res, next) {
71-
if (req.session && req.session.userId) {
72-
return next();
73-
} else {
74-
var err = new Error('You must be logged in to view this page.');
75-
err.status = 401;
76-
return next(err);
77-
}
78-
}
79-
80105

81106
module.exports = router;

server/solutions/0410cdc84c843ada8d63e52046c02158

Lines changed: 0 additions & 9 deletions
This file was deleted.

server/solutions/0538c5becfb1e500521e16e17da901bd

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)