Commit 3d43fe71 authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

refactor

parent 4b8ad40c
Showing with 121 additions and 99 deletions
+121 -99
/built /built
/routes/cert /src/routes/cert
/node_modules /node_modules
import dbconn = require('../config/dbconn') import dbconn = require('../config/dbconn')
const methods = { const dbController = {
// ===================== user db ===================== // ===================== user db =====================
registerNewUser: function (data: any, callback: any) { registerNewUser: function (data: any, callback: any) {
dbconn.user.getConnection(function (err: any, thisconn) { dbconn.user.getConnection(function (err: any, thisconn) {
...@@ -205,4 +205,4 @@ const methods = { ...@@ -205,4 +205,4 @@ const methods = {
} }
} }
export = methods export { dbController }
...@@ -5,7 +5,7 @@ import formData from 'form-data' ...@@ -5,7 +5,7 @@ import formData from 'form-data'
const env = process.env.NODE_ENV || 'testing' const env = process.env.NODE_ENV || 'testing'
const config = require('../config/config')[env] const config = require('../config/config')[env]
const gitlab = { const gitlabController = {
getUserByEmail: async function (email: string) { getUserByEmail: async function (email: string) {
return await axios({ return await axios({
method: 'get', method: 'get',
...@@ -24,8 +24,8 @@ const gitlab = { ...@@ -24,8 +24,8 @@ const gitlab = {
return await axios({ return await axios({
method: 'post', method: 'post',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/user/' + newPagesData.getOwnerGitlabId() + url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/user/' + String(newPagesData.getOwnerGitlabId()) +
'?name=' + newPagesData.getName() + '&description=' + newPagesData.getDesc() + '&tag_list=website' + '?name=' + String(newPagesData.getName()) + '&description=' + String(newPagesData.getDesc()) + '&tag_list=website' +
'&use_custom_template=true&template_name=' + template, '&use_custom_template=true&template_name=' + template,
headers: { headers: {
Authorization: 'Bearer ' + config.gitlab.token_readWriteProjects, Authorization: 'Bearer ' + config.gitlab.token_readWriteProjects,
...@@ -124,4 +124,4 @@ const gitlab = { ...@@ -124,4 +124,4 @@ const gitlab = {
} }
} }
export = gitlab export {gitlabController}
import async from 'async'
import mailer from '../config/mailer'
import { dbController } from './dbController'
const lang = 'DE'
const publicController = {
showRegistrationPage: function (res: any) {
res.render(lang + '/account/registration')
},
showContactPage: function (req: any, res: any) {
res.render(lang + '/account/contact', {
user: req.user
})
},
showForgotPwdPage: function (req: any, res: any) {
res.render(lang + '/account/forgotPwd', {
user: req.user
})
},
showResetToken: async function (req: any, res: any) {
const user = await dbController.getUserByToken(req.params.token)
if (user) {
res.render(lang + '/account/reset')
} else {
res.flash('error', 'Der Schlüssel zum zurücksetzen des Passworts ist ungültig oder abgelaufen.')
res.redirect('/account/forgotPwd')
}
},
sendContactMessage: function (req: any, res: any) {
const emailAddress = req.body.inputEmail
const supportAddress = 'support-transfer@hft-stuttgart.de'
const inputName = req.body.name
const inputContent = req.body.message
const emailSubject = 'Ihre Anfrage an das Transferportal'
const emailContent = '<div>Es wurde eine Anfrage an das Transferportal gestellt: <br/><br/>NAME: ' + inputName + '<br/>NACHRICHT: ' + inputContent + '</div>'
async.waterfall([
function (done: any) {
// send email
mailer.options.to = supportAddress
mailer.options.cc = emailAddress
mailer.options.subject = emailSubject
mailer.options.html = emailContent
mailer.transporter.sendMail(mailer.options, function (err: any) {
done(err, 'done')
})
}
], function (err: any) {
if (!err) { res.flash('success', 'Vielen Dank für Ihre Anfrage. Wir melden uns baldmöglichst bei Ihnen. Eine Kopie Ihrer Anfrage wurde an ' + emailAddress + ' versandt.') } else {
console.error(err)
res.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.')
}
res.redirect('/account/contact')
})
},
checkUserEmail: async function (req: any, res: any) {
const user = await dbController.checkUserEmail(req.params.email)
if (user) { res.send(false) } else {
res.send(true)
}
}
}
export { publicController }
File moved
...@@ -3,8 +3,8 @@ import async from 'async' ...@@ -3,8 +3,8 @@ import async from 'async'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
import * as passportSaml from 'passport-saml' import * as passportSaml from 'passport-saml'
import dbconn from '../config/dbconn' import dbconn from '../config/dbconn'
import methods from '../functions/methods' import { dbController } from '../controller/dbController'
import gitlab from '../functions/gitlab' import { gitlabController } from '../controller/gitlabController'
import constants from '../config/const' import constants from '../config/const'
import mailer from '../config/mailer' import mailer from '../config/mailer'
import portalUser from '../classes/user' import portalUser from '../classes/user'
...@@ -83,7 +83,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -83,7 +83,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
// ======== APP ROUTES - ACCOUNT ==================== // ======== APP ROUTES - ACCOUNT ====================
async function getLoggedInUserData (email: string) { async function getLoggedInUserData (email: string) {
const user = await methods.getUserByEmail(email) const user = await dbController.getUserByEmail(email)
if (!user) { if (!user) {
console.log('no user found') console.log('no user found')
return null return null
...@@ -92,7 +92,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -92,7 +92,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
user.id, email, user.salutation, user.title, user.firstname, user.lastname, user.industry, user.organisation, user.speciality, user.m4lab_idp, user.verificationStatus user.id, email, user.salutation, user.title, user.firstname, user.lastname, user.industry, user.organisation, user.speciality, user.m4lab_idp, user.verificationStatus
) )
const userGitlabId = await methods.getGitlabId(loggedInUser.id) const userGitlabId = await dbController.getGitlabId(loggedInUser.id)
if (userGitlabId) { if (userGitlabId) {
loggedInUser.setGitlabUserId(userGitlabId) loggedInUser.setGitlabUserId(userGitlabId)
} }
...@@ -153,7 +153,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -153,7 +153,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
if (loggedInUser == null) { // null user if (loggedInUser == null) { // null user
res.redirect('/account/') res.redirect('/account/')
} else { } else {
if (loggedInUser.getVerificationStatus() != 1) { if (loggedInUser.getVerificationStatus() !== 1) {
res.redirect('/account/') res.redirect('/account/')
} else { } else {
res.render(lang + '/account/profile', { res.render(lang + '/account/profile', {
...@@ -172,14 +172,14 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -172,14 +172,14 @@ export = function (app: any, config: any, passport: any, lang: string) {
if (loggedInUser == null) { // null user if (loggedInUser == null) { // null user
res.redirect('/account/') res.redirect('/account/')
} else { } else {
if (loggedInUser.getVerificationStatus() != 1) { // unverified users if (loggedInUser.getVerificationStatus() !== 1) { // unverified users
res.redirect('/account/') res.redirect('/account/')
} else { } else {
const gitlabReposArr = [] const gitlabReposArr = []
const gitlabPagesArr = [] const gitlabPagesArr = []
if (loggedInUser.getGitlabUserId()) { // for users who have activated their gitlab account if (loggedInUser.getGitlabUserId()) { // for users who have activated their gitlab account
const userProjects = await gitlab.getUserProjects(loggedInUser.getGitlabUserId()!) const userProjects = await gitlabController.getUserProjects(loggedInUser.getGitlabUserId()!)
if (!userProjects) { if (!userProjects) {
console.error('something went wrong') console.error('something went wrong')
res.status(500).render(lang + '/500', { error: 'something went wrong' }) res.status(500).render(lang + '/500', { error: 'something went wrong' })
...@@ -191,7 +191,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -191,7 +191,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
const page = { const page = {
projectInformation: new projectInformation(loggedInUser.getGitlabUserId()!, userProjects[project].name, userProjects[project].description, projectInformation: new projectInformation(loggedInUser.getGitlabUserId()!, userProjects[project].name, userProjects[project].description,
userProjects[project].id, userProjects[project].avatar_url, userProjects[project].path_with_namespace), userProjects[project].id, userProjects[project].avatar_url, userProjects[project].path_with_namespace),
pipelineStatus: await gitlab.getProjectPipelineLatestStatus(userProjects[project].id) pipelineStatus: await gitlabController.getProjectPipelineLatestStatus(userProjects[project].id)
} }
gitlabPagesArr.push(page) gitlabPagesArr.push(page)
} else { } else {
...@@ -207,7 +207,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -207,7 +207,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
gitlabPages: gitlabPagesArr gitlabPages: gitlabPagesArr
}) })
} else { // for users who have not activated their gitlab account yet } else { // for users who have not activated their gitlab account yet
const gitlabUser = await gitlab.getUserByEmail(loggedInUser.getEmail()) const gitlabUser = await gitlabController.getUserByEmail(loggedInUser.getEmail())
if (!gitlabUser) { if (!gitlabUser) {
res.render(lang + '/account/services', { res.render(lang + '/account/services', {
user: loggedInUser, user: loggedInUser,
...@@ -220,7 +220,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -220,7 +220,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
gitlab_userId: gitlabUser.id gitlab_userId: gitlabUser.id
} }
methods.addGitlabUser(gitlabActivationData, function (err: any) { dbController.addGitlabUser(gitlabActivationData, function (err: any) {
if (err) { if (err) {
res.status(500).render(lang + '/500', { error: err }) res.status(500).render(lang + '/500', { error: err })
} else { } else {
...@@ -242,7 +242,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -242,7 +242,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
if (loggedInUser == null) { // null user if (loggedInUser == null) { // null user
res.redirect('/account/') res.redirect('/account/')
} else { } else {
if (loggedInUser.getVerificationStatus() == 1 && loggedInUser.getIdpStatus() == 1) { if (loggedInUser.getVerificationStatus() === 1 && loggedInUser.getIdpStatus() === 1) {
res.render(lang + '/account/security', { res.render(lang + '/account/security', {
user: loggedInUser user: loggedInUser
}) })
...@@ -271,7 +271,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -271,7 +271,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
industry: req.body.inputIndustry, industry: req.body.inputIndustry,
speciality: req.body.inputSpeciality speciality: req.body.inputSpeciality
} }
const result = await methods.updateUserById(loggedInUser.getId(), userData) const result = await dbController.updateUserById(loggedInUser.getId(), userData)
if (!result) { if (!result) {
res.flash('error', 'Failed') res.flash('error', 'Failed')
} else { } else {
...@@ -325,7 +325,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -325,7 +325,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
user_id: loggedInUser.getId() user_id: loggedInUser.getId()
} }
const result = await methods.updateCredential(credentialData) const result = await dbController.updateCredential(credentialData)
if (!result) { if (!result) {
console.log('Failed to reset password') console.log('Failed to reset password')
res.flash('error', 'Datenbankfehler: Passwort kann nicht geändert werden.') res.flash('error', 'Datenbankfehler: Passwort kann nicht geändert werden.')
...@@ -358,7 +358,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -358,7 +358,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
if (loggedInUser == null) { if (loggedInUser == null) {
res.redirect('/login') res.redirect('/login')
} else { } else {
const token = await methods.getVerificationTokenByUserId(loggedInUser.id) const token = await dbController.getVerificationTokenByUserId(loggedInUser.id)
if (!token) { if (!token) {
res.send(false) res.send(false)
} else { } else {
...@@ -395,7 +395,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -395,7 +395,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
if (loggedInUser == null) { if (loggedInUser == null) {
res.redirect('/login') res.redirect('/login')
} else { } else {
const gitlabUser = await gitlab.getUserByEmail(loggedInUser.getEmail()) const gitlabUser = await gitlabController.getUserByEmail(loggedInUser.getEmail())
if (!gitlabUser) { // no user found if (!gitlabUser) { // no user found
res.redirect('/account/services') res.redirect('/account/services')
} else { } else {
...@@ -439,7 +439,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -439,7 +439,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
} }
}, },
async function (newLogoFile: any) { // create a new GitLab Page async function (newLogoFile: any) { // create a new GitLab Page
const newPages = await gitlab.createNewPages(newInformation, newLogoFile, projectTemplate) const newPages = await gitlabController.createNewPages(newInformation, newLogoFile, projectTemplate)
if (newPages.status) { if (newPages.status) {
if (newPages.data.message.name == 'has already been taken') { if (newPages.data.message.name == 'has already been taken') {
res.flash('error', "Der Projektname '" + newInformation.getName() + "' ist bereits vergeben, bitte wählen Sie einen anderen Namen.") res.flash('error', "Der Projektname '" + newInformation.getName() + "' ist bereits vergeben, bitte wählen Sie einen anderen Namen.")
...@@ -450,7 +450,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -450,7 +450,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
} else { } else {
res.flash('success', 'Ihre Webseite wurde erstellt, aber noch nicht veröffentlicht. Um Ihre Webseite endgültig zu veröffentlichen, ' + res.flash('success', 'Ihre Webseite wurde erstellt, aber noch nicht veröffentlicht. Um Ihre Webseite endgültig zu veröffentlichen, ' +
'schließen Sie die Einrichtung gemäß unten stehender Anleitung ab.') 'schließen Sie die Einrichtung gemäß unten stehender Anleitung ab.')
res.redirect('/account/updateInformation?id=' + newPages.id) res.redirect('/account/updateInformation?id=' + String(newPages.id))
} }
} }
], function (err) { ], function (err) {
...@@ -479,7 +479,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -479,7 +479,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
if (!req.query.id) { if (!req.query.id) {
res.redirect('/account/services') res.redirect('/account/services')
} else { } else {
const project = await gitlab.getProjectById(req.query.id) const project = await gitlabController.getProjectById(req.query.id)
if (!project) { if (!project) {
console.log(' ========= Error or no project found') console.log(' ========= Error or no project found')
res.redirect('/account/services') res.redirect('/account/services')
...@@ -527,18 +527,18 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -527,18 +527,18 @@ export = function (app: any, config: any, passport: any, lang: string) {
callback(null, newLogoFile) callback(null, newLogoFile)
} else { } else {
newLogoFile = req.files.logo newLogoFile = req.files.logo
newLogoFile.mv(logoDir + newLogoFile.name, function (err: any) { newLogoFile.mv(logoDir + String(newLogoFile.name), function (err: any) {
newLogoFile = logoDir + newLogoFile.name newLogoFile = logoDir + String(newLogoFile.name)
callback(err, newLogoFile) callback(err, newLogoFile)
}) })
} }
}, },
async function (newLogoFile: any) { // update gitlab page async function (newLogoFile: any) { // update gitlab page
const updatedPages = await gitlab.updateProject(updatedInformation, newLogoFile) const updatedPages = await gitlabController.updateProject(updatedInformation, newLogoFile)
if (updatedPages.status) { if (updatedPages.status) {
if (updatedPages.data.message.name == 'has already been taken') { if (updatedPages.data.message.name === 'has already been taken') {
res.flash('error', "Der Projektname '" + projectName + "' ist bereits vergeben, bitte wählen Sie einen anderen Namen.") res.flash('error', "Der Projektname '" + String(projectName) + "' ist bereits vergeben, bitte wählen Sie einen anderen Namen.")
} else { } else {
res.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut. ') res.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut. ')
} }
...@@ -575,7 +575,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -575,7 +575,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
if (projectId) { if (projectId) {
// check if the owner is valid // check if the owner is valid
const project = await gitlab.getProjectById(projectId) const project = await gitlabController.getProjectById(projectId)
if (!project) { if (!project) {
console.log(' ========= Error or no project found') console.log(' ========= Error or no project found')
} else if (!project.owner) { } else if (!project.owner) {
...@@ -583,7 +583,7 @@ export = function (app: any, config: any, passport: any, lang: string) { ...@@ -583,7 +583,7 @@ export = function (app: any, config: any, passport: any, lang: string) {
} else if (project.owner.id != loggedInUser.getGitlabUserId()) { } else if (project.owner.id != loggedInUser.getGitlabUserId()) {
console.log(' ========= Access denied: Not your project') console.log(' ========= Access denied: Not your project')
} else { } else {
const isDeleted = await gitlab.deleteProjectById(projectId) const isDeleted = await gitlabController.deleteProjectById(projectId)
if (!isDeleted) { if (!isDeleted) {
res.flash('error', 'Project cannot be deleted. Please try again.') res.flash('error', 'Project cannot be deleted. Please try again.')
} }
......
import async from 'async' import async from 'async'
import bcrypt from 'bcryptjs' import bcrypt from 'bcryptjs'
import methods from '../functions/methods' import { dbController } from '../controller/dbController'
import mailer from '../config/mailer' import mailer from '../config/mailer'
import constants from '../config/const' import constants from '../config/const'
import { publicController } from '../controller/publicController'
const saltRounds: number = 10 const saltRounds: number = 10
const salt: number = 64 const salt: number = 64
...@@ -10,7 +11,7 @@ const salt: number = 64 ...@@ -10,7 +11,7 @@ const salt: number = 64
export = function (app: any, config: any, lang: string) { export = function (app: any, config: any, lang: string) {
// ================== NEW USERS REGISTRATION ====================== // ================== NEW USERS REGISTRATION ======================
app.get('/registration', function (req: any, res: any) { app.get('/registration', function (req: any, res: any) {
res.render(lang + '/account/registration') publicController.showRegistrationPage(res)
}) })
app.post('/registration', function (req: any, res: any) { app.post('/registration', function (req: any, res: any) {
// user data // user data
...@@ -58,7 +59,7 @@ export = function (app: any, config: any, lang: string) { ...@@ -58,7 +59,7 @@ export = function (app: any, config: any, lang: string) {
}, },
// save data // save data
function (newAccount: any, err: any) { function (newAccount: any, err: any) {
methods.registerNewUser(newAccount, function (err: any) { dbController.registerNewUser(newAccount, function (err: any) {
if (err) { if (err) {
res.flash('error', 'Fehlgeschlagen') res.flash('error', 'Fehlgeschlagen')
} else { } else {
...@@ -66,16 +67,16 @@ export = function (app: any, config: any, lang: string) { ...@@ -66,16 +67,16 @@ export = function (app: any, config: any, lang: string) {
const emailSubject = 'Bitte bestätigen Sie Ihr M4_LAB Benutzerkonto' const emailSubject = 'Bitte bestätigen Sie Ihr M4_LAB Benutzerkonto'
const emailContent = '<div>Lieber Nutzer,<br/><br/>' + const emailContent = '<div>Lieber Nutzer,<br/><br/>' +
'<p>vielen Dank für Ihre Anmeldung am Transferportal der HFT Stuttgart. <br/>' + '<p>vielen Dank für Ihre Anmeldung am Transferportal der HFT Stuttgart. <br/>' +
'Um Ihre Anmeldung zu bestätigen, klicken Sie bitte <a href=' + config.app.host + '/verifyAccount?token=' + newAccount.verificationToken + '>diesen Link</a> ' + 'Um Ihre Anmeldung zu bestätigen, klicken Sie bitte <a href=' + String(config.app.host) + '/verifyAccount?token=' + String(newAccount.verificationToken) + '>diesen Link</a> ' +
'<br/><br/>' + '<br/><br/>' +
'Ohne Bestätigung Ihres Kontos müssen wir Ihr Konto leider nach 7 Tagen löschen.</p><br/>' + constants.mailSignature + 'Ohne Bestätigung Ihres Kontos müssen wir Ihr Konto leider nach 7 Tagen löschen.</p><br/>' + String(constants.mailSignature) +
'</div>' '</div>'
mailer.options.to = req.body.inputEmail mailer.options.to = req.body.inputEmail
mailer.options.subject = emailSubject mailer.options.subject = emailSubject
mailer.options.html = emailContent mailer.options.html = emailContent
mailer.transporter.sendMail(mailer.options, function (err: any) { mailer.transporter.sendMail(mailer.options, function (err: any) {
if (err) { if (err) {
console.error('Cannot send email. [Error] ' + err) console.error('Cannot send email. [Error] ' + String(err))
throw err throw err
} }
}) })
...@@ -92,20 +93,13 @@ export = function (app: any, config: any, lang: string) { ...@@ -92,20 +93,13 @@ export = function (app: any, config: any, lang: string) {
}) })
// to check whether or not an account is already exist // to check whether or not an account is already exist
app.get('/email/:email', async function (req: any, res: any) { app.get('/email/:email', async function (req: any, res: any) {
const user = await methods.checkUserEmail(req.params.email) publicController.checkUserEmail(req, res)
if (!user) {
console.log('No user found: ' + req.params.email)
res.send(true)
} else {
console.log('User found: ' + req.params.email)
res.send(false)
}
}) })
// =================== USERS VERIFICATION ========================= // =================== USERS VERIFICATION =========================
app.get('/verifyAccount', async function (req: any, res: any) { app.get('/verifyAccount', async function (req: any, res: any) {
const userId: number = await methods.getUserIdByVerificationToken(req.query.token) const userId: number = await dbController.getUserIdByVerificationToken(req.query.token)
if (!userId) { if (!userId) {
// no user found // no user found
res.render(lang + '/account/verification', { res.render(lang + '/account/verification', {
...@@ -117,15 +111,15 @@ export = function (app: any, config: any, lang: string) { ...@@ -117,15 +111,15 @@ export = function (app: any, config: any, lang: string) {
id: userId, id: userId,
verificationStatus: 1 verificationStatus: 1
} }
methods.verifyUserAccount(userData, async function (err: any) { dbController.verifyUserAccount(userData, async function (err: any) {
if (err) { if (err) {
console.log('Error: ' + err) console.error(err)
res.render(lang + '/account/verification', { res.render(lang + '/account/verification', {
status: false status: false
}) })
} else { } else {
// send welcome email after successful account verification // send welcome email after successful account verification
const userEmail: string = await methods.getUserEmailById(userId) const userEmail: string = await dbController.getUserEmailById(userId)
if (!userEmail) { if (!userEmail) {
res.render(lang + '/account/verification', { res.render(lang + '/account/verification', {
status: false status: false
...@@ -158,17 +152,15 @@ export = function (app: any, config: any, lang: string) { ...@@ -158,17 +152,15 @@ export = function (app: any, config: any, lang: string) {
// ==================== FORGOT PASSWORD =========================== // ==================== FORGOT PASSWORD ===========================
app.get('/forgotPwd', function (req: any, res: any) { app.get('/forgotPwd', function (req: any, res: any) {
res.render(lang + '/account/forgotPwd', { publicController.showForgotPwdPage(req, res)
user: req.user
})
}) })
app.post('/forgotPwd', function (req: any, res: any) { app.post('/forgotPwd', function (req: any, res: any) {
const emailAddress = req.body.inputEmail const emailAddress = req.body.inputEmail
async.waterfall([ async.waterfall([
async function (done: any) { async function (done: any) {
const user = await methods.checkUserEmail(emailAddress) const user = await dbController.checkUserEmail(emailAddress)
if (!user) { if (!user) {
console.log('No user found: ' + emailAddress) console.log('No user found: ' + String(emailAddress))
} else { } else {
// generate token // generate token
let token: string = '' let token: string = ''
...@@ -180,15 +172,15 @@ export = function (app: any, config: any, lang: string) { ...@@ -180,15 +172,15 @@ export = function (app: any, config: any, lang: string) {
const emailSubject = 'Ihre Passwort-Anfrage an das Transferportal der HFT Stuttgart' const emailSubject = 'Ihre Passwort-Anfrage an das Transferportal der HFT Stuttgart'
const emailContent = '<div>Lieber Nutzer,<br/><br/>' + const emailContent = '<div>Lieber Nutzer,<br/><br/>' +
'<p>wir haben Ihre Anfrage zur Erneuerung Ihres Passwortes erhalten. Falls Sie diese Anfrage nicht gesendet haben, ignorieren Sie bitte diese E-Mail.<br/><br/>' + '<p>wir haben Ihre Anfrage zur Erneuerung Ihres Passwortes erhalten. Falls Sie diese Anfrage nicht gesendet haben, ignorieren Sie bitte diese E-Mail.<br/><br/>' +
'Sie können Ihr Passwort mit dem Klick auf diesen Link ändern: ' + config.app.host + '/reset/' + token + '<br/>' + 'Sie können Ihr Passwort mit dem Klick auf diesen Link ändern: ' + String(config.app.host) + '/reset/' + String(token) + '<br/>' +
'Dieser Link ist aus Sicherheitsgründen nur für 1 Stunde gültig.<br/></p>' + constants.mailSignature + '</div>' 'Dieser Link ist aus Sicherheitsgründen nur für 1 Stunde gültig.<br/></p>' + String(constants.mailSignature) + '</div>'
const credentialData = { const credentialData = {
user_id: user.id, user_id: user.id,
resetPasswordToken: token, resetPasswordToken: token,
resetPasswordExpires: Date.now() + 3600000 // 1 hour resetPasswordExpires: Date.now() + 3600000 // 1 hour
} }
const result = await methods.updateCredential(credentialData) const result = await dbController.updateCredential(credentialData)
if (!result) { if (!result) {
console.log('failed to update credential') console.log('failed to update credential')
} else { } else {
...@@ -207,7 +199,7 @@ export = function (app: any, config: any, lang: string) { ...@@ -207,7 +199,7 @@ export = function (app: any, config: any, lang: string) {
if (err) { if (err) {
res.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.') res.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.')
} else { } else {
res.flash('success', 'Wenn Ihre E-Mail-Adresse registriert ist, wurde eine E-Mail mit dem weiteren Vorgehen an ' + emailAddress + ' versendet.') res.flash('success', 'Wenn Ihre E-Mail-Adresse registriert ist, wurde eine E-Mail mit dem weiteren Vorgehen an ' + String(emailAddress) + ' versendet.')
} }
res.redirect('/account/forgotPwd') res.redirect('/account/forgotPwd')
}) })
...@@ -215,18 +207,12 @@ export = function (app: any, config: any, lang: string) { ...@@ -215,18 +207,12 @@ export = function (app: any, config: any, lang: string) {
// reset // reset
app.get('/reset/:token', async function (req: any, res: any) { app.get('/reset/:token', async function (req: any, res: any) {
const user = await methods.getUserByToken(req.params.token) publicController.showResetToken(req, res)
if (!user) {
res.flash('error', 'Der Schlüssel zum zurücksetzen des Passworts ist ungültig oder abgelaufen.')
res.redirect('/account/forgotPwd')
} else {
res.render(lang + '/account/reset')
}
}) })
app.post('/reset/:token', async function (req: any, res: any) { app.post('/reset/:token', async function (req: any, res: any) {
const newPwd = req.body.inputNewPwd const newPwd = req.body.inputNewPwd
const user = await methods.getUserByToken(req.params.token) const user = await dbController.getUserByToken(req.params.token)
if (!user) { if (!user) {
res.flash('error', 'User not found.') res.flash('error', 'User not found.')
res.redirect('/login') res.redirect('/login')
...@@ -241,7 +227,7 @@ export = function (app: any, config: any, lang: string) { ...@@ -241,7 +227,7 @@ export = function (app: any, config: any, lang: string) {
resetPasswordExpires: null resetPasswordExpires: null
} }
// update password // update password
const result = await methods.updateCredential(credentialData) const result = await dbController.updateCredential(credentialData)
if (!result) { if (!result) {
console.log('Failed to reset password') console.log('Failed to reset password')
res.flash('error', 'Datenbankfehler: Passwort kann nicht geändert werden.') res.flash('error', 'Datenbankfehler: Passwort kann nicht geändert werden.')
...@@ -263,37 +249,9 @@ export = function (app: any, config: any, lang: string) { ...@@ -263,37 +249,9 @@ export = function (app: any, config: any, lang: string) {
// ======================= CONTACT FORM =========================== // ======================= CONTACT FORM ===========================
app.get('/contact', function (req: any, res: any) { app.get('/contact', function (req: any, res: any) {
res.render(lang + '/account/contact', { publicController.showContactPage(req, res)
user: req.user
})
}) })
app.post('/contact', function (req: any, res: any, next: any) { app.post('/contact', function (req: any, res: any) {
// methods.currentDate(); publicController.sendContactMessage(req, res)
const emailAddress = req.body.inputEmail
const supportAddress = 'support-transfer@hft-stuttgart.de'
const inputName = req.body.name
const inputContent = req.body.message
const emailSubject = 'Ihre Anfrage an das Transferportal'
const emailContent = '<div>Es wurde eine Anfrage an das Transferportal gestellt: <br/><br/>NAME: ' + inputName + '<br/>NACHRICHT: ' + inputContent + '</div>'
async.waterfall([
function (done: any) {
// send email
mailer.options.to = supportAddress
mailer.options.cc = emailAddress
mailer.options.subject = emailSubject
mailer.options.html = emailContent
mailer.transporter.sendMail(mailer.options, function (err: any) {
done(err, 'done')
})
}
], function (err: any) {
if (err) {
console.error(err)
res.flash('error', 'Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut.')
} else {
res.flash('success', 'Vielen Dank für Ihre Anfrage. Wir melden uns baldmöglichst bei Ihnen. Eine Kopie Ihrer Anfrage wurde an ' + emailAddress + ' versandt.')
}
res.redirect('/account/contact')
})
}) })
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment