Skip to content
Snippets Groups Projects
Commit 2dae912e authored by Kyle Doherty's avatar Kyle Doherty
Browse files

merge

parents caf1d5e2 e19e7c11
Branches
Tags
No related merge requests found
......@@ -58,16 +58,6 @@ Corvus.config(['$routeProvider', '$locationProvider', function($routeProvider, $
}
});
$routeProvider.when('/setup/', {
templateUrl: '/app/setup/partials/setup_intro.html',
controller: 'SetupIntro'
});
$routeProvider.when('/setup/init/:setupToken', {
template: '',
controller: 'SetupInit'
});
$routeProvider.when('/superadmin/', {
redirectTo: function(routeParams, path, search) {
return '/superadmin/settings/';
......
......@@ -1097,4 +1097,4 @@ CoreServices.factory('PermissionViolation', ['$resource', '$cookies', function($
},
});
}]);
\ No newline at end of file
}]);
<div class="SetupSteps flex flex-column layout-centered wrapper wrapper-max-sm">
<section class="SetupStep bordered rounded full relative" ng-class="{ 'SetupStep--active shadowed' : activeStep == 'user', 'SetupStep--completed shadowed' : completedSteps.user }">
<div class="flex align-center py2">
<div class="flex align-center py2" ng-click="activeStep = 'user'">
<span class="SetupStep-indicator flex layout-centered absolute bordered">
<span class="SetupStep-number">1</span>
<cv-check-icon class="SetupStep-check" width="16px" height="16px"></cv-check-icon>
......@@ -9,8 +9,13 @@
</div>
<form class="Form-new" name="form" ng-submit="createOrgAndUser()" novalidate ng-if="activeStep == 'user'" novalidate>
<div class="Form-field" mb-form-field="first_name">
<mb-form-label display-name="Your name" field-name="name"></mb-form-label>
<input class="Form-input Form-offset full" name="name" placeholder="Johnny Appleseed" ng-model="newUser.name" required autofocus />
<mb-form-label display-name="First name" field-name="first_name"></mb-form-label>
<input class="Form-input Form-offset full" name="name" placeholder="Johnny" ng-model="newUser.first_name" required autofocus />
<span class="Form-charm"></span>
</div>
<div class="Form-field" mb-form-field="last_name">
<mb-form-label display-name="Last name" field-name="last_name"></mb-form-label>
<input class="Form-input Form-offset full" name="name" placeholder="Appleseed" ng-model="newUser.last_name" required />
<span class="Form-charm"></span>
</div>
......@@ -33,8 +38,8 @@
</div>
<div class="Form-field" mb-form-field="organization">
<mb-form-label display-name="Your company or team name" field-name="password"></mb-form-label>
<input class="Form-input Form-offset full" name="organization" type="text" placeholder="Department of awesome" ng-model="userOrgName" autofocus required>
<mb-form-label display-name="Your organization or company name" field-name="organization"></mb-form-label>
<input class="Form-input Form-offset full" name="organization" type="text" placeholder="Organization name" ng-model="newUser.orgName" autofocus required>
<span class="Form-charm"></span>
</div>
......@@ -64,7 +69,7 @@
<!-- Bottom Actions -->
<div class="Form-actions">
<button class="Button" ng-class="{'Button--primary': form.$valid}" ng-click="save(database, details, false)" ng-disabled="!form.$valid">
<button class="Button" ng-class="{'Button--primary': form.$valid}" ng-click="save(database, details, false)" ng-disabled="!form.$valid || !database.engine">
Save
</button>
<mb-form-message></mb-form-message>
......@@ -83,4 +88,5 @@
<button class="Button Button--primary">Take me to my data</button>
</section>
</div>
......@@ -2,15 +2,39 @@
var SetupControllers = angular.module('corvus.setup.controllers', ['corvus.metabase.services', 'corvus.setup.services']);
SetupControllers.controller('SetupInfo', ['$scope', '$routeParams', '$location', '$timeout', 'ipCookie', 'Organization', 'AppState', 'Setup', 'Metabase', 'CorvusCore',
function($scope, $routeParams, $location, $timeout, ipCookie, Organization, AppState, Setup, Metabase, CorvusCore) {
SetupControllers.controller('SetupInit', ['$scope', '$location', '$routeParams', 'AppState',
function($scope, $location, $routeParams, AppState) {
// The only thing this controller does is grab the setup token from the url and store it in our AppState
// then we begin the actual setup workflow by sending the user to /setup/
AppState.model.setupToken = $routeParams.setupToken;
$location.path('/setup/welcome');
}
]);
SetupControllers.controller('SetupInfo', ['$scope', '$routeParams', '$location', '$timeout', 'ipCookie', 'Organization', 'User', 'AppState', 'Setup', 'Metabase', 'CorvusCore',
function($scope, $routeParams, $location, $timeout, ipCookie, Organization, User, AppState, Setup, Metabase, CorvusCore) {
$scope.activeStep = "user";
$scope.completedSteps = {
user: false,
database: false
};
$scope.newUser = {};
$scope.setActiveStep = function(name) {
console.log(name);
if (name === "user") {
$scope.activeStep = "user";
} else if (name === "database" && $scope.completedSteps.user) {
$scope.activeStep = "database";
} else if (name === "finish" && $scope.completedSteps.user && $scope.completedSteps.database) {
$scope.activeStep = "finish";
}
}
$scope.$on("database:created", function(event, database) {
$timeout(function() {
$scope.activeStep = "finish";
......@@ -18,66 +42,104 @@ SetupControllers.controller('SetupInfo', ['$scope', '$routeParams', '$location',
});
});
var oldPassword = null;
function createOrUpdateUser() {
if (AppState.model.currentUser) {
return User.update({
'id': AppState.model.currentUser.id,
'email': $scope.newUser.email,
'first_name': $scope.newUser.first_name,
'last_name': $scope.newUser.last_name
}).$promise.then(function(user) {
if (!oldPassword) {
$scope.newUser.password = "";
$scope.newUser.repeated_password = "";
} else {
return User.update_password({
'id': AppState.model.currentUser.id,
'password': $scope.newUser.password,
'old_password': oldPassword
}).$promise;
}
}).then(function() {
// record the last known password in case the user goes back to edit it
oldPassword = $scope.newUser.password;
});
} else {
return Setup.create_user({
'token': AppState.model.setupToken,
'email': $scope.newUser.email,
'first_name': $scope.newUser.first_name,
'last_name': $scope.newUser.last_name,
'password': $scope.newUser.password
}).$promise.then(function(user) {
console.log('first user created', user);
// record the last known password in case the user goes back to edit it
oldPassword = $scope.newUser.password;
// result should have a single :id value which is our new session id
var sessionId = user.id;
// we've now used the setup token for all it's worth, so lets actively purge it now
AppState.model.setupToken = null;
// TODO - this session cookie code needs to be somewhere easily reusable
var isSecure = ($location.protocol() === "https") ? true : false;
ipCookie('metabase.SESSION_ID', sessionId, {
path: '/',
expires: 14,
secure: isSecure
});
// send a login notification event
$scope.$emit('appstate:login', sessionId);
// this is ridiculously stupid. we have to wait (300ms) for the cookie to actually be set in the browser :(
return $timeout(function(){}, 1000);
});
}
}
function createOrUpdateOrg() {
// TODO - we need some logic to slugify the name specified. can't have spaces, caps, etc.
if (AppState.model.currentOrg) {
return Organization.update({
'id': AppState.model.currentOrg.id,
'name': $scope.newUser.orgName,
'slug': $scope.newUser.orgName
}).$promise;
} else {
return Organization.create({
'name': $scope.newUser.orgName,
'slug': $scope.newUser.orgName
}).$promise.then(function(org) {
console.log('first org created', org);
// switch the org
// TODO - make sure this is up to snuff from a security standpoint
AppState.switchOrg(org.slug);
});
}
}
$scope.createOrgAndUser = function() {
var name = $scope.newUser.name.split(' ')
var firstName = name[0];
var lastName = name[1];
debugger;
// start off by creating the first user of the system
// NOTE: this should both create the user AND log us in and return a session id
Setup.create_user({
'token': AppState.model.setupToken,
'email': $scope.newUser.email,
'first_name': firstName,
'last_name': lastName,
'password': $scope.newUser.password
}, function(result) {
// result should have a single :id value which is our new session id
var sessionId = result.id;
// we've now used the setup token for all it's worth, so lets actively purge it now
AppState.model.setupToken = null;
// TODO - this session cookie code needs to be somewhere easily reusable
var isSecure = ($location.protocol() === "https") ? true : false;
ipCookie('metabase.SESSION_ID', sessionId, {
path: '/',
expires: 14,
secure: isSecure
});
createOrUpdateUser().then(function() {
// now that we should be logged in and our session cookie is established, lets do the rest of the work
// create our first Organization
return createOrUpdateOrg();
}).then(function() {
// reset error in case there were previous errors
$scope.error = null;
// send a login notification event
$scope.$emit('appstate:login', sessionId);
// this is ridiculously stupid. we have to wait (300ms) for the cookie to actually be set in the browser :(
$timeout(function() {
// now that we should be logged in and our session cookie is established, lets do the rest of the work
// create our first Organization
// TODO - we need some logic to slugify the name specified. can't have spaces, caps, etc.
Organization.create({
'name': $scope.userOrgName,
'slug': $scope.userOrgName
}, function(org) {
console.log('first org created', org);
// switch the org
// TODO - make sure this is up to snuff from a security standpoint
AppState.switchOrg(org.slug);
// we should be good to carry on with setting up data at this point
// $location.path('/setup/data/');
$scope.activeStep = "database";
$scope.completedSteps.user = true;
}, function(error) {
$scope.error = error.data;
console.log('error creating organization', error);
});
}, 300);
}, function(error) {
// we should be good to carry on with setting up data at this point
$scope.activeStep = "database";
$scope.completedSteps.user = true;
}).catch(function(error) {
console.log('error with initial', error);
$scope.error = error.data;
console.log('error with initial user creation', error);
});
};
}
......
......@@ -6,6 +6,12 @@ var Setup = angular.module('corvus.setup', [
]);
Setup.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/setup/init/:setupToken', {
template: '',
controller: 'SetupInit'
});
$routeProvider.when('/setup/welcome', {
templateUrl: '/app/setup/partials/setup_welcome.html'
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment