WIP: start implementing add-account controller

This commit is contained in:
Tankred Hase 2014-11-07 22:21:37 +01:00
parent 5884b1231f
commit 069628c62b
8 changed files with 136 additions and 85 deletions

View File

@ -7,6 +7,7 @@ exports.config = {
cloudUrl: 'https://keys.whiteout.io',
privkeyServerUrl: 'https://keychain.whiteout.io',
adminUrl: 'https://admin-node.whiteout.io',
settingsUrl: 'https://settings.whiteout.io/autodiscovery/',
wmailDomain: 'wmail.io',
serverPrivateKeyId: 'EE342F0DDBB0F3BE',
symKeySize: 256,

View File

@ -3,89 +3,41 @@
var appCtrl = require('../app-controller'),
cfg = require('../app-config').config;
var AddAccountCtrl = function($scope, $location, $routeParams) {
var AddAccountCtrl = function($scope, $location, $routeParams, $http) {
if (!appCtrl._auth && !$routeParams.dev) {
$location.path('/'); // init app
return;
}
$scope.step = 1;
$scope.goTo = function(step) {
$scope.step = step;
};
$scope.createWhiteoutAccount = function() {
$scope.getAccountSettings = 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) {
var domain = $scope.emailAddress.split('@')[1];
var url = cfg.settingsUrl + domain;
$http.get(url).success(function(config) {
$scope.busy = false;
$scope.state.mailConfig = config;
$scope.state.emailAddress = $scope.emailAddress;
if (err) {
$scope.errMsg = err.errMsg || err.message;
$scope.$apply();
// check for gmail/oauth server
var hostname = config.imap.hostname;
if (hostname.match(/.gmail.com$/) || hostname.match(/.googlemail.com$/)) {
$scope.connectToGoogle();
return;
}
$scope.goTo(3);
$scope.$apply();
}).error(function() {
$scope.busy = false;
$scope.errMsg = 'Error getting IMAP settings for that email address!';
});
};
$scope.validateUser = function() {
if ($scope.formValidate.$invalid) {
return;
}
$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;
$scope.$apply();
return;
}
// proceed to login
$scope.login();
});
};
$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()) {

View File

@ -0,0 +1,43 @@
'use strict';
var appCtrl = require('../app-controller'),
cfg = require('../app-config').config;
var CreateAccountCtrl = function($scope, $location, $routeParams) {
if (!appCtrl._auth && !$routeParams.dev) {
$location.path('/'); // init app
return;
}
$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;
}
// proceed to login and keygen
$location.path('/validate-phone');
$scope.$apply();
});
};
};
module.exports = CreateAccountCtrl;

View File

@ -27,6 +27,8 @@ var SetCredentialsCtrl = function($scope, $location, $routeParams) {
if ($scope.useOAuth) {
$scope.emailAddress = auth.emailAddress;
} else if ($scope.state.emailAddress) {
$scope.emailAddress = $scope.state.emailAddress;
}
if ($scope.hasProviderPreset) {

View File

@ -0,0 +1,55 @@
'use strict';
var appCtrl = require('../app-controller'),
cfg = require('../app-config').config;
var ValidatePhoneCtrl = function($scope, $location, $routeParams) {
if (!appCtrl._auth && !$routeParams.dev) {
$location.path('/'); // init app
return;
}
$scope.validateUser = function() {
if ($scope.formValidate.$invalid) {
return;
}
$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;
$scope.$apply();
return;
}
// proceed to login
$scope.login();
});
};
$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();
};
};
module.exports = ValidatePhoneCtrl;

View File

@ -4,23 +4,25 @@
<img src="img/whiteout_logo.svg" alt="whiteout.io">
</header>
<main class="page__main">
<h2 class="typo-title">Connect your email account</h2>
<p class="typo-paragraph">Enter your email to connect with whiteout.</p>
<h2 class="typo-title">Connect email account</h2>
<p class="typo-paragraph">Connect the Whiteout Mail client to your existing email account via IMAP for easy to use end-to-end encryption. We cannot read your password or messages. <a href="https://github.com/whiteout-io/mail-html5/wiki/FAQ#encryption-and-security" target="_blank">Learn more</a></p>
<form class="form" name="form">
<p class="form__error-message" ng-show="errMsg">{{errMsg}}</p>
<p class="form__error-message" ng-show="form.$invalid">Please fill out all required fields!</p>
<div class="form__row">
<input class="input-text input-text--big" required type="mail" placeholder="Enter email address">
<input type="email" ng-model="emailAddress" class="input-text input-text--big" placeholder="Enter email address" required>
</div>
<div class="spinner-block" ng-show="busy">
<span class="spinner spinner--big"></span>
</div>
<div class="form__row">
<button class="btn btn--big" type="submit">Connect</button>
<button class="btn btn--big" type="submit" ng-click="getAccountSettings()">Connect</button>
</div>
</form>
<p class="typo-paragraph">
Or create a new fully encrypted <a href="#">whiteout mailbox</a>.
Or sign up for a new fully encrypted <a href="#create-account">Whiteout Mailbox</a>.
</p>
</main>
<div ng-include="'tpl/page-footer.html'"></div>

View File

@ -6,14 +6,10 @@
<main class="page__main">
<h2 class="typo-title">Login</h2>
<p class="typo-paragraph" ng-hide="useOAuth">
Please enter your email address and password.
The password is used to authenticate directly
with your mail provider and is not sent to our servers.
Please enter your email address and password. The password is used to authenticate with your mail provider over an encrypted connection. We cannot read your password. <a href="https://github.com/whiteout-io/mail-html5/wiki/FAQ#encryption-and-security" target="_blank">Learn more</a>
</p>
<p class="typo-paragraph" ng-show="useOAuth">
Please confirm your email address. Your account will
authenticate directly with your mail provider. Your
credentials are never sent to our servers.
Please confirm your email address. Your account will authenticate with your mail provider over an encrypted connection. <a href="https://github.com/whiteout-io/mail-html5/wiki/FAQ#encryption-and-security" target="_blank">Learn more</a>
</p>
<form class="form" name="form">

View File

@ -1,12 +1,12 @@
<footer class="page__footer">
<nav>
<ul>
<li><a href="https://whiteout.io/imprint.html">Imprint</a></li>
<li><a href="https://whiteout.io/privacy.html">Privacy</a></li>
<li><a href="https://whiteout.io/terms.html">Terms</a></li>
<li><a href="https://github.com/whiteout-io/mail-html5#license">License</a></li>
<li>Version: TODO</li>
</ul>
</nav>
&copy; 2014 Whiteout Networks GmbH
<footer class="page__footer" ng-controller="AboutCtrl">
<nav>
<ul>
<li><a href="https://whiteout.io/imprint.html" target="_blank">Imprint</a></li>
<li><a href="https://whiteout.io/privacy-service.html" target="_blank">Privacy</a></li>
<li><a href="https://whiteout.io/terms.html" target="_blank">Terms</a></li>
<li><a href="https://github.com/whiteout-io/mail-html5#license" target="_blank">License</a></li>
<li>Version: {{version}}</li>
</ul>
</nav>
&copy; {{ date | date:'yyyy'}} Whiteout Networks GmbH
</footer>