asdasdawdq
This commit is contained in:
parent
b3c3d06517
commit
6ec47ddbf7
81
routes/debug.js
Normal file
81
routes/debug.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const User = require("../models/user.js")
|
||||
|
||||
//login handle
|
||||
router.get('/login',(req,res)=>{
|
||||
res.render('login');
|
||||
})
|
||||
|
||||
router.get('/register',(req,res)=>{
|
||||
res.render('register')
|
||||
})
|
||||
//Register handle
|
||||
router.post('/register',(req,res)=>{
|
||||
const {name,email, password, password2} = req.body;
|
||||
let errors = [];
|
||||
console.log(' Name ' + name+ ' email :' + email+ ' pass:' + password);
|
||||
if(!name || !email || !password || !password2) {
|
||||
errors.push({msg : "Please fill in all fields"})
|
||||
}
|
||||
//check if match
|
||||
if(password !== password2) {
|
||||
errors.push({msg : "passwords dont match"});
|
||||
}
|
||||
|
||||
//check if password is more than 6 characters
|
||||
if(password.length < 6 ) {
|
||||
errors.push({msg : 'password atleast 6 characters'})
|
||||
}
|
||||
if(errors.length > 0 ) {
|
||||
res.render('register', {
|
||||
errors : errors,
|
||||
name : name,
|
||||
email : email,
|
||||
password : password,
|
||||
password2 : password2})
|
||||
} else {
|
||||
//validation passed
|
||||
User.findOne({email: email}).exec((err, user) => {
|
||||
console.log(user);
|
||||
if (user) {
|
||||
errors.push({msg: 'email already registered'});
|
||||
render(res, errors, name, email, password, password2);
|
||||
|
||||
} else {
|
||||
const newUser = new User({
|
||||
name: name,
|
||||
email: email,
|
||||
password: password
|
||||
});
|
||||
//hash password
|
||||
bcrypt.genSalt(10, (err, salt) =>
|
||||
bcrypt.hash(newUser.password, salt,
|
||||
(err, hash) => {
|
||||
if (err) throw err;
|
||||
//save pass to hash
|
||||
newUser.password = hash;
|
||||
//save user
|
||||
newUser.save()
|
||||
.then((value) => {
|
||||
console.log(value)
|
||||
res.redirect('/users/login');
|
||||
})
|
||||
.catch(value => console.log(value));
|
||||
|
||||
}));
|
||||
} //ELSE statement ends here
|
||||
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/login',(req,res,next)=>{
|
||||
|
||||
})
|
||||
|
||||
//logout
|
||||
router.get('/logout',(req,res)=>{
|
||||
})
|
||||
module.exports = router;
|
|
@ -200,6 +200,30 @@ router.get('/getAll', auth, async(req, res, next) => {
|
|||
|
||||
} catch (err) { next(err) }
|
||||
})
|
||||
router.get('/getAll/:type', auth, async(req, res, next) => {
|
||||
try {
|
||||
let queryObj = {
|
||||
where: {username: req.userData.username}
|
||||
}
|
||||
let user = await User.findOne(queryObj)
|
||||
if (!user) {
|
||||
res.status(200)
|
||||
res.json({success: false})
|
||||
}
|
||||
let checkIfSent = await Relationship.findAndCountAll({
|
||||
where: {friend1Id: user.id, type: req.params.type},
|
||||
include: [{ model: User, as: 'friend1', attributes: ['username', 'createdAt', 'id', 'color', 'picture', 'locked', 'admin', 'booster', 'executive', 'bot'] }, { model: User, as: 'friend2', attributes: ['username', 'createdAt', 'id', 'color', 'picture', 'locked', 'admin', 'booster', 'executive', 'bot'] } ]
|
||||
})
|
||||
if (checkIfSent) {
|
||||
res.status(200)
|
||||
res.json(checkIfSent)
|
||||
} else {
|
||||
res.status(200)
|
||||
res.json({})
|
||||
}
|
||||
|
||||
} catch (err) { next(err) }
|
||||
})
|
||||
router.get('/getAllPendingCanAccept', auth, async(req, res, next) => {
|
||||
try {
|
||||
let queryObj = {
|
||||
|
|
Loading…
Reference in a new issue