-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/samdsk/lab-pwm
- Loading branch information
Showing
141 changed files
with
5,819 additions
and
34,538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: '' | ||
assignees: '' | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior: | ||
1. Go to '...' | ||
2. Click on '....' | ||
3. Scroll down to '....' | ||
4. See error | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Desktop (please complete the following information):** | ||
- OS: [e.g. iOS] | ||
- Browser [e.g. chrome, safari] | ||
- Version [e.g. 22] | ||
|
||
**Smartphone (please complete the following information):** | ||
- Device: [e.g. iPhone6] | ||
- OS: [e.g. iOS8.1] | ||
- Browser [e.g. stock browser, safari] | ||
- Version [e.g. 22] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const recaptcha = require('../utils/recaptcha') | ||
const sendEmail = require('../utils/sendEmail') | ||
|
||
const getContact = async (req,res,next) =>{ | ||
if(!req.session.username || !req.session.email) | ||
res.render('pages/contact',{contact:true}) | ||
else | ||
res.render('pages/contact',{contact:true,logout:true}) | ||
|
||
} | ||
|
||
const postContact = async (req,res,next) =>{ | ||
const {name,email,subject,message} = req.body | ||
let catpcha = await recaptcha(req.body['g-recaptcha-response']) | ||
if(!catpcha) return res.json(JSON.stringify({error:"Invalid captcha!"})) | ||
|
||
const mail_opt = { | ||
from:name+" : "+email, | ||
to:process.env.EMAIL, | ||
subject:name+" "+subject, | ||
text:`message from ${name} | ||
email: ${email} | ||
subject:${subject}: | ||
message:${message}`, | ||
html:` | ||
<h4 class="h4">Contact form</h4> | ||
<h5 class="h5">Name: ${name} Email: ${email}</h5> | ||
<h5 class="h5">Subject: ${subject}</h5> | ||
<p>Message: ${message}</p> | ||
` | ||
} | ||
|
||
await sendEmail(mail_opt).then(()=>{ | ||
return res.json(JSON.stringify({success:"Your message has been sent!"})) | ||
}).catch((err)=>{ | ||
return res.json(JSON.stringify({error:"Failed to send message!"})) | ||
}) | ||
} | ||
|
||
|
||
module.exports = {getContact,postContact} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const getDashboard = async (req,res,next) =>{ | ||
res.redirect('/dashboard/profile') | ||
res.redirect('/dashboard/history') | ||
} | ||
|
||
module.exports = getDashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const Auth = require('../models/Auth') | ||
const jwt = require('jsonwebtoken') | ||
const sendEmail = require('../utils/sendEmail') | ||
const User = require('../models/User') | ||
|
||
const JWT_EXP = '30m' | ||
|
||
// FIXME change the email address | ||
|
||
const postEmail = async (req,res,next) => { | ||
if(req.body.email){ | ||
Auth.findOne({email:req.body.email},async (err,auth)=>{ | ||
|
||
if(err) return res.sendStatus(500) | ||
if(!auth) return res.json(JSON.stringify({error:"Invalid email"})) | ||
|
||
const name = await User.findById(auth._id) | ||
|
||
const secret = process.env.Server_Secret + auth.password | ||
const token = jwt.sign({ | ||
email:auth.email | ||
},secret,{expiresIn:JWT_EXP}) | ||
|
||
const link = `http://${process.env.HOSTNAME}/reset-password/${auth.email}/${token}` | ||
|
||
const mail_opt = { | ||
from:'Twitter Analytics App', | ||
to:sendTo, | ||
subject:'Twitter Analytics App Password Recovery', | ||
text:'You have requested for a password reset. Follow this link: ' + link, | ||
html:` | ||
<h4 class="h4">Hi ${name}!</h4> | ||
<p>You have requested for a password reset, follow the following link</p> | ||
<a href="${link}">${link}</a> | ||
` | ||
} | ||
|
||
await sendEmail(mail_opt).then(()=>{ | ||
return res.json(JSON.stringify({success:"Email sent to "+req.body.email})) | ||
}).catch((err)=>{ | ||
return res.json(JSON.stringify({error:"Failed to send message!"})) | ||
}) | ||
}) | ||
|
||
}else{ | ||
return res.sendStatus(500) | ||
} | ||
|
||
} | ||
|
||
module.exports = {postEmail} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
const getHistory = async (req,res,next) => { | ||
res.render('pages/history',{logout:true,username:req.session.username}) | ||
const Auth = require('../models/Auth') | ||
const User = require('../models/User') | ||
const SearchResults = require('../models/SearchResults') | ||
|
||
const getSearchedResults = async (email) => { | ||
let user = await Auth.findOne({email:email}) | ||
let searched = await User.findOne({_id:user._id},'searched') | ||
searched = searched.searched | ||
const search_ids = [] | ||
const projections = `_id date name user_img username | ||
start_date end_date followings followers total_tweets total.count`; | ||
|
||
await Promise.all( | ||
searched.map( async (id) => { | ||
let temp = await SearchResults.findById(id,projections) | ||
search_ids.push(temp) | ||
}) | ||
) | ||
|
||
return search_ids | ||
} | ||
|
||
const getHistory = async (req,res,next) => { | ||
|
||
let results = await getSearchedResults(req.session.email) | ||
|
||
results = results.sort( (a,b)=>{ | ||
return new Date(a.date) < new Date(b.date) ? 1 : -1 | ||
}) | ||
|
||
res.render('pages/history',{ | ||
logout:true, | ||
username:req.session.username, | ||
email_hash:req.session.gravatar, | ||
results:results, | ||
history:true, | ||
dashboard:true, | ||
}) | ||
} | ||
|
||
module.exports = getHistory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,96 @@ | ||
const bcrypt = require('bcrypt') | ||
const Auth = require("../models/Auth") | ||
const User = require("../models/User") | ||
const SearchResults = require('../models/SearchResults') | ||
const recaptcha = require('../utils/recaptcha') | ||
|
||
const getProfile = async (req,res,next) => { | ||
req.session.email | ||
res.render('pages/profile', | ||
{ | ||
logout:true, | ||
username:req.session.username, | ||
email: req.session.email | ||
|
||
res.render('pages/profile',{ | ||
logout:true, | ||
username:req.session.username, | ||
email: req.session.email, | ||
email_hash:req.session.gravatar, | ||
profile:true, | ||
dashboard:true, | ||
}) | ||
} | ||
|
||
const postProfile = async (req,res,next) => { | ||
if(req.session.email){ | ||
|
||
let catpcha = await recaptcha(req.body['g-recaptcha-response']) | ||
if(!catpcha) return res.json(JSON.stringify({error:"Invalid captcha!"})) | ||
|
||
const {password,new_password,new_password_confirm} = req.body | ||
if(new_password !== new_password_confirm) | ||
return res.json(JSON.stringify({error:"Passwords don't match"})) | ||
|
||
Auth.findOne({email:req.session.email},async function(err,auth){ | ||
bcrypt.compare(password,auth.password).then(async (check)=>{ | ||
|
||
if(!check) return res.json(JSON.stringify({error:"Credentials are not valid"})) | ||
const password = await bcrypt.hash(new_password,10) | ||
await Auth.findByIdAndUpdate(auth._id,{password:password}) | ||
|
||
return res.json(JSON.stringify({success:"Password updated"})) | ||
}) | ||
|
||
}) | ||
}else{ | ||
return res.sendStatus(500) | ||
} | ||
|
||
|
||
} | ||
|
||
const deleteProfile = async (req,res,next) => { | ||
if(req.session.email){ | ||
Auth.findOne({email:req.session.email},async function(err,auth){ | ||
console.log(req.body.password); | ||
await bcrypt.compare(req.body.password,auth.password).then(async (check)=>{ | ||
|
||
if(!check) return res.json(JSON.stringify({error:"Credentials are not valid"})) | ||
console.log("pass: psw"); | ||
|
||
let searched = await User.findById(auth._id,'searched') | ||
|
||
await Promise.all( | ||
searched.searched.map(async(x)=>{ | ||
SearchResults.findByIdAndRemove(x).exec((err,data)=>{ | ||
if(err) { | ||
return res.json(JSON.stringify({error:"Profile delete: SearchResults error"})) | ||
} | ||
console.log("pass: search",x); | ||
}) | ||
}) | ||
) | ||
|
||
Auth.findByIdAndRemove(auth._id).exec((err,data)=>{ | ||
if(err) { | ||
return res.json(JSON.stringify({error:"Profile delete: Auth error"})) | ||
} | ||
console.log("pass: delete auth"); | ||
}) | ||
|
||
User.findByIdAndRemove(auth._id).exec((err,data)=>{ | ||
if(err) { | ||
return res.json(JSON.stringify({error:"Profile delete: User error"})) | ||
|
||
} | ||
console.log("pass: delete user"); | ||
}) | ||
|
||
req.session.destroy() | ||
return res.json(JSON.stringify({success:"Profile has been delete successfully"})) | ||
}) | ||
|
||
}) | ||
}else{ | ||
return res.sendStatus(500) | ||
} | ||
} | ||
|
||
|
||
|
||
module.exports = getProfile | ||
module.exports = {getProfile,postProfile,deleteProfile} |
Oops, something went wrong.