1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-16 06:05:07 -05:00
mail/src/js/controller/add-account.js

118 lines
3.2 KiB
JavaScript
Raw Normal View History

2014-10-02 16:05:44 -04:00
'use strict';
2014-01-27 12:50:13 -05:00
2014-10-02 16:05:44 -04:00
var appCtrl = require('../app-controller'),
cfg = require('../app-config').config;
2014-01-27 12:50:13 -05:00
2014-10-02 16:05:44 -04:00
var AddAccountCtrl = function($scope, $location, $routeParams) {
if (!appCtrl._auth && !$routeParams.dev) {
$location.path('/'); // init app
return;
}
2014-10-02 16:05:44 -04:00
$scope.step = 1;
2014-10-02 16:05:44 -04:00
$scope.goTo = function(step) {
$scope.step = step;
};
2014-10-02 16:05:44 -04:00
$scope.createWhiteoutAccount = function() {
if ($scope.form.$invalid) {
return;
}
$scope.busy = true;
$scope.errMsg = undefined; // reset error msg
$scope.emailAddress = $scope.user + '@' + cfg.wmailDomain;
// call REST api
appCtrl._adminDao.createUser({
emailAddress: $scope.emailAddress,
password: $scope.pass,
phone: $scope.phone.replace(/\s+/g, ''), // remove spaces from the phone number
betaCode: $scope.betaCode.toUpperCase()
}, function(err) {
$scope.busy = false;
if (err) {
$scope.errMsg = err.errMsg || err.message;
$scope.$apply();
return;
}
2014-10-02 16:05:44 -04:00
$scope.goTo(3);
$scope.$apply();
});
};
2014-09-19 12:59:13 -04:00
2014-10-02 16:05:44 -04:00
$scope.validateUser = function() {
if ($scope.formValidate.$invalid) {
return;
}
2014-10-02 16:05:44 -04:00
$scope.busyValidate = true;
$scope.errMsgValidate = undefined; // reset error msg
// verify user to REST api
appCtrl._adminDao.validateUser({
emailAddress: $scope.emailAddress,
token: $scope.token.toUpperCase()
}, function(err) {
if (err) {
$scope.busyValidate = false;
$scope.errMsgValidate = err.errMsg || err.message;
2014-09-19 12:59:13 -04:00
$scope.$apply();
return;
}
2014-10-02 16:05:44 -04:00
// proceed to login
$scope.login();
});
};
2014-09-19 12:59:13 -04:00
2014-10-02 16:05:44 -04:00
$scope.login = function() {
// store credentials in memory
appCtrl._auth.setCredentials({
provider: 'wmail',
emailAddress: $scope.emailAddress,
username: $scope.emailAddress,
realname: $scope.realname,
password: $scope.pass,
imap: cfg.wmail.imap,
smtp: cfg.wmail.smtp
});
// proceed to login and keygen
$location.path('/login');
$scope.$apply();
};
$scope.connectToGoogle = function() {
// test for oauth support
if (appCtrl._auth._oauth.isSupported()) {
// fetches the email address from the chrome identity api
appCtrl._auth.getOAuthToken(function(err) {
2014-09-19 12:59:13 -04:00
if (err) {
2014-10-02 16:05:44 -04:00
return $scope.onError(err);
2014-09-19 12:59:13 -04:00
}
2014-10-02 16:05:44 -04:00
$location.path('/login-set-credentials').search({
provider: 'gmail'
});
2014-10-02 16:05:44 -04:00
$scope.$apply();
2014-01-27 12:50:13 -05:00
});
2014-10-02 16:05:44 -04:00
return;
}
2014-01-27 12:50:13 -05:00
2014-10-02 16:05:44 -04:00
// use normal user/password login
$location.path('/login-set-credentials').search({
provider: 'gmail'
});
};
$scope.connectTo = function(provider) {
$location.path('/login-set-credentials').search({
provider: provider
});
2014-01-27 12:50:13 -05:00
};
2014-10-02 16:05:44 -04:00
};
2014-01-27 12:50:13 -05:00
2014-10-08 06:34:34 -04:00
module.exports = AddAccountCtrl;