thisconn.query('INSERT INTO user SET ?',data.profile,function(err:any,results:any,fields:any){
if(err){
returnthisconn.rollback(function(){
throwerr
});
}
letnewUserId:number=results.insertId
// set password
varcredentialData:any={
user_id:newUserId,
password:data.password
}
thisconn.query('INSERT INTO credential SET ?',credentialData,function(err:any,results:any,fields:any){
if(err){
returnthisconn.rollback(function(){
throwerr
});
}
// set default user-project-role
varprojectRoleData:any={
project_id:1,//M4_LAB
role_id:2,// USER
user_id:newUserId
}
thisconn.query('INSERT INTO user_project_role SET ?',projectRoleData,function(err:any,results:any,fields:any){
if(err){
returnthisconn.rollback(function(){
throwerr
});
}
// MLAB-129: INSERT verification token
letverificationData:any={
user_id:newUserId,
token:data.verificationToken
}
thisconn.query('INSERT INTO verification SET ?',verificationData,function(err:any,results:any,fields:any){
if(err){
returnthisconn.rollback(function(){
throwerr
});
}
// COMMIT
thisconn.commit(function(err:any){
if(err){
returnthisconn.rollback(function(){
throwerr
})
}
})
})
})
});
});
});
callback(err)
})
},
getUserByEmail:asyncfunction(email:any){
try{
letrows:any=awaitdbconn.user.promise().query('SELECT id, verificationStatus, salutation, title, firstname, lastname, industry, organisation, speciality, m4lab_idp FROM user WHERE email = "'+email+'"')
if(rows[0][0]){
returnrows[0][0]
}
else{returnnull}
}catch(err){
console.error(err)
}
returnnull
},
getUserEmailById:asyncfunction(userId:number){
try{
letrows:any=awaitdbconn.user.promise().query('SELECT email FROM user WHERE id = '+userId)
if(rows[0][0]){
returnrows[0][0].email
}
else{returnnull}
}catch(err){
console.error(err)
}
returnnull
},
checkUserEmail:asyncfunction(email:any){
try{
letrows:any=awaitdbconn.user.promise().query('SELECT id, email FROM user WHERE email = "'+email+'"')
if(rows[0][0]){
returnrows[0][0]
}
else{returnnull}
}catch(err){
console.error(err)
}
returnnull
},
getUserByToken:asyncfunction(token:any){
try{
letrows:any=awaitdbconn.user.promise().query('SELECT t1.user_id, t2.email FROM userdb.credential AS t1 INNER JOIN userdb.user AS t2 ON t1.user_id = t2.id AND t1.resetPasswordToken = "'
+token+'" and resetPasswordExpires > '+Date.now())
thisconn.query('UPDATE user SET ? WHERE id ='+userData.id,userData,function(err:any,rows:any,fields:any){
if(err){
returnthisconn.rollback(function(){throwerr})
}
// delete verification token
thisconn.query('DELETE FROM verification WHERE user_id = '+userData.id,function(err:any,rows:any,fields:any){
if(err){
returnthisconn.rollback(function(){throwerr})
}
// COMMIT
thisconn.commit(function(err:any){
if(err){
returnthisconn.rollback(function(){throwerr})
}
})
thisconn.query('INSERT INTO user_project_role SET ?',projectRoleData,function(err:any,results:any,fields:any){
if(err){
returnthisconn.rollback(function(){
throwerr
})
}
// MLAB-129: INSERT verification token
constverificationData:any={
user_id:newUserId,
token:data.verificationToken
}
thisconn.query('INSERT INTO verification SET ?',verificationData,function(err:any,results:any,fields:any){
if(err){
returnthisconn.rollback(function(){
throwerr
})
}
// COMMIT
thisconn.commit(function(err:any){
if(err){
returnthisconn.rollback(function(){
throwerr
})
}
})
})
})
callback(err)
})
})
},
/* ===== GitLab ===== */
getGitlabId:asyncfunction(userId:number){
try{
letrows:any=awaitdbconn.user.promise().query('SELECT gu.gitlab_userId FROM user_gitlab gu, user u WHERE u.id = "'+userId+'" and gu.user_id = u.id')
if(rows[0][0]){
returnrows[0][0].gitlab_userId
}else{
returnnull
})
callback(err)
})
},
getUserByEmail:asyncfunction(email:any){
try{
constrows:any=awaitdbconn.user.promise().query('SELECT id, verificationStatus, salutation, title, firstname, lastname, industry, organisation, speciality, m4lab_idp FROM user WHERE email = "'+email+'"')
if(rows[0][0]){
returnrows[0][0]
}else{returnnull}
}catch(err){
console.error(err)
}
returnnull
},
getUserEmailById:asyncfunction(userId:number){
try{
constrows:any=awaitdbconn.user.promise().query('SELECT email FROM user WHERE id = '+userId)
if(rows[0][0]){
returnrows[0][0].email
}else{returnnull}
}catch(err){
console.error(err)
}
returnnull
},
checkUserEmail:asyncfunction(email:any){
try{
constrows:any=awaitdbconn.user.promise().query('SELECT id, email FROM user WHERE email = "'+email+'"')
if(rows[0][0]){
returnrows[0][0]
}else{returnnull}
}catch(err){
console.error(err)
}
returnnull
},
getUserByToken:asyncfunction(token:any){
try{
constrows:any=awaitdbconn.user.promise().query('SELECT t1.user_id, t2.email FROM userdb.credential AS t1 INNER JOIN userdb.user AS t2 ON t1.user_id = t2.id AND t1.resetPasswordToken = "'+
varmenu=[{'name':'Informationen','combos':[{'name':'Projekte','link':'/project'},{'name':'Über das M4_LAB','link':'/projectoverview?projectID=1'},{'name':'Kontakt','link':'/account/contact'}],'type':'dropdown','link':'#'},{'name':'Zusammenarbeit','combos':[{'name':'Mailinglisten','link':'/mailinglists'},{'name':'Videokonferenzen','link':'/videoconference.html'},/* {'name':'...', 'link':'#'}*/],'type':'dropdown','link':'#'},{'name':'Events','combos':[{'name':'Veranstaltungen der HfT','link':'http://www.hft-stuttgart.de/Aktuell/Veranstaltungen/'},{'name':'Veranstaltungen der HfT Forschung','link':'https://www.hft-stuttgart.de/forschung/veranstaltungen'}],'type':'dropdown','link':'#'},{'name':'Benutzerkonto','combos':[],'type':'','link':'/account/'}];
constmenu=[{name:'Informationen',combos:[{name:'Projekte',link:'/project'},{name:'Über das M4_LAB',link:'/projectoverview?projectID=1'},{name:'Kontakt',link:'/account/contact'}],type:'dropdown',link:'#'},{name:'Zusammenarbeit',combos:[{name:'Mailinglisten',link:'/mailinglists'},{name:'Videokonferenzen',link:'/videoconference.html'}/* {'name':'...', 'link':'#'}*/],type:'dropdown',link:'#'},{name:'Events',combos:[{name:'Veranstaltungen der HfT',link:'http://www.hft-stuttgart.de/Aktuell/Veranstaltungen/'},{name:'Veranstaltungen der HfT Forschung',link:'https://www.hft-stuttgart.de/forschung/veranstaltungen'}],type:'dropdown',link:'#'},{name:'Benutzerkonto',combos:[],type:'',link:'/account/'}]