-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.js
81 lines (68 loc) · 2.38 KB
/
register.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const register=function(app,people,messagee,reinit,bc){
app.post('/register',async(req,res,done)=>{
if(req.session.user&&req.session.user!='admin@admin.admin'){
res.redirect('/dashboard')
}
else if(req.session.user&&req.session.user=='admin@admin.admin'){
res.redirect('/admin_dashboard')
}
else{
await reinit(messagee);
let un= await req.body.username;
let em=await req.body.email;
let pass= await req.body.password;
let cpass= await req.body.confirm;
let ep=await(req.body.password==req.body.confirm)
let ps= await bc.hash(req.body.password,10);
let age=await req.body.age;
let prime=await req.body.prime;
let points=await req.body.points;
let pic=await req.body.picture;
let dt;
await people.findOne({email:em})
.then((data)=>{dt=data})
.catch(()=>{console.log("error while finding one")})
if(em=="admin@admin.admin"){
messagee.msg=await "Wrong Email Format";
messagee.pw=await pass;
messagee.cpw=await cpass;
messagee.em=await em;
messagee.un=await un;
await res.redirect('/register');
done(null);
}
else if(dt){
messagee.msg=await"Email Already Used \n If its yours Proceed to Login Page ";
messagee.pw=await pass;
messagee.cpw=await cpass;
messagee.em=await em;
messagee.un=await un;
await res.redirect('/register');
done(null);
}
else if(!ep){
messagee.msg=await "Passwords dont match";
await res.redirect('/register');done(null);
}
else if(pass.length<6){
messagee.msg=await "Password minimum length is 6 characters";
await res.redirect('/register');done(null);
}
else if(age<18||age>200){
messagee.msg=await "Invalid age (At least 18) ";
await res.redirect('/register');done(null);
}
else{
let usere=await new people({username:un,email:em,password:ps,age:parseInt(age),status:0})
let message=""
// console.log(usere)
await usere.save()
.then((d)=>{console.log("user saved");message="Your account is registered successfully"})
.catch((e)=>{console.log(e);message="An Error Has Occured"})
messagee.msg=message
await res.render('login.ejs',{message:messagee});
done(null);}
}
})
};
module.exports={register}