Commit 25fc154a authored by Wolfgang Knopki's avatar Wolfgang Knopki
Browse files

Merge branch 'prepare_prod' into 'master'

merge testing

See merge request !112
parents fe1cf482 208280eb
Pipeline #4835 passed with stage
in 10 seconds
/built
/routes/cert
/node_modules
sp-account-metadata.xml
.idea
deploy-testing:
stage: deploy
script:
- cat $configfiledev > ./config/config.js
- cat $cert > ./routes/cert/cert.pem
- cat $certidp > ./routes/cert/cert_idp.pem
- cat $key > ./routes/cert/key.pem
- npm install
- npm run clean
- npm run build
- rm -rf ./built/public/default
- rm -rf ./built/routes/cert
- rm -rf ./built/views
- cp -R ./public/default ./built/public
- cp -R ./routes/cert ./built/routes
- cp -R ./views ./built
- cat $configfiledev > ./built/config/config.js
- cat $cert > ./built/routes/cert/cert.pem
- cat $certidp > ./built/routes/cert/cert_idp.pem
- cat $key > ./built/routes/cert/key.pem
- "pm2 delete --silent account || :"
- pm2 start ./app.js --name=account
- pm2 start ./built/app.js --name=account
- pm2 save
tags:
- testing
......@@ -17,15 +25,23 @@ deploy-testing:
deploy-master:
stage: deploy
script:
- cat $configfileprod > ./config/config.js
- cat $cert > ./routes/cert/cert.pem
- cat $certidp > ./routes/cert/cert_idp.pem
- cat $key > ./routes/cert/key.pem
- npm install
- npm run clean
- npm run build
- rm -rf ./built/public/default
- rm -rf ./built/routes/cert
- rm -rf ./built/views
- cp -R ./public/default ./built/public
- cp -R ./routes/cert ./built/routes
- cp -R ./views ./built
- cat $configfiledev > ./built/config/config.js
- cat $cert > ./built/routes/cert/cert.pem
- cat $certidp > ./built/routes/cert/cert_idp.pem
- cat $key > ./built/routes/cert/key.pem
- "pm2 delete --silent account || :"
- pm2 start ./app.js --name=account
- pm2 start ./built/app.js --name=account
- pm2 save
tags:
- production
only:
- master
\ No newline at end of file
- master
const gitlab = require('../functions/gitlab')
import gitlab from '../functions/gitlab'
//const axios = require('axios')
//jest.mock('axios')
......
const methods = require('../functions/methods')
import methods from '../functions/methods'
describe("DB methohds test", () => {
......@@ -49,4 +49,4 @@ describe("DB methohds test", () => {
expect(user).toBeNull()
})
})
})
\ No newline at end of file
const express = require('express');
const http = require('http');
const path = require('path');
const passport = require('passport');
const morgan = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('express-session');
const errorhandler = require('errorhandler');
const flash = require('express-flash-2');
const fileUpload = require('express-fileupload');
const helmet = require('helmet');
const compression = require('compression');
const methodOverride = require('method-override');
import express from 'express';
import path from 'path';
import passport from 'passport';
import morgan from 'morgan';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import session from 'express-session';
import flash from 'express-flash-2';
import fileUpload from 'express-fileupload';
import helmet from 'helmet';
import compression from 'compression';
import methodOverride from 'method-override';
import dotenv from 'dotenv'
dotenv.config();
var env = process.env.NODE_ENV || 'testing';
const config = require('./config/config')[env];
const lang = 'DE';
var app = express();
app.set('port', config.app.port);
app.set('views', __dirname + '/views');
app.set('views', path.join( __dirname + '/views'));
app.set('view engine', 'pug');
// enable files upload
......@@ -30,12 +30,25 @@ app.use(fileUpload({
fileSize: 1000000 // 1 MB max. file size
}
}));
app.use(methodOverride('_method'));
app.use(helmet());
app.use(
helmet.contentSecurityPolicy({
useDefaults: true,
directives: {
"font-src": ["'self'", "https://use.fontawesome.com"],
"img-src": ["'self'", "https://transfer.hft-stuttgart.de"],
"script-src": ["'self'", "https://code.jquery.com/jquery-3.3.1.min.js", "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js",
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js", "https://unpkg.com/bootstrap-show-password@1.2.1/dist/bootstrap-show-password.min.js"],
"style-src": ["'self'", "https://use.fontawesome.com/releases/v5.8.2/css/all.css"],
"frame-src": ["'self'"]
},
reportOnly: true,
})
);
app.use(compression());
app.use(morgan('combined'));
app.use(cookieParser());
app.use(cookieParser(config.app.sessionSecret));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
......@@ -43,13 +56,11 @@ app.use((req, res, next) => {
next();
});
app.use(session(
{
resave: true,
saveUninitialized: true,
secret: config.app.sessionSecret
}
));
app.use(session({
resave: true,
saveUninitialized: true,
secret: config.app.sessionSecret
}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
......@@ -61,16 +72,16 @@ app.use(function(req, res, next) {
next();
});
require('./routes/account')(app, config, passport, lang);
require('./routes/public')(app, config, lang);
require('./routes/account')(app, config, passport, lang);
// Handle 404
app.use(function (req, res) {
app.use(function (req:any, res:any) {
res.status(404).render(lang+'/404')
})
// Handle 500 - any server error
app.use(function (err, req, res, next) {
app.use(function (err:any, req:any, res:any, next:any) {
console.error(err.stack)
res.status(500).render(lang+'/500', {
error: err
......
class Project {
constructor(ownerGitlabId, id, name, desc, logo, path) {
ownerGitlabId:number
name:string
desc:string
id?:number
logo?:string
path?:string
constructor(ownerGitlabId:number, name:string, desc:string, id?:number, logo?:string, path?:string) {
this.ownerGitlabId = ownerGitlabId
this.id = id
this.name = name
this.desc = desc
this.id = id
this.logo = logo
this.path = path
}
......@@ -28,24 +35,24 @@ class Project {
return this.path
}
// setter
setOwnerGitlabId(newOwnerGitlabId){
setOwnerGitlabId(newOwnerGitlabId:number){
this.ownerGitlabId = newOwnerGitlabId
}
setId(newId) {
setId(newId:number) {
this.id = newId
}
setName(newName) {
setName(newName:string) {
this.name = newName
}
setDesc(newDesc) {
setDesc(newDesc:string) {
this.desc = newDesc
}
setLogo(newLogoUrl) {
setLogo(newLogoUrl:string) {
this.logo = newLogoUrl
}
setPath(newPath) {
setPath(newPath:string) {
this.path = newPath
}
}
module.exports = Project
\ No newline at end of file
export = Project
\ No newline at end of file
const Project = require("./project");
class Repo extends Project {
constructor(ownerGitlabId, id, name, desc, logo, path) {
super(ownerGitlabId, id, name, desc, logo, path)
}
}
module.exports = Repo
\ No newline at end of file
import Project from "./project"
class Repo extends Project {
constructor(ownerGitlabId:number, name:string, desc:string, id?:number, logo?:string, path?:string) {
super(ownerGitlabId, name, desc, id, logo, path)
}
}
export = Repo
\ No newline at end of file
class User {
constructor(id, email, salutation, title, firstName, lastName, industry, organisation, speciality, is_m4lab_idp, gitlabUserId, verificationStatus) {
this.id = id
this.email = email
this.salutation = salutation
this.title = title
this.firstName = firstName
this.lastName = lastName
this.industry = industry
this.organisation = organisation
this.speciality = speciality
this.is_m4lab_idp = is_m4lab_idp // 1 or 0
this.gitlabUserId = gitlabUserId
this.verificationStatus = verificationStatus
id:number
email:string
salutation:string // should be enum
title:string // should be enum
firstName:string
lastName:string
industry:string
organisation:string
speciality:string
is_m4lab_idp:number // 1 or 0
verificationStatus:number // 1 or 0 - // should be boolean
gitlabUserId?:number
constructor(id:number, email:string, salutation:string, title:string, firstName:string, lastName:string, industry:string, organisation:string,
speciality:string, is_m4lab_idp:number, verificationStatus:number, gitlabUserId?:number) {
this.id = id
this.email = email
this.salutation = salutation
this.title = title
this.firstName = firstName
this.lastName = lastName
this.industry = industry
this.organisation = organisation
this.speciality = speciality
this.is_m4lab_idp = is_m4lab_idp
this.verificationStatus = verificationStatus
this.gitlabUserId = gitlabUserId
}
// getter
......@@ -27,48 +41,48 @@ class User {
getIdpStatus() {
return this.is_m4lab_idp
}
getGitlabUserId() {
return this.gitlabUserId
}
getVerificationStatus() {
return this.verificationStatus
}
getGitlabUserId() {
return this.gitlabUserId
}
// setter
setEmail(email) {
setEmail(email:string) {
this.email = email
}
setSalutation(salutation) {
setSalutation(salutation:string) {
this.salutation = salutation
}
setTitle(title) {
setTitle(title:string) {
this.title = title
}
setFirstName(firstName) {
setFirstName(firstName:string) {
this.firstName = firstName
}
setLastName(lastName) {
setLastName(lastName:string) {
this.lastName = lastName
}
setIndustry(industry) {
setIndustry(industry:string) {
this.industry = industry
}
setOrganisation(organisation) {
setOrganisation(organisation:string) {
this.organisation = organisation
}
setSpeciality(speciality) {
setSpeciality(speciality:string) {
this.speciality = speciality
}
setM4lab_idp(m4lab_idp) {
this.m4lab_idp = m4lab_idp
}
setGitlabUserId(newGitlabUserId) {
this.gitlabUserId = newGitlabUserId
setM4lab_idp(m4lab_idp:number) {
this.is_m4lab_idp = m4lab_idp
}
setVerificationStatus(verificationStatus) {
setVerificationStatus(verificationStatus:number) {
this.verificationStatus = verificationStatus
}
setGitlabUserId(newGitlabUserId:number) {
this.gitlabUserId = newGitlabUserId
}
updateProfile(newSalutation, newTitle, newFirstname, newLastname, newEmail, newOrganisation, newIndustry, newSpeciality) {
updateProfile(newSalutation:string, newTitle:string, newFirstname:string, newLastname:string, newEmail:string, newOrganisation:string, newIndustry:string, newSpeciality:string) {
this.salutation = newSalutation
this.title = newTitle
this.firstName = newFirstname
......@@ -80,4 +94,4 @@ class User {
}
}
module.exports = User
\ No newline at end of file
export = User
\ No newline at end of file
const Project = require("./project");
class Website extends Project {
constructor(ownerGitlabId, id, name, desc, logo, path) {
super(ownerGitlabId, id, name, desc, logo, path)
}
}
module.exports = Website
\ No newline at end of file
import Project from "./project"
class Website extends Project {
constructor(ownerGitlabId:number, name:string, desc:string, id?:number, logo?:string, path?:string) {
super(ownerGitlabId, name, desc, id, logo, path)
}
}
export = Website
\ No newline at end of file
module.exports = {
export = {
development: {
app: {
name: 'User Account Management',
......@@ -28,7 +28,7 @@ module.exports = {
host: 'mailhost', // hostname
secureConnection: false, // TLS requires secureConnection to be false
port: 587, // port for secure SMTP
TLS: true, // sets requireTLS
TLS: true,
authUser: 'mailuser',
authPass: 'mailpass',
tlsCiphers: 'SSLv3',
......@@ -67,7 +67,7 @@ module.exports = {
host: 'mailhost', // hostname
secureConnection: false, // TLS requires secureConnection to be false
port: 587, // port for secure SMTP
TLS: true, // sets requireTLS
TLS: true,
authUser: 'mailuser',
authPass: 'mailpass',
tlsCiphers: 'SSLv3',
......@@ -77,4 +77,4 @@ module.exports = {
token_readWriteProjects: 'token-goes-here'
}
}
}
}
\ No newline at end of file
module.exports = {
export = {
mailSignature: 'Mit den besten Grüßen,<br/>das Transferportal-Team der HFT Stuttgart<br/><br/>' +
'Transferportal der Hochschule für Technik Stuttgart<br/>' +
......
const mysql = require('mysql')
import mysql from 'mysql2'
var env = process.env.NODE_ENV || 'testing';
var env = process.env.NODE_ENV || 'testing'
const config = require('./config')[env]
// ==== USER ACOOUNT DB CONNECTION ====
......@@ -14,7 +14,7 @@ var userConnection = mysql.createConnection({
})
userConnection.connect(function(err) {
if (err) throw err;
if (err) throw err
})
userConnection.query('USE '+config.database.dbUser)
......@@ -52,7 +52,7 @@ var projectConnection = mysql.createConnection({
})
projectConnection.connect(function(err) {
if (err) throw err;
if (err) throw err
})
projectConnection.query('USE '+config.database.dbProject)
......@@ -61,4 +61,4 @@ var connection = {
project: projectConnection
}
module.exports = connection
\ No newline at end of file
export = connection
\ No newline at end of file
const mysql = require('mysql2')
var env = process.env.NODE_ENV || 'testing';
const config = require('./config')[env]
// ==== USER ACOOUNT DB CONNECTION ====
var userConnection = mysql.createConnection({
host: config.database.host,
user: config.database.user,
password: config.database.password,
port: config.database.port,
database: config.database.dbUser,
multipleStatements: true
})
userConnection.connect(function(err) {
if (err) throw err;
})
userConnection.query('USE '+config.database.dbUser)
// ALTERNATIVE approach: close db connection manually after every query
/*
var dbconn = function dbconn(query, values, next) {
var connection = mysql.createConnection({
host: config.database.host,
user: config.database.user,
password: config.database.password,
port: config.database.port,
database: config.database.db
})
connection.connect(function(err) {
if (err) throw err;
})
connection.query(query, values, function(err) {
connection.end(); // close the connection
if (err) {
throw err;
}
// Execute the callback
next.apply(this, arguments);
});
}
*/
// ==== PROJECT DB CONNECTION ====
var projectConnection = mysql.createConnection({
host: config.database.host_project,
user: config.database.user,
password: config.database.password,
port: config.database.port,
database: config.database.dbProject
})
projectConnection.connect(function(err) {
if (err) throw err;
})
projectConnection.query('USE '+config.database.dbProject)
var connection = {
user: userConnection,
project: projectConnection
}
module.exports = connection
\ No newline at end of file
const nodemailer = require('nodemailer');
const nodemailerNTLMAuth = require('nodemailer-ntlm-auth');
var env = process.env.NODE_ENV || 'testing';
const config = require('./config')[env]
var smtpTransport = nodemailer.createTransport({
host: config.mailer.host,
secure: config.mailer.secureConnection,
port: config.mailer.port,
requireTLS: config.mailer.TLS,
auth: {
type: 'custom',
method: 'NTLM',
user: config.mailer.authUser,
pass: config.mailer.authPass,
options: {
domain: 'ad'
}
},
customAuth:{
NTLM: nodemailerNTLMAuth
}
});
var mailOptions = {
to: "",
from: config.mailer.from,
subject: "",
text: ""
};
var mailer = {
transport: smtpTransport,
options: mailOptions
}
module.exports = mailer
const nodemailer = require('nodemailer')
const nodemailerNTLMAuth = require('nodemailer-ntlm-auth')
var env = process.env.NODE_ENV || 'testing'
const config = require('./config')[env]
var smtpTransporter = nodemailer.createTransport({
host: config.mailer.host,
secure: config.mailer.secureConnection,
port: config.mailer.port,
requireTLS: config.mailer.TLS,
auth: {
type: 'custom',
method: 'NTLM',
user: config.mailer.authUser,
pass: config.mailer.authPass,
options: {
domain: 'ad'
}
},
customAuth:{
NTLM: nodemailerNTLMAuth
}
});
var mailOptions:any = {
to: "",
cc: "",
from: config.mailer.from,
subject: "",
text: "",
html: ""
}
var mailer:any = {
transporter: smtpTransporter,
options: mailOptions
}
export = mailer
\ No newline at end of file
import axios from 'axios'
import fs from 'fs'
import formData from 'form-data'
var env = process.env.NODE_ENV || 'testing'
const config = require('../config/config')[env]
const axios = require('axios')
const fs = require('fs')
var formData = require('form-data')
var gitlab = {
// todo: GraphQL currentUser
getUserByEmail: async function(email) {
getUserByEmail: async function(email:string) {
return axios({
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/users?search='+email,
......@@ -15,9 +14,12 @@ var gitlab = {
'Authorization': 'Bearer '+config.gitlab.token_readWriteProjects}
})
.then(res => res.data[0])
.catch(err => console.error(err))
.catch(function(err){
console.error(err)
return null
})
},
createNewPages: async function(newPagesData, newLogoFile, template) {
createNewPages: async function(newPagesData:any, newLogoFile:string, template:any) {
let data = new formData()
data.append('avatar', fs.createReadStream(newLogoFile))
......@@ -32,16 +34,15 @@ var gitlab = {
},
data: data
})
.then(res => res = {
error: false,
data: res.data
})
.catch(err => res = {
error: true,
data: err.response.data
.then(res => res.data)
.catch(function(err) {
console.error("ERR Status: "+err.response.status)
console.error("ERR Name: "+err.response.data.message.name)
console.error("ERR Path: "+err.response.data.message.path)
return err.response
})
},
updateProject: async function(updatedProjectData, newLogoFile){
updateProject: async function(updatedProjectData:any, newLogoFile:string){
let data = new formData()
if (newLogoFile) {
data.append('avatar', fs.createReadStream(newLogoFile))
......@@ -57,16 +58,16 @@ var gitlab = {
},
data : data
})
.then(res => res = {
error: false,
data: res.data
})
.catch(err => res = {
error: true,
data: err.response.data
//.then(res => res.data[0])
.then(res => res.data)
.catch(function(err){
console.error("ERR Status: "+err.response.status)
console.error("ERR Name: "+err.response.data.message.name)
console.error("ERR Path: "+err.response.data.message.path)
return err.response
})
},
deleteProjectById: function(projectId){
deleteProjectById: function(projectId:number){
// https://docs.gitlab.com/ee/api/projects.html#delete-project
return axios({
method: 'delete',
......@@ -75,16 +76,15 @@ var gitlab = {
'Authorization': 'Bearer '+config.gitlab.token_readWriteProjects
}
})
.then(res => res = {
error: false,
data: res.data
})
.catch(err => res = {
error: true,
data: err.response.data
.then(res => true)
.catch(function(err) {
console.error("ERR Status: "+err.response.status)
console.error("ERR Name: "+err.response.data.message.name)
console.error("ERR Path: "+err.response.data.message.path)
return false
})
},
getUserProjects: async function(gitlabUserId) {
getUserProjects: async function(gitlabUserId:number) {
return axios({
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/users/'+gitlabUserId+'/projects?owned=true&visibility=public',
......@@ -93,9 +93,12 @@ var gitlab = {
}
})
.then(res => res.data)
.catch(err => console.error(err))
.catch(function(err) {
console.error(err)
return null
})
},
getProjectById: async function(projectId) {
getProjectById: async function(projectId:number) {
return axios({
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/'+projectId,
......@@ -104,45 +107,22 @@ var gitlab = {
}
})
.then(res => res.data)
.catch(err => console.error(err.response.status))
.catch(function(err) {
console.error(err)
return null
})
},
getProjectPipelineLatestStatus: async function(projectId) {
getProjectPipelineLatestStatus: async function(projectId:number) {
return axios({
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/'+projectId+'/pipelines'
})
.then(res => res.data[0].status)
.catch(err => console.error(err))
},
//
// test GraphQL
getGraphqlTest: function(callback) {
axios({
url: 'https://gitlab.com/api/graphql',
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer '+config.gitlab.token_readWriteProjects
},
data: {
query: `{
currentUser {
id
username
}
}`
/* query: `{
projects {
nodes {
id
}
}
}` */
}
}).then((result) => {
console.log(JSON.stringify(result.data))
});
.catch(function(err) {
console.error(err)
return null
})
}
}
module.exports = gitlab
\ No newline at end of file
export = gitlab
\ No newline at end of file
var helpers = {
stringToArray: function (input){
stringToArray: function (input:string){
if(input != null){
return input.split(',');
}else{
......@@ -8,4 +8,4 @@ var helpers = {
}
};
module.exports = helpers;
\ No newline at end of file
export = helpers;
\ No newline at end of file
const dbconn_OBSOLETE = require('../config/dbconn') // DO NOT USE THIS FOR NEW FUNCTIONS
const dbconn = require('../config/dbconn2')
import dbconn = require('../config/dbconn')
var methods = {
// ===================== user db =====================
registerNewUser: function(data, callback) {
dbconn_OBSOLETE.user.beginTransaction(function(err) { // START TRANSACTION
if (err) {
throw err
}
registerNewUser: function(data:any, callback:any) {
dbconn.user.beginTransaction(function(err:any) { // START TRANSACTION
if (err) { throw err }
// insert profile
dbconn_OBSOLETE.user.query('INSERT INTO user SET ?', data.profile, function (err, results, fields) {
dbconn.user.query('INSERT INTO user SET ?', data.profile, function (err:any, results:any, fields:any) {
if (err) {
return dbconn_OBSOLETE.user.rollback(function() {
return dbconn.user.rollback(function() {
throw err
});
}
var newUserId = results.insertId
let newUserId:number = results.insertId
// set password
var credentialData = {
var credentialData:any = {
user_id: newUserId,
password: data.password
}
dbconn_OBSOLETE.user.query('INSERT INTO credential SET ?', credentialData, function (err, results, fields) {
dbconn.user.query('INSERT INTO credential SET ?', credentialData, function (err:any, results:any, fields:any) {
if (err) {
return dbconn_OBSOLETE.user.rollback(function() {
return dbconn.user.rollback(function() {
throw err
});
}
// set default user-project-role
var projectRoleData = {
var projectRoleData:any = {
project_id: 1, //M4_LAB
role_id: 2, // USER
user_id: newUserId
}
dbconn_OBSOLETE.user.query('INSERT INTO user_project_role SET ?', projectRoleData, function (err, results, fields) {
dbconn.user.query('INSERT INTO user_project_role SET ?', projectRoleData, function (err:any, results:any, fields:any) {
if (err) {
return dbconn_OBSOLETE.user.rollback(function() {
return dbconn.user.rollback(function() {
throw err
});
}
// MLAB-129: INSERT verification token
let verificationData = {
let verificationData:any = {
user_id: newUserId,
token: data.verificationToken
}
dbconn_OBSOLETE.user.query('INSERT INTO verification SET ?', verificationData, function (err, results, fields) {
dbconn.user.query('INSERT INTO verification SET ?', verificationData, function (err:any, results:any, fields:any) {
if (err) {
return dbconn_OBSOLETE.user.rollback(function() {
return dbconn.user.rollback(function() {
throw err
});
}
// COMMIT
dbconn_OBSOLETE.user.commit(function(err) {
dbconn.user.commit(function(err:any) {
if (err) {
return dbconn_OBSOLETE.user.rollback(function() {
return dbconn.user.rollback(function() {
throw err
})
}
......@@ -65,9 +62,9 @@ var methods = {
callback(err)
})
},
getUserByEmail: async function(email) {
getUserByEmail: async function(email:any) {
try {
let rows = await dbconn.user.promise().query('SELECT id, verificationStatus, salutation, title, firstname, lastname, industry, organisation, speciality, m4lab_idp FROM user WHERE email = "' +email+'"')
let rows:any = await dbconn.user.promise().query('SELECT id, verificationStatus, salutation, title, firstname, lastname, industry, organisation, speciality, m4lab_idp FROM user WHERE email = "' +email+'"')
if (rows[0][0]) {
return rows[0][0]
}
......@@ -77,9 +74,9 @@ var methods = {
}
return null
},
getUserEmailById: async function(userId) {
getUserEmailById: async function(userId:number) {
try {
let rows = await dbconn.user.promise().query('SELECT email FROM user WHERE id = ' +userId)
let rows:any = await dbconn.user.promise().query('SELECT email FROM user WHERE id = ' +userId)
if (rows[0][0]) {
return rows[0][0].email
}
......@@ -89,9 +86,9 @@ var methods = {
}
return null
},
checkUserEmail: async function(email) {
checkUserEmail: async function(email:any) {
try {
let rows = await dbconn.user.promise().query('SELECT id, email FROM user WHERE email = "' +email+'"')
let rows:any = await dbconn.user.promise().query('SELECT id, email FROM user WHERE email = "' +email+'"')
if (rows[0][0]) {
return rows[0][0]
}
......@@ -101,9 +98,9 @@ var methods = {
}
return null
},
getUserByToken: async function(token) {
getUserByToken: async function(token:any) {
try {
let rows = await dbconn.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 = "'
let rows:any = await dbconn.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())
if (rows[0][0]) {
return rows[0][0]
......@@ -114,47 +111,33 @@ var methods = {
}
return null
},
updateUserById: function(userData, callback) {
dbconn_OBSOLETE.user.query('UPDATE user SET ? WHERE id = ' +userData.id, userData, function (err, rows, fields) {
if (err) throw err
callback(err)
})
},
updateCredential: function(data, callback) {
dbconn_OBSOLETE.user.query('UPDATE credential SET ? WHERE user_id = ' +data.user_id, data, function (err, rows, fields) {
if (err) throw err
callback(err)
})
},
getUserIdByEmail_OBSOLETE: function(email, callback) {
let userId
dbconn_OBSOLETE.user.query('SELECT id FROM user WHERE email = "' +email+'"', function (err, rows, fields) {
if (err) {
throw err
}
else {
if ( rows.length > 0) {
userId = rows[0].id
}
}
callback(userId, err)
});
updateUserById: async function(userId:number, userData:any) {
try {
let result:any = await dbconn.user.promise().query('UPDATE user SET ? WHERE id = ' +userId, userData)
return result
} catch (err) {
console.error(err)
}
return null
},
getUserProjectRole_OBSOLETE: function(userId, callback) {
dbconn_OBSOLETE.user.query('SELECT project_id, role_id FROM user_project_role WHERE user_id = "' +userId+'"', function (err, rows, fields) {
if (err) throw err
callback(rows, err)
});
updateCredential: async function(data:any) {
try {
let result:any = await dbconn.user.promise().query('UPDATE credential SET ? WHERE user_id = ' +data.user_id, data)
return result
} catch (err) {
console.error(err)
}
return null
},
addUserProjectRole: function(data, callback) {
dbconn_OBSOLETE.user.query('INSERT INTO user_project_role SET ?', data, function (err, results, fields){
addUserProjectRole_OBSOLETE: function(data:any, callback:any) {
dbconn.user.query('INSERT INTO user_project_role SET ?', data, function (err:any){
if (err) throw err
callback(err)
})
},
getVerificationTokenByUserId: async function(userId) {
getVerificationTokenByUserId: async function(userId:number) {
try {
let rows = await dbconn.user.promise().query('SELECT token FROM verification WHERE user_id = "' +userId+'"')
let rows:any = await dbconn.user.promise().query('SELECT token FROM verification WHERE user_id = "' +userId+'"')
if (rows[0][0]) {
return rows[0][0].token
}
......@@ -164,9 +147,9 @@ var methods = {
}
return null
},
getUserIdByVerificationToken: async function(token) {
getUserIdByVerificationToken: async function(token:any) {
try {
let rows = await dbconn.user.promise().query('SELECT user_id FROM verification WHERE token = "' +token+'"')
let rows:any = await dbconn.user.promise().query('SELECT user_id FROM verification WHERE token = "' +token+'"')
if (rows[0][0]) {
return rows[0][0].user_id
}
......@@ -178,23 +161,23 @@ var methods = {
}
return null
},
verifyUserAccount: function(userData, callback) {
dbconn_OBSOLETE.user.beginTransaction(function(err) { // START TRANSACTION
verifyUserAccount: function(userData:any, callback:any) {
dbconn.user.beginTransaction(function(err:any) { // START TRANSACTION
if (err) { throw err }
// update user status
dbconn_OBSOLETE.user.query('UPDATE user SET ? WHERE id =' +userData.id, userData, function (err, rows, fields) {
dbconn.user.query('UPDATE user SET ? WHERE id =' +userData.id, userData, function (err:any, rows:any, fields:any) {
if (err) {
return dbconn_OBSOLETE.user.rollback(function() { throw err })
return dbconn.user.rollback(function() { throw err })
}
// delete verification token
dbconn_OBSOLETE.user.query('DELETE FROM verification WHERE user_id = '+userData.id, function (err, rows, fields) {
dbconn.user.query('DELETE FROM verification WHERE user_id = '+userData.id, function (err:any, rows:any, fields:any) {
if (err) {
return dbconn_OBSOLETE.user.rollback(function() { throw err })
return dbconn.user.rollback(function() { throw err })
}
// COMMIT
dbconn_OBSOLETE.user.commit(function(err) {
dbconn.user.commit(function(err:any) {
if (err) {
return dbconn_OBSOLETE.user.rollback(function() { throw err })
return dbconn.user.rollback(function() { throw err })
}
})
})
......@@ -203,9 +186,9 @@ var methods = {
})
},
/* ===== GitLab ===== */
getGitlabId: async function(userId) {
getGitlabId: async function(userId:number) {
try {
let rows = await dbconn.user.promise().query('SELECT gu.gitlab_userId FROM user_gitlab gu, user u WHERE u.id = "' +userId+'" and gu.user_id = u.id')
let rows:any = await dbconn.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]) {
return rows[0][0].gitlab_userId
} else {
......@@ -217,12 +200,12 @@ var methods = {
return err
}
},
addGitlabUser: function(data, callback){
dbconn_OBSOLETE.user.query('INSERT INTO user_gitlab SET ?', data, function (err) {
addGitlabUser: function(data:any, callback:any){
dbconn.user.query('INSERT INTO user_gitlab SET ?', data, function (err:any) {
if (err) throw err
callback(err)
})
}
};
module.exports = methods;
\ No newline at end of file
export = methods
\ No newline at end of file
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