Permalink
Browse files

Updated install process to add extra details and user validation

  • Loading branch information...
1 parent 6290f6c commit b040b21a9a08c847d91375d8e57aa69fef92e092 @cliftonc committed Sep 8, 2011
View
@@ -23,7 +23,7 @@
},
"performance": {
"cache":{
- "enabled":true,
+ "enabled":false,
"ttl":600
},
"watchFiles":true
@@ -84,7 +84,8 @@ function init(module, app, next) {
// Default installation routers
module.router.addRoute('GET /admin/install', install, null, this.parallel());
module.router.addRoute('POST /admin/install', install, null, this.parallel());
- module.router.addRoute('POST /admin/installApi/mongo', installMongoTest, null, this.parallel());
+ module.router.addRoute('POST /admin/installTest/mongo', installMongoTest, null, this.parallel());
+ module.router.addRoute('POST /admin/installTest/user', installUserTest, null, this.parallel());
}, function done() {
@@ -289,6 +290,12 @@ function installMongo(req,res,next) {
*/
function installMongoTest(req, res, template, block, next) {
+ if (calipso.config.get('installed')) {
+ res.format = "json";
+ res.end(JSON.stringify({status:"Invalid Request"}),"UTF-8");
+ return next();
+ }
+
calipso.form.process(req,function(form) {
var dbUri = form.dbUri;
@@ -332,11 +339,12 @@ function installUser(req,res,next) {
var userForm = {
id:'install-user-form',title:'',type:'form',method:'POST',action:'/admin/install',
fields:[
- {label:'Username', name:'user[username]', type:'text'},
+ {label:'Username', name:'user[username]', cls:'username', type:'text'},
{label:'Full Name', name:'user[fullname]', type:'text'},
{label:'Email', name:'user[email]', type:'text'},
{label:'Language', name:'user[language]', type:'select', options:req.languages}, // TODO : Select based on available
- {label:'Password', name:'user[password]', type:'password'},
+ {label:'Password', name:'user[password]', cls:'password', type:'password'},
+ {label:'Repeat Password', name:'user[check_password]', cls: 'check_password', type:'password'},
{label:'',name:'installStep',type:'hidden'},
{label:'',name:'userStep',type:'hidden'}
],
@@ -356,6 +364,51 @@ function installUser(req,res,next) {
}
/**
+ * Function to enable ajax testing of the mongo configuration
+ */
+function installUserTest(req, res, template, block, next) {
+
+ if (calipso.config.get('installed')) {
+ res.format = "json";
+ res.end(JSON.stringify({status:"Invalid Request"}),"UTF-8");
+ return next();
+ }
+
+
+ calipso.form.process(req,function(form) {
+
+ // Check to see if new passwords match
+ var err;
+
+ if(form.password != form.check_password) {
+ err = new Error(req.t('Your passwords do not match.'));
+ }
+
+ // Check to see if new passwords are blank
+ if(form.password === '') {
+ err = new Error(req.t('Your password cannot be blank.'));
+ }
+
+ if(form.username === '') {
+ err = new Error(req.t('Your username cannot be blank.'));
+ }
+
+ var output = {};
+ if(err) {
+ output.status = "FAILED";
+ output.message= "There was a problem because: " + err.message;
+ } else {
+ output.status = "OK";
+ }
+ res.format = "json";
+ res.end(JSON.stringify(output),"UTF-8");
+ next();
+
+ });
+
+}
+
+/**
* Install Modules - called by install router, not a routing function.
*/
function installModules(req,res,next) {
@@ -426,7 +479,7 @@ function doInstallation(next) {
},
function reloadConfiguration() {
// This ensures the configuration is applied in cluster mode
- calipso.reloadConfig(calipso.config, this);
+ calipso.reloadConfig("ADMIN_INSTALL", calipso.config, this);
},
function done(err) {
return next(err);
@@ -1,10 +1,10 @@
<div class='admin-install'>
<h1><%= t("Configure MongoDB") %></h1>
+ <div id="mongo-status" style="display: none;">
+ </div>
<div>
<%- form %>
- </div>
- <div id="mongo-status" style="display: none; padding: 10px; margin-bottom: 20px; text-align: center; width: 100%;">
- </div>
+ </div>
<div class="admin-install-links">
<a href="?installStep=welcome"><%= "<< " + t("First Step: Welcome") %></a> | <a id='form-submit' href=""><%= t("Third Step: Configure Default User") + " >>" %></a>
</div>
@@ -23,17 +23,17 @@
$.ajax({
type: "POST",
- url: "/admin/installApi/mongo",
+ url: "/admin/installTest/mongo",
dataType:"json",
data:postData,
success: function(res){
if(res.status === "OK") {
- $('#mongo-status').html("<span class='install-success'>MongoDB connection successfull ... </span>");
+ $('#mongo-status').html("<ul class='info'><li>MongoDB connection successfull ... </li></ul>");
setTimeout(function() {
$('#install-mongo-form').submit();
},1000);
} else {
- $('#mongo-status').html("<span class='install-failure'>MongoDB connection failed, please check the details and try again ... </span>");
+ $('#mongo-status').html("<ul class='error'><li>MongoDB connection failed, please check the details and try again ...</li></ul>");
}
}
});
@@ -1,15 +1,53 @@
<div class='admin-install'>
<h1><%= t("Create Admin User") %></h1>
+ <div id="user-status" style="display: none;">
+ </div>
<div>
<%- form %>
- </div>
+ </div>
<div class="admin-install-links">
<a href="?installStep=mongodb"><%= "<< " + t("Second Step: Configure MongoDB") %></a> | <a id="form-submit" href="#"><%= t("Fourth Step: Configure Modules") + " >> " %></a>
</div>
- <script>
- $('#form-submit').click(function(event) {
- event.preventDefault();
- $('#install-user-form').submit();
+ <script>
+ $(document).ready(function() {
+
+ // Ajax request to /admin/install/mongo/test
+ function checkUser() {
+
+ $('#user-status').show();
+ $('#user-status').html("<span class='install-progress'>Validating user, please wait ... </span>");
+
+ var username = $(".username").val();
+ var password = $(".password").val();
+ var check_password = $(".check_password").val();
+
+ var postData = {"username":username,"password":password,"check_password":check_password};
+
+ $.ajax({
+ type: "POST",
+ url: "/admin/installTest/user",
+ dataType:"json",
+ data:postData,
+ success: function(res){
+ if(res.status === "OK") {
+ $('#user-status').html("<ul class='info'><li>User is valid ... </li></ul>");
+ setTimeout(function() {
+ $('#install-user-form').submit();
+ },1000);
+ } else {
+ console.log(res);
+ $('#user-status').html("<ul class='error'><li>" + res.message + "</li></ul>");
+ }
+ }
+ });
+
+ }
+
+ $('#form-submit').click(function(event) {
+ event.preventDefault();
+ checkUser();
+ });
+
});
</script>
</div>
View
@@ -939,68 +939,60 @@ function install(next) {
function createDefaults() {
+ var self = this;
+
// Create default roles
var r = new Role({
name:'Guest',
description:'Guest account',
isAdmin:false,
isDefault:true
});
- r.save(this.parallel());
+ r.save(self.parallel());
var r = new Role({
name:'Contributor',
description:'Able to create and manage own content items linked to their own user profile area.',
isAdmin:false,
isDefault:false
});
- r.save(this.parallel());
+ r.save(self.parallel());
var r = new Role({
name:'Administrator',
description:'Able to manage the entire site.',
isAdmin:true,
isDefault:false
});
- r.save(this.parallel());
+ r.save(self.parallel());
// Create administrative user
if (calipso.data.adminUser) {
+
+ var adminUser = calipso.data.adminUser;
-
- // Create default if skipped form
- if(!calipso.data.adminUser.username && !calipso.data.adminUser.password) {
- calipso.data.adminUser = {
- username: 'admin',
- password: 'password',
- email: 'admin@example.com',
- about: 'Default administrator.'
- }
- }
- var user = calipso.data.adminUser;
-
- // We have a user u via the install process, apply defaults just in case
- // They screw up the form
+ // Create a new user
var admin = new User({
- username:user.username,
- hash:calipso.lib.crypto.hash(user.password,calipso.config.get('session:secret')),
- email:user.email,
- about:user.about,
+ username:adminUser.username,
+ hash:calipso.lib.crypto.hash(adminUser.password,calipso.config.get('session:secret')),
+ email:adminUser.email,
+ about:adminUser.about,
roles:['Administrator']
});
- admin.save(this.parallel());
+ admin.save(self.parallel());
+
+ } else {
- // Note the details for the admin user are in memory at this point @ calipso.data.adminUser
- // This is later used to display the summary page, it will be deleted there.
+ // Fatal error
+ self.parallel()(new Error("No administrative user details provided through login process!"));
}
},
- function allDone(err) {
-
+ function allDone(err) {
if(err) {
calipso.error("User module installed " + err.message);
- next(err);
+ next();
} else {
storeRoles();
calipso.log("User module installed ... ");

0 comments on commit b040b21

Please sign in to comment.