fix #17 fix #36 remove notification, rss fix&more

This commit is contained in:
lesion
2019-03-21 22:20:30 +01:00
parent ba0004a89f
commit 58f0d8c9fe
30 changed files with 302 additions and 123 deletions

View File

@@ -111,9 +111,12 @@ const eventController = {
async addNotification (req, res) {
try {
const notification = req.body
notification.remove_code = crypto.randomBytes(16).toString('hex')
await Notification.create(req.body)
const notification = {
email: req.body.email,
type: 'mail',
remove_code: crypto.randomBytes(16).toString('hex')
}
await Notification.create(notification)
res.sendStatus(200)
} catch (e) {
res.sendStatus(404)
@@ -126,7 +129,7 @@ const eventController = {
const notification = await Notification.findOne({ where: { remove_code: { [Op.eq]: remove_code } } })
await notification.destroy()
} catch (e) {
return res.send('Error')
return res.status(404).send('Error')
}
res.send('Ok, notification removed')
},

View File

@@ -21,8 +21,7 @@ const exportController = {
wherePlace.name = places.split(',')
}
const events = await Event.findAll({
// order: [['start_datetime', 'ASC']],
where: { start_datetime: { [Op.gte]: yesterday } },
where: { is_visible: true, start_datetime: { [Op.gte]: yesterday } },
include: [Comment, {
model: Tag,
where: whereTag

View File

@@ -10,6 +10,7 @@ const mail = require('../mail')
const { Op } = require('sequelize')
const fs = require('fs')
const path = require('path')
const crypto = require('crypto')
const userController = {
async login (req, res) {
@@ -201,6 +202,36 @@ const userController = {
}
},
async forgotPassword (req, res) {
const email = req.body.email
const user = await User.findOne({ where: { email: { [Op.eq]: email } } })
if (!user) return res.sendStatus(200)
user.recover_code = crypto.randomBytes(16).toString('hex')
mail.send(user.email, 'recover', { user, config })
await user.save()
res.sendStatus(200)
},
async checkRecoverCode (req, res) {
const recover_code = req.body.recover_code
if (!recover_code) return res.sendStatus(400)
const user = await User.findOne({ where: { recover_code: { [Op.eq]: recover_code } } })
if (!user) return res.sendStatus(400)
res.json(user)
},
async updatePasswordWithRecoverCode (req, res) {
const recover_code = req.body.recover_code
if (!recover_code) return res.sendStatus(400)
const password = req.body.password
const user = await User.findOne({ where: { recover_code: { [Op.eq]: recover_code } } })
if (!user) return res.sendStatus(400)
user.password = password
await user.save()
res.sendStatus(200)
},
async current (req, res) {
res.json(req.user)
},
@@ -236,7 +267,7 @@ const userController = {
}
const user = await User.create(req.body)
try {
mail.send(user.email, 'register', { user })
mail.send([user.email, config.admin], 'register', { user, config })
} catch (e) {
return res.status(400).json(e)
}