Skip to content

Commit

Permalink
Add config model, update the rest for using it
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Radchenko committed Mar 16, 2015
1 parent 4701f62 commit 6796fac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
11 changes: 10 additions & 1 deletion lib/models/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ var mongoose = require('mongoose')

var Config = new Schema({
version: Number,
// is there any other configuration we want?
serverName: String,
proxyUrl: String,

smtp: {
host: String,
port: Number,
user: String,
password: String,
fromAddress: String
}
})

module.exports = mongoose.model('Config', Config)
Expand Down
16 changes: 14 additions & 2 deletions lib/routes/api/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
'us estrict';

var fs = require('fs');
var path = require('path');
Expand All @@ -19,7 +19,7 @@ router.post('/', function (req, res) {
}

if (needsConfig) {
createConfig(config, function (err) {
createConfig(configData, function (err) {
if (err) {
return res.status(400).send('Invalid config data');
}
Expand All @@ -33,6 +33,15 @@ router.post('/', function (req, res) {
});
});
}
else {
createUser(userData, function (err) {
if (err) {
return res.status(400).send('Invalid user data');
}

res.json('ok');
});
}
});
});

Expand All @@ -42,6 +51,9 @@ function createConfig(config, cb) {

// TODO: populate config, modify model first
c.version = Config.SCHEMA_VERSION;
c.proxyUrl = config.general.proxyUrl;
c.serverName = config.general.serverName;
c.smtp = config.smtp;

c.save(cb);
}
Expand Down
1 change: 1 addition & 0 deletions lib/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ exports.index = function(req, res){

Upgrade.isFreshDb(function (err, isFresh) {
if (err) {
console.error(err);
return res.status(500).send('Database error, make sure you\'ve setup' +
'your mongodb instance correctly.');
}
Expand Down
16 changes: 10 additions & 6 deletions lib/views/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ <h3>Setup Strider</h3>
<legend>Basics</legend>

<label for="basic-servername">Server Name</label>
<input id="basic-servername" type="text" placeholder="Publically visible url" required=true ng-model="config.general.server_name">
<input id="basic-servername" type="text" placeholder="Publically visible url" required=true ng-model="config.general.serverName">
<span class="help-block">Publicaly accessible URL for this instance of Strider, e.g. ci.mydomain.com</span>

<label for="basic-proxyurl">Proxy URL</label>
<input id="basic-proxyurl" type="text" placeholder="Proxy URL" ng-model="config.general.proxyUrl">
<span class="help-block">Publicaly accessible URL for this instance of Strider, e.g. ci.mydomain.com</span>
</fieldset>
<button wz-next type="submit" class="btn btn-default">Next</button>
Expand Down Expand Up @@ -52,23 +56,23 @@ <h3>Setup Strider</h3>
<legend>Email</legend>

<label>Host</label>
<input type="text" placeholder="Type something…" ng-model="config.general.smtp_host">
<input type="text" placeholder="Type something…" ng-model="config.smtp.host">
<span class="help-block">Example block-level help text here.</span>

<label>Port</label>
<input type="text" placeholder="Type something…" ng-model="config.general.smtp_port">
<input type="text" placeholder="Type something…" ng-model="config.smtp.port">
<span class="help-block">Example block-level help text here.</span>

<label>User</label>
<input type="text" placeholder="Type something…" ng-model="config.general.smtp_user">
<input type="text" placeholder="Type something…" ng-model="config.smtp.user">
<span class="help-block">Example block-level help text here.</span>

<label>Password</label>
<input type="text" placeholder="Type something…" ng-model="config.general.smtp_pass">
<input type="text" placeholder="Type something…" ng-model="config.smtp.password">
<span class="help-block">Example block-level help text here.</span>

<label>From Email Address</label>
<input type="text" placeholder="Type something…" ng-model="config.general.smtp_from">
<input type="text" placeholder="Type something…" ng-model="config.smtp.fromAddress">
<span class="help-block">Example block-level help text here.</span>
</fieldset>
<button wz-finish type="submit" class="btn btn-primary">Finish</button>
Expand Down

0 comments on commit 6796fac

Please sign in to comment.