Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

existed user checking #17

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,14 @@ output/
web/uploads/
web/provenance-templates/*.json
web/templates/read-potential-cases-gstt.py

web/views/analytics.pug

!requirements.txt
!README.txt
!logo.png
!architecture.png

web/env/
web/nenv/
generator/env/
Empty file added web/db.dev.sqlite;
Empty file.
Empty file added web/db.test.sqlite;
Empty file.
41 changes: 41 additions & 0 deletions web/migrations/1-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var Sequelize = require('sequelize');
* createTable "implementations", deps: [steps]
* createTable "inputs", deps: [steps]
* createTable "outputs", deps: [steps]
* createTable "questionnaires", deps: [steps]
* addIndex ["language","stepId"] to table "implementations"
* addIndex ["stepId"] to table "inputs"
* addIndex ["stepId"] to table "outputs"
Expand Down Expand Up @@ -355,6 +356,43 @@ var migrationCommands = [{
{}
]
},
{
fn: "createTable",
params: [
"questionnaires",
{
"id": {
"type": Sequelize.INTEGER,
"field": "id",
"autoIncrement": true,
"primaryKey": true,
"allowNull": false
},
"username": {
"type": Sequelize.STRING,
"field": "username",
"allowNull": true
},
"answers": {
"type": Sequelize.STRING,
"field": "answers",
"allowNull": true
},
"createdAt": {
"type": Sequelize.DATE,
"field": "createdAt",
"allowNull": true
},
"updatedAt": {
"type": Sequelize.DATE,
"field": "updatedAt",
"allowNull": true
}

},
{}
]
},
{
fn: "addIndex",
params: [
Expand Down Expand Up @@ -445,3 +483,6 @@ module.exports = {
},
info: info
};



35 changes: 34 additions & 1 deletion web/migrations/_current.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,40 @@
}
},
"indexes": []
},
"questionnaires": {
"tableName": "questionnaire",
"schema": {
"id": {
"allowNull": false,
"primaryKey": true,
"autoIncrement": true,
"field": "id",
"seqType": "Sequelize.INTEGER"
},
"username": {
"field": "username",
"seqType": "Sequelize.STRING",
"allowNull": true
},
"answers": {
"field": "answers",
"seqType": "Sequelize.STRING",
"allowNull": true
},
"createdAt": {
"allowNull": true,
"field": "createdAt",
"seqType": "Sequelize.DATE"
},
"updatedAt": {
"allowNull": true,
"field": "updatedAt",
"seqType": "Sequelize.DATE"
}
},
"indexes": []
}
},
"revision": 1
}
}
23 changes: 23 additions & 0 deletions web/models/questionnaire.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
module.exports = function(sequelize, DataTypes) {

var questionnaire = sequelize.define('questionnaire', {
username: DataTypes.STRING,
answers: DataTypes.STRING,
createdAt: {
type: DataTypes.DATE,
defaultValue: false
},
updatedAt: {
type: DataTypes.DATE,
defaultValue: false
}
});

// questionnaire.associate = function(models) {
// questionnaire.belongsTo(models.user, {onDelete:"CASCADE", foreignKey:{allowNull: false}});
// };

return questionnaire;

};
Empty file modified web/proxy/certs/gen-domain-cert.sh
100644 → 100755
Empty file.
Binary file removed web/public/images/favicon.ico
Binary file not shown.
23 changes: 23 additions & 0 deletions web/public/javascripts/sendquestionnaire.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

function sendquestionnaire() {

let form = document.querySelector('#questionnaireform');
let formdata = new FormData(form);
let data={}

for (var [key, value] of formdata.entries()) {
data[key] = value
}

let url="phenotype/questionnaire/postquestionnaire"
let datajsons=JSON.stringify(data)
let callback=function(response){
//console.log("posted"+response)
}

sendPostRequest(url, datajsons, callback, contentType='application/json')

window.close();

}

83 changes: 83 additions & 0 deletions web/public/stylesheets/questionnairestyle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
html, body {
min-height: 100%;
background-color: #f5f6fc;
font-family: 'Poppins', sans-serif!important;
}
body, div, form, input, p {
padding: 0;
margin: 0;
outline: none;
font-family: Roboto, Arial, sans-serif;
font-size: 16px;
color: #666;
line-height: 28px;
}
h1 {
font-weight: 400;
}
h4 {
margin: 25px 0 5px;
}
.testbox {
display: flex;
justify-content: center;
align-items: center;
height: inherit;
padding-left: 30px;
padding-right: 30px;
padding-top: 30px;
padding-bottom: 5px;
background-color: #17a2b8!important;
}
form {
width: 100%;
padding: 20px;
background: #f5f6fc;
box-shadow: 0 2px 5px #ccc;
}
input {
width: auto;
margin-right: 15px;
vertical-align: middle;
}
.question-answer label {
display: block;
}
textarea {
width: calc(100% - 12px);
padding: 5px;
}
textarea:hover {
outline: none;
border: 1px solid #095484;
}
.btn-block {
display: flex;
justify-content: center;
align-items: center;
height: inherit;
/* padding: 30px; */
background-color: #17a2b8!important;
/* margin-top: 20px; */
text-align: center;
}
button {
width: 150px;
padding: 10px;
border: none;
outline: none;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
background-color: #0e7e8f;
font-size: 16px;
color: #fff;
cursor: pointer;
}
button:hover {
background-color: #0a6b7a;
}
input:hover, select:hover, textarea:hover {
outline: none;
box-shadow: 0 0 5px 0 #095484;
}
5 changes: 5 additions & 0 deletions web/routes/step.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ router.post('/:workflowId/:position', jwt({secret:config.get("jwt.RSA_PRIVATE_KE
return res.status(500).send(error);
}
if(!(workflow.userName==req.user.sub)) return res.sendStatus(500);

//checking step name
let exitstep = await models.step.findOne({where:{name:sanitizeHtml(req.body.name)}});
if(!exitstep) return res.sendStatus(500).send("duplicated step name");

await models.step.upsert({name:sanitizeHtml(req.body.name), doc: sanitizeHtml(req.body.doc), type:sanitizeHtml(req.body.type), workflowId:req.params.workflowId, position:req.params.position});
let stepId = await models.step.findOne({where:{workflowId:req.params.workflowId, position:req.params.position}});
await Workflow.workflowComplete(workflow.id);
Expand Down
108 changes: 108 additions & 0 deletions web/routes/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const sanitizeHtml = require('sanitize-html');
const jwt = require('express-jwt');
const Workflow = require("../util/workflow");
const Download = require("../util/download");
const bcrypt = require("bcrypt");

function processOffset(offsetParam) {

Expand Down Expand Up @@ -90,10 +91,117 @@ router.get("/download/:workflowId", async function(req, res, next) {

});


//added questionnaire
router.get("/questionnaire", async function(req, res, next) {
try {
res.render("questionnaire", {title:"Questionnaire"});
}catch(error) {
logger.error("Get workflow error: " + error);
res.sendStatus(500);
}
});

router.post("/questionnaire/postquestionnaire", async function(req, res, next) {

try {

//let user = await models.user.findOne({where:{name: workflow.userName}});
let user="yuleifan"
if(user == null){
user = ''
}
console.log(req.body)

let questionnaire = await models.questionnaire.create(
{
username:user,
answers:JSON.stringify(req.body)
}
);

console.log("inserted")
res.send({"id":questionnaire.id});
console.log(questionnaire.id)


} catch(error) {
console.log(error)
error = "Error adding workflow: " + (error&&error.errors&&error.errors[0]&&error.errors[0].message?error.errors[0].message:error);
logger.debug(error);
res.status(500).send(error);
}

});


//added registration
router.get("/registration", async function(req, res, next) {
try {
res.render("registration", {title:"Registration",existuser:"new user"});
}catch(error) {
logger.error("Get workflow error: " + error);
res.sendStatus(500);
}
});

router.get("/registrationok", async function(req, res, next) {
try {
res.render("registrationok", {title:"Registration",existuser:" Successfully"});
}catch(error) {
logger.error("Get workflow error: " + error);
res.sendStatus(500);
}
});

router.post("/registration/postregistration", async function(req, res, next) {
//insert database
console.log(req.body)

const password = req.body.password1
const rounds = 10

bcrypt.hash(password, rounds, async (err, hash) => {
if (err) {
console.error(err)
return
}
console.log(hash)

try {
let newuser = await models.user.create(
{
name:req.body.email,
password:hash
}
);
//console.log("inserted")
res.send({"name":newuser.name});
//console.log(newuser.name)

} catch (error) {
//console.log("not inserted")
res.send({"name":"exited"});
}


//res.render("registration", {existuser:"Successfully"});

})

//res.redirect('/phenoflow/phenotype/define')//not work


});

router.post("/new", jwt({secret:config.get("jwt.RSA_PRIVATE_KEY"), algorithms:['RS256']}), async function(req, res, next) {

if(!req.body.name || !req.body.about || !req.body.userName) return res.sendStatus(500);
try {
//checking workflow name
let exitworkflow = await models.workflow.findOne({where:{name:sanitizeHtml(req.body.name)}});
if(!exitworkflow) return res.sendStatus(500).send("duplicated workflow name");

let workflow = await models.workflow.create({name:sanitizeHtml(req.body.name), about:sanitizeHtml(req.body.about), userName:sanitizeHtml(req.body.userName)});
res.send({"id":workflow.id});
} catch(error) {
Expand Down
1 change: 0 additions & 1 deletion web/test/implementation/js/covid19/omop/ohdsi
Submodule ohdsi deleted from 0b7f81
Loading