2014-11-07 16:21:37 -05:00
|
|
|
'use strict';
|
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
var CreateAccountCtrl = function($scope, $location, $routeParams, $q, auth, admin, appConfig) {
|
2014-11-19 14:54:59 -05:00
|
|
|
!$routeParams.dev && !auth.isInitialized() && $location.path('/'); // init app
|
2014-11-07 16:21:37 -05:00
|
|
|
|
2015-01-13 05:32:44 -05:00
|
|
|
// init phone region
|
|
|
|
$scope.region = 'DE';
|
|
|
|
|
2014-11-07 16:21:37 -05:00
|
|
|
$scope.createWhiteoutAccount = function() {
|
|
|
|
if ($scope.form.$invalid) {
|
2014-11-09 14:58:13 -05:00
|
|
|
$scope.errMsg = 'Please fill out all required fields!';
|
2014-11-07 16:21:37 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
return $q(function(resolve) {
|
|
|
|
$scope.busy = true;
|
|
|
|
$scope.errMsg = undefined; // reset error msg
|
|
|
|
resolve();
|
|
|
|
|
|
|
|
}).then(function() {
|
2015-01-13 05:32:44 -05:00
|
|
|
// read form values
|
|
|
|
var emailAddress = $scope.user + '@' + appConfig.config.wmailDomain;
|
|
|
|
var phone = PhoneNumber.Parse($scope.dial, $scope.region);
|
|
|
|
if (!phone || !phone.internationalNumber) {
|
|
|
|
throw new Error('Invalid phone number!');
|
|
|
|
}
|
|
|
|
|
2014-12-16 10:14:16 -05:00
|
|
|
// set to state for next view
|
|
|
|
auth.setCredentials({
|
|
|
|
emailAddress: emailAddress,
|
|
|
|
password: $scope.pass,
|
|
|
|
realname: $scope.realname
|
|
|
|
});
|
|
|
|
|
|
|
|
// call REST api
|
|
|
|
return admin.createUser({
|
|
|
|
emailAddress: emailAddress,
|
|
|
|
password: $scope.pass,
|
2015-01-13 05:32:44 -05:00
|
|
|
phone: phone.internationalNumber,
|
2014-12-16 10:14:16 -05:00
|
|
|
betaCode: $scope.betaCode.toUpperCase()
|
|
|
|
});
|
|
|
|
|
|
|
|
}).then(function() {
|
2014-11-07 16:21:37 -05:00
|
|
|
$scope.busy = false;
|
|
|
|
// proceed to login and keygen
|
|
|
|
$location.path('/validate-phone');
|
2014-12-16 10:14:16 -05:00
|
|
|
|
|
|
|
}).catch(function(err) {
|
|
|
|
$scope.busy = false;
|
|
|
|
$scope.errMsg = err.errMsg || err.message;
|
2014-11-07 16:21:37 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = CreateAccountCtrl;
|