UNPKG

sheercms

Version:

Sheer Cliff CMS is a simple and powerful content management system (CMS) for Node JS.

96 lines (74 loc) 2.62 kB
app.controller('SetupController', function($scope, $location, $q, SetupService) { $scope.step = 0; $scope.data = { username: "", password1: "", password2: "", message: "", package: "starter" }; $scope.beginSetup = function() { $scope.gotoStep(1); }; $scope.createAccount = function() { //show processing message setMessage('Creating account...please wait.', 'alert-info'); //validate the username and password if ($scope.data.username.length === 0) { setMessage("Invalid username. Try something like 'admin' or 'youremail@gmail.com'", 'alert-danger'); return; } if ($scope.data.password1.length < 8 || $scope.data.password1.length > 24) { setMessage("Invalid password. The password must be at least 8 characters long and no more than 24.", 'alert-danger'); return; } if ($scope.data.password1 != $scope.data.password2) { setMessage("The passwords do not match.", 'alert-danger'); return; } SetupService.createAccount($scope.data.username, $scope.data.password1).then(function(result) { if (result.success === true) { $scope.gotoStep(2); } else { setMessage(result.message, 'alert-danger'); } }); }; $scope.installPackage = function() { //show processing message var msg = $scope.data.package === 'none' ? 'Completing installation...please wait.' : 'Installing package...please wait.'; setMessage(msg, 'alert-info'); SetupService.installPackage($scope.data.package).then(function(result) { if (result.success === true) { $scope.gotoComplete(); } else { setMessage(result.message, 'alert-danger'); } }); }; $scope.gotoLogin = function() { window.location.href = '/cms/login'; }; $scope.gotoComplete = function() { clearMessage(); $scope.step = 99; var path = '/complete'; $location.path(path); }; $scope.gotoStep = function(num) { clearMessage(); $scope.step = num; var path = '/step' + $scope.step; $location.path(path); }; function setMessage(msg, type) { $scope.data.messageType = type; $scope.data.message = msg; } function clearMessage() { $scope.data.message = ''; $scope.data.messageType = ''; } });