diff --git a/functions/methods.ts b/functions/methods.ts index cebfcb2179d5dcd9dc70e591708c6bd69300523c..f6a4eb5972d88f3102a138a05660dc477e6cd473 100644 --- a/functions/methods.ts +++ b/functions/methods.ts @@ -3,62 +3,64 @@ import dbconn = require('../config/dbconn') var methods = { // ===================== user db ===================== registerNewUser: function(data:any, callback:any) { - dbconn.user.beginTransaction(function(err:any) { // START TRANSACTION - if (err) { throw err } - // insert profile - dbconn.user.query('INSERT INTO user SET ?', data.profile, function (err:any, results:any, fields:any) { - if (err) { - return dbconn.user.rollback(function() { - throw err - }); - } - let newUserId:number = results.insertId - // set password - var credentialData:any = { - user_id: newUserId, - password: data.password - } - dbconn.user.query('INSERT INTO credential SET ?', credentialData, function (err:any, results:any, fields:any) { + dbconn.user.getConnection(function(err:any, thisconn){ + thisconn.beginTransaction(function(err:any) { // START TRANSACTION + if (err) { throw err } + // insert profile + thisconn.query('INSERT INTO user SET ?', data.profile, function (err:any, results:any, fields:any) { if (err) { - return dbconn.user.rollback(function() { - throw err - }); + return thisconn.rollback(function() { + throw err + }); } - // set default user-project-role - var projectRoleData:any = { - project_id: 1, //M4_LAB - role_id: 2, // USER - user_id: newUserId + let newUserId:number = results.insertId + // set password + var credentialData:any = { + user_id: newUserId, + password: data.password } - dbconn.user.query('INSERT INTO user_project_role SET ?', projectRoleData, function (err:any, results:any, fields:any) { + thisconn.query('INSERT INTO credential SET ?', credentialData, function (err:any, results:any, fields:any) { if (err) { - return dbconn.user.rollback(function() { + return thisconn.rollback(function() { throw err }); } - // MLAB-129: INSERT verification token - let verificationData:any = { - user_id: newUserId, - token: data.verificationToken + // set default user-project-role + var projectRoleData:any = { + project_id: 1, //M4_LAB + role_id: 2, // USER + user_id: newUserId } - dbconn.user.query('INSERT INTO verification SET ?', verificationData, function (err:any, results:any, fields:any) { + thisconn.query('INSERT INTO user_project_role SET ?', projectRoleData, function (err:any, results:any, fields:any) { if (err) { - return dbconn.user.rollback(function() { + return thisconn.rollback(function() { throw err }); } - // COMMIT - dbconn.user.commit(function(err:any) { + // MLAB-129: INSERT verification token + let verificationData:any = { + user_id: newUserId, + token: data.verificationToken + } + thisconn.query('INSERT INTO verification SET ?', verificationData, function (err:any, results:any, fields:any) { if (err) { - return dbconn.user.rollback(function() { + return thisconn.rollback(function() { throw err - }) + }); } + // COMMIT + thisconn.commit(function(err:any) { + if (err) { + return thisconn.rollback(function() { + throw err + }) + } + }) }) }) - }) + }); }); - }); + }); callback(err) }) }, @@ -162,27 +164,29 @@ var methods = { return null }, verifyUserAccount: function(userData:any, callback:any) { - dbconn.user.beginTransaction(function(err:any) { // START TRANSACTION - if (err) { throw err } - // update user status - dbconn.user.query('UPDATE user SET ? WHERE id =' +userData.id, userData, function (err:any, rows:any, fields:any) { - if (err) { - return dbconn.user.rollback(function() { throw err }) - } - // delete verification token - dbconn.user.query('DELETE FROM verification WHERE user_id = '+userData.id, function (err:any, rows:any, fields:any) { + dbconn.user.getConnection(function(err:any, thisconn){ + thisconn.beginTransaction(function(err:any) { // START TRANSACTION + if (err) { throw err } + // update user status + thisconn.query('UPDATE user SET ? WHERE id =' +userData.id, userData, function (err:any, rows:any, fields:any) { if (err) { - return dbconn.user.rollback(function() { throw err }) + return thisconn.rollback(function() { throw err }) } - // COMMIT - dbconn.user.commit(function(err:any) { + // delete verification token + thisconn.query('DELETE FROM verification WHERE user_id = '+userData.id, function (err:any, rows:any, fields:any) { if (err) { - return dbconn.user.rollback(function() { throw err }) + return thisconn.rollback(function() { throw err }) } + // COMMIT + thisconn.commit(function(err:any) { + if (err) { + return thisconn.rollback(function() { throw err }) + } + }) }) }) }) - callback(err) + callback(err) }) }, /* ===== GitLab ===== */ @@ -208,4 +212,4 @@ var methods = { } }; -export = methods \ No newline at end of file +export = methods diff --git a/routes/account.ts b/routes/account.ts index 68c3ca613a942c9b1d8f75e072b07d0f4377d7c8..f47a1ac4892fdd663bbb3c1e86d66c17c96a20fb 100644 --- a/routes/account.ts +++ b/routes/account.ts @@ -106,10 +106,14 @@ export = function (app:any, config:any, passport:any, lang:string) { res.redirect('/login') } else { let loggedInUser = await getLoggedInUserData(req.user.email) - - res.render(lang+'/account/home', { - user: loggedInUser - }); + if (!loggedInUser) { + console.error("user data is not found") + res.status(500).render(lang+'/500', { error: "Your data is not found. Please try again." }) + } else { + res.render(lang+'/account/home', { + user: loggedInUser + }); + } } }); @@ -282,7 +286,7 @@ export = function (app:any, config:any, passport:any, lang:string) { } }); - app.post('/account/changePwd', async function (req:any, res:any) { + app.post('/changePwd', async function (req:any, res:any) { if( !req.isAuthenticated() ) { res.redirect('/login') } else { diff --git a/views/DE/account/contact.pug b/views/DE/account/contact.pug index 99c37ce949e6a54d2e8c31b406d8a674edc73058..d25a801dd2ea2a088d55e64e595347c47db040e1 100644 --- a/views/DE/account/contact.pug +++ b/views/DE/account/contact.pug @@ -6,6 +6,7 @@ html(lang="de") meta(name="viewport", content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no") link(rel="stylesheet", type="text/css", href="/css/bootstrap.min.css") link(rel="stylesheet", type="text/css", href="/css/m4lab.css") + link(rel="stylesheet", type="text/css", href="/css/m4lab-mobile.css") link(rel="stylesheet", type="text/css", href="/css/Contact-Form-Clean.css") link(rel="stylesheet", href="https://use.fontawesome.com/releases/v5.8.2/css/all.css", integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay", crossorigin="anonymous") body @@ -52,3 +53,4 @@ html(lang="de") script(src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous") // M4_LAB script(src="/js/headfoot.js") + script(src="/js/mobile.js") diff --git a/views/DE/account/profile.pug b/views/DE/account/profile.pug index 8ab9bf550e30e249616c9cea366057c9286dbd7b..3c109a51f671e21cea635353f6fa589045cdbf2d 100644 --- a/views/DE/account/profile.pug +++ b/views/DE/account/profile.pug @@ -49,7 +49,7 @@ html(lang="de") a(class="close", href="#", data-dismiss="alert", aria-label="close") × h3(class="pb-2") Mein Profil - form#profileForm(method="POST", action="/updateProfile") + form#profileForm(method="POST", action="/account/updateProfile") div(class="form-row") div(class='form-group col-md-2') label(for="title") Anrede diff --git a/views/DE/account/updateInformation.pug b/views/DE/account/updateInformation.pug index 58cd8a42bbbda6f773864ea1cbab81e87abed816..130dd95e687f0145f7cbafba1e69751664f70832 100644 --- a/views/DE/account/updateInformation.pug +++ b/views/DE/account/updateInformation.pug @@ -130,7 +130,7 @@ html(lang="de") |
Sie sind dabei, diese Webseite, ihr Repositorium und alle zugehörigen Ressourcen, inklusive aller Inhalte, Bilder etc. endgültig zu löschen.
|Sobald eine Webseite endgültig gelöscht ist, kann sie nicht wiederhergestellt werden. Diese Aktion kann nicht rückgängig gemacht werden.
div(class="modal-footer") - form(method="POST", action="/deleteProject?_method=DELETE", encType="multipart/form-data") + form(method="POST", action="/account/deleteProject?_method=DELETE", encType="multipart/form-data") input(name="id", value=information.id, type="hidden") button(type="button" class="btn btn-primary mx-2" data-dismiss="modal") Abbrechen, Webseite behalten button(type="submit" class="btn btn-danger") Ja, Webseite löschen