<commit_before>var debug = true;

var application_root = __dirname,
        express = require("express"),
        path = require("path"),
        mongoose = require('mongoose');

var basepath = '/api';

var app = express();
// database
mongoose.connect('mongodb://localhost/scenario');
// config
app.configure(function () {
        app.set('port', process.env.PORT || 3000);
        app.use(express.json());
        app.use(express.urlencoded());
        app.use(express.methodOverride());
        app.use(express.logger('dev'));
        app.use(app.router);
        app.use(express.static(path.join(application_root, "public")));
        app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

// schemas
var Schema = mongoose.Schema;

var Scenario = new Schema({
        scenarioid: { type: String, required: true },
        password: <PASSWORD>
});

var ScenarioProject = new Schema({
        projectid: { type: String, required: true },
        title: String,
        description: String,
        password: <PASSWORD>,
        backgroundurl: String,
        modified: { type: Date, default: Date.now },
        phases: [ {phaseid: String, phasepos: Number} ]
});

var ScenarioPhase = new Schema({
        projectid: { type: String, required: true },
        palette: [ScenarioItem],
        randomizepalette: Boolean,
        palettestyle: String,
        paletteposition: String,
        paletteitemoffset: {x: Number, y: Number},
        oninit: String,
        onsubmit: String
});

var ScenarioItem = new Schema({
        projectid:  { type: String, required: true },
        scenarioid: { type: String, required: true },
        ispaletteitem: Boolean,
        text: String,
        imageurl: String,
        thumbnailurl: String,
        width: { type: Number, default: 200 },
        height: { type: Number, default: 200 },
        imagewidth: { type: Number, default: 200 },
        imageheight: { type: Number, default: 200 },
        posx: { type: Number, default: 0 },
        posy: { type: Number, default: 0 },
        posz: { type: Number, default: 0 },
        rot: { type: Number, default: 0 },
        modified: { type: Date, default: Date.now }
});

var ScenarioModel = mongoose.model('Scenario', Scenario);
var ScenarioProjectModel = mongoose.model('ScenarioProject', ScenarioProject);
var ScenarioPhaseModel = mongoose.model('ScenarioPhase', ScenarioPhase);
var ScenarioItemModel = mongoose.model('ScenarioItem', ScenarioItem);

// check for existence of the api
app.get(basepath, function (req, res) {
        res.send('Scenario API is running');
});

// list scenarioprojects
app.get(basepath + '/projects', function (req, res){
        log_call(req);
        return ScenarioProjectModel.find(function (err, scenarioprojects) {
                if (!err) {
                        //fix: do not return the passwords
                        return res.send(scenarioprojects);
                } else {
                        return console.log(err);
                }
        });
});

// create scenarioproject
app.post(basepath + '/projects', function (req, res){
        log_call(req);
        var scenarioproject = new ScenarioProjectModel({
                projectid: req.body.projectid,
                password: <PASSWORD>,
        });
        scenarioproject.save(function (err) {
                if (!err) {
                        return console.log("created scenarioproject: " + req.body.projectid);
                } else {
                        return console.log(err);
                }
        });
        return res.send(scenarioproject);
});

// list scenarios by project id
app.get(basepath + '/projects/:projectid/scenarios', function (req, res){
        log_call(req);
       return ScenarioModel.find({'projectid' : req.params.projectid}, function (err, scenarios) {
                if (!err) {
                        return res.send(scenarios);
                } else {
                        return console.log(err);
                }
        });
});

// create scenario
app.post(basepath + '/projects/:projectid/scenarios', function (req, res){ //xxx
        log_call(req);
        var scenario = new ScenarioModel({
                projectid: req.body.projectid,
                password: <PASSWORD>
        });
        scenario.save(function (err) {
                if (!err) {
                        return console.log("created: " + req.body.id);
                } else {
                        return console.log(err);
                }
        });
        return res.send(scenario);
});

// login to a scenario by :id
app.post(basepath + '/projects/:projectid/scenarios/:scenarioid/login', function (req, res){ //xxx
        log_call(req);
        return ScenarioModel.find({'scenarioid' : req.params.scenarioid}, function (err, scenario) {
                if (req.body.password == scenario[0].password) {
                        return res.send({'result': 'ok'});
                } else {
                        return res.send({'result': 'failure', 'message': 'wrong password'});
                }
        });
});

// read scenario by :id
app.get(basepath + '/projects/:projectid/scenarios/:scenarioid', function (req, res){ //xxx
        log_call(req);
        return ScenarioModel.find({'scenarioid' : req.params.scenarioid}, function (err, scenario) {
                if (!err) {
                        //fix: return also scenario phases at the same time
                        return res.send(scenario);
                } else {
                        return console.log(err);
                }<commit_msg>removed old login stuff in favour of passport.js<commit_after>var debug = true;

var application_root = __dirname,
        express = require("express"),
        path = require("path"),
        mongoose = require('mongoose');

var basepath = '/api';

var app = express();
// database
mongoose.connect('mongodb://localhost/scenario');
// config
app.configure(function () {
        app.set('port', process.env.PORT || 3000);
        app.use(express.json());
        app.use(express.urlencoded());
        app.use(express.methodOverride());
        app.use(express.logger('dev'));
        app.use(app.router);
        app.use(express.static(path.join(application_root, "public")));
        app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

// schemas
var Schema = mongoose.Schema;

var Scenario = new Schema({
        scenarioid: { type: String, required: true },
        password: String
});

var ScenarioProject = new Schema({
        projectid: { type: String, required: true },
        title: String,
        description: String,
        password: String,
        backgroundurl: String,
        modified: { type: Date, default: Date.now },
        phases: [ {phaseid: String, phasepos: Number} ]
});

var ScenarioPhase = new Schema({
        projectid: { type: String, required: true },
        palette: [ScenarioItem],
        randomizepalette: Boolean,
        palettestyle: String,
        paletteposition: String,
        paletteitemoffset: {x: Number, y: Number},
        oninit: String,
        onsubmit: String
});

var ScenarioItem = new Schema({
        projectid:  { type: String, required: true },
        scenarioid: { type: String, required: true },
        ispaletteitem: Boolean,
        text: String,
        imageurl: String,
        thumbnailurl: String,
        width: { type: Number, default: 200 },
        height: { type: Number, default: 200 },
        imagewidth: { type: Number, default: 200 },
        imageheight: { type: Number, default: 200 },
        posx: { type: Number, default: 0 },
        posy: { type: Number, default: 0 },
        posz: { type: Number, default: 0 },
        rot: { type: Number, default: 0 },
        modified: { type: Date, default: Date.now }
});

var ScenarioModel = mongoose.model('Scenario', Scenario);
var ScenarioProjectModel = mongoose.model('ScenarioProject', ScenarioProject);
var ScenarioPhaseModel = mongoose.model('ScenarioPhase', ScenarioPhase);
var ScenarioItemModel = mongoose.model('ScenarioItem', ScenarioItem);

// check for existence of the api
app.get(basepath, function (req, res) {
        res.send('Scenario API is running');
});

// list scenarioprojects
app.get(basepath + '/projects', function (req, res){
        log_call(req);
        return ScenarioProjectModel.find(function (err, scenarioprojects) {
                if (!err) {
                        //fix: do not return the passwords
                        return res.send(scenarioprojects);
                } else {
                        return console.log(err);
                }
        });
});

// create scenarioproject
app.post(basepath + '/projects', function (req, res){
        log_call(req);
        var scenarioproject = new ScenarioProjectModel({
                projectid: req.body.projectid,
                password: <PASSWORD>,
        });
        scenarioproject.save(function (err) {
                if (!err) {
                        return console.log("created scenarioproject: " + req.body.projectid);
                } else {
                        return console.log(err);
                }
        });
        return res.send(scenarioproject);
});

// list scenarios by project id
app.get(basepath + '/projects/:projectid/scenarios', function (req, res){
        log_call(req);
       return ScenarioModel.find({'projectid' : req.params.projectid}, function (err, scenarios) {
                if (!err) {
                        return res.send(scenarios);
                } else {
                        return console.log(err);
                }
        });
});

// create scenario
app.post(basepath + '/projects/:projectid/scenarios', function (req, res){ //xxx
        log_call(req);
        var scenario = new ScenarioModel({
                projectid: req.body.projectid,
                password: <PASSWORD>
        });
        scenario.save(function (err) {
                if (!err) {
                        return console.log("created: " + req.body.id);
                } else {
                        return console.log(err);
                }
        });
        return res.send(scenario);
});

// read scenario by :id
app.get(basepath + '/projects/:projectid/scenarios/:scenarioid', function (req, res){ //xxx
        log_call(req);
        return ScenarioModel.find({'scenarioid' : req.params.scenarioid}, function (err, scenario) {
                if (!err) {
                        //fix: return also scenario phases at the same time
                        return res.send(scenario);
                } else {
                        return console.log(err);
                }
{'fraction_non_alphanumeric': 0.12992236460574313, 'fraction_numerical': 0.003835001403049294, 'mean_word_length': 2.0092879256965945, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7333777', 'n_tokens_mistral': 3017, 'n_tokens_neox': 2929, 'n_words': 723}