mirror of
https://github.com/UniversityOfHelsinkiCS/ohtuilmo.git
synced 2026-10-12 19:03:41 +03:00
@@ -1,6 +1,7 @@
|
||||
const topicsRouter = require('express').Router()
|
||||
const db = require('../models/index')
|
||||
const checkAdmin = require('../utils/middleware/checkAdmin').checkAdmin
|
||||
const email = require('../utils/email')
|
||||
const getRandomId = require('../utils/idGeneration').getRandomId
|
||||
|
||||
topicsRouter.post('/', (req, res) => {
|
||||
@@ -12,6 +13,7 @@ topicsRouter.post('/', (req, res) => {
|
||||
secret_id
|
||||
})
|
||||
.then(topic => {
|
||||
email.sendSecretLink(topic.secret_id, topic.email)
|
||||
res.status(200).json({ topic })
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
+10
-1
@@ -14,9 +14,18 @@ let login = 'http://opetushallinto.cs.helsinki.fi/login'
|
||||
|
||||
let secret = 'secret'
|
||||
|
||||
//email config
|
||||
let email = {
|
||||
sender: 'Ohtuilmo Robot <noreply@helsinki.fi>',
|
||||
host: 'smtp.helsinki.fi',
|
||||
port: 587,
|
||||
secure: false
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
dbUrl,
|
||||
port,
|
||||
login,
|
||||
secret
|
||||
secret,
|
||||
email
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
const config = require('./config')
|
||||
const nodemailer = require('nodemailer')
|
||||
|
||||
function sendSecretLink(secretId, address) {
|
||||
const options = {
|
||||
to: address,
|
||||
subject: 'Link to your Software Engineering Project topic submission',
|
||||
html: '<a href="http://svm-45.cs.helsinki.fi:7000/topics/'+secretId+'">Click this link to view or edit your submission</a>'
|
||||
}
|
||||
send(options)
|
||||
}
|
||||
|
||||
function send(options) {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: config.email.host,
|
||||
port: config.email.port,
|
||||
secure: config.email.secure
|
||||
})
|
||||
|
||||
const mailOptions = {
|
||||
from: config.email.sender,
|
||||
to: options.to,
|
||||
subject: options.subject,
|
||||
text: options.text,
|
||||
html: options.html
|
||||
}
|
||||
|
||||
transporter.sendMail(mailOptions, (error, info) => {
|
||||
if (error) {
|
||||
console.log(error)
|
||||
}
|
||||
console.log('sent: ', info)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sendSecretLink
|
||||
}
|
||||
Reference in New Issue
Block a user