Skip to content

Commit c5068a4

Browse files
committed
Changed bcrypt callback to promise
1 parent d6eae41 commit c5068a4

12 files changed

Lines changed: 41 additions & 84 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
server/solutions/
33
judge/result/
4-
solutions/
4+
solutions/
5+
codecamp-front/node_modules/

judge/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (cluster.isMaster) {
3232
const mongoose = require('mongoose')
3333

3434
mongoose.Promise = global.Promise
35-
mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/OnlineJudge')
35+
mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27018/OnlineJudge')
3636

3737
const bodyParser = require('body-parser');
3838
app.use( bodyParser.json() );

judge/result/binary/Solution.out

-176 Bytes
Binary file not shown.

judge/result/source/Solution.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include<stdio.h>
22
int main()
33
{
4-
printf("Welcome To CodeCamp");
4+
int n;
5+
scanf("%d",&n);
6+
while(n--)
7+
printf("Hello World\n");
58
}
6-
9+

judge/result/source/Solution.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
#include<bits/stdc++.h>
2-
using namespace std;
3-
int main()
4-
{
5-
//int arr[123456781];
6-
//cout << arr[12];
7-
while(1);
8-
}
1+
print("Welcome To CodeCamp")

judge/result/source/Solution.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import java.util.*;
2-
3-
public class Solution {
4-
5-
public static void main(String[] args) {
6-
7-
System.out.print("Welcome To CodeCamp");
8-
for(int i=0;i<1000000000;i++);
9-
}
10-
11-
}
12-
1+
#include<stdio.h>
2+
int main()
3+
{
4+
printf("Welcome To CodeCamp");
5+
}
6+
Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
import math
2-
t=int(input())
3-
def fun(a,b,y):
4-
x=ord(a[-1])-ord('0')
5-
res=x**y
6-
print(res%10)
7-
'''m=math.ceil(math.log10(res))
8-
print(m)
9-
res=res%(10**m)
10-
print(res)'''
11-
12-
for _ in range(t):
13-
a,b=map(str,input().split())
14-
if len(b)==1 and int(b)==0:
15-
print(1)
16-
continue
17-
if len(b)<=1:
18-
x=int(b)
19-
else:
20-
l=len(b)
21-
x=(ord(b[-1])-ord('0'))+10*(ord(b[-2])-ord('0'))
22-
23-
if x%4==0:
24-
fun(a,x,4)
25-
else:
26-
fun(a,x,x%4)
27-
28-
1+
import java.util.*;
2+
public class Solution {
3+
public static void main(String[] args) {
4+
System.out.print("Welcome To CodeCamp");
5+
}
6+
}
7+

judge/routes/solution.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ router.get('/:id',(req,res)=>{
3131
maxBuffer:pro.sourcelimit,
3232
encoding:'utf8'
3333
}
34-
judge.compileAndRunProblem(contest,problem,id,language ,description,option).then((result)=>{
35-
console.log(result)
34+
judge.compileAndRunProblem(contest,problem,id,language ,description,option).then((result)=>{
3635
res.send(result);
3736
}).catch((e)=>{
38-
console.log(e)
3937
var compileError = /(g[/++/]|gcc|javac)/;
4038
if(e.toString().match(compileError)){
4139
res.status(200).send('CE');

server/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const app = express();
1010
const mongoose = require('mongoose')
1111

1212
mongoose.Promise = global.Promise
13-
mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/OnlineJudge')
13+
mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27018/OnlineJudge')
1414

1515
const bodyParser = require('body-parser');
1616
app.use(cors())
@@ -55,7 +55,7 @@ app.get('/',(req,res)=>{
5555
})
5656

5757
const port = process.env.PORT || 80;
58-
app.listen(port,'192.168.0.11');
58+
app.listen(port,'0.0.0.0');
5959
console.log('magic is started at ' + port)
6060

6161
module.exports={app}

server/models/user/user.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ var UserSchema = new mongoose.Schema({
108108

109109
UserSchema.pre('save',function(next) {
110110
var user =this;
111-
bcrypt.genSalt(10, function(err, salt) {
112-
bcrypt.hash(user.password, salt, function(err, hash) {
113-
user.password=hash
114-
next();
115-
});
111+
bcrypt.hash(user.password, 10).then(function(hash) {
112+
user.password=hash;
113+
next();
114+
}).catch((e)=>{
115+
next(err);
116116
});
117-
})
117+
});
118+
118119

119120
UserSchema.methods.toJSON = function() {
120121
var user = this ;
@@ -130,20 +131,14 @@ UserSchema.statics.findByUsername=function(username,password,done){
130131
}else if(!user){
131132
return done(null,null);
132133
}else{
133-
bcrypt.compare(password, user.password, function(err , res){
134-
if(err){
135-
return done(err);
136-
}else if(!res){
137-
<<<<<<< HEAD
138-
return done(err);
134+
bcrypt.compare(password, user.password).then((res)=>{
135+
if(!res){
136+
return done('WP',user);
139137
}else if(res){
140138
return done(null,user);
141-
=======
142-
return done(err)
143-
} else if(res){
144-
return done(null,user)
145-
>>>>>>> 2cc704141c7f90f47465c9318ad6508d35a021e3
146139
}
140+
}).catch((err)=>{
141+
return done(err);
147142
})
148143
}
149144
})

0 commit comments

Comments
 (0)