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', cloudUrl: 'https://keys.whiteout.io',
privkeyServerUrl: 'https://keychain.whiteout.io', privkeyServerUrl: 'https://keychain.whiteout.io',
adminUrl: 'https://admin-node.whiteout.io', adminUrl: 'https://admin-node.whiteout.io',
settingsUrl: 'https://settings.whiteout.io/autodiscovery/',
wmailDomain: 'wmail.io', wmailDomain: 'wmail.io',
serverPrivateKeyId: 'EE342F0DDBB0F3BE', serverPrivateKeyId: 'EE342F0DDBB0F3BE',
symKeySize: 256, symKeySize: 256,

View File

@ -3,89 +3,41 @@
var appCtrl = require('../app-controller'), var appCtrl = require('../app-controller'),
cfg = require('../app-config').config; cfg = require('../app-config').config;
var AddAccountCtrl = function($scope, $location, $routeParams) { var AddAccountCtrl = function($scope, $location, $routeParams, $http) {
if (!appCtrl._auth && !$routeParams.dev) { if (!appCtrl._auth && !$routeParams.dev) {
$location.path('/'); // init app $location.path('/'); // init app
return; return;
} }
$scope.step = 1; $scope.getAccountSettings = function() {
$scope.goTo = function(step) {
$scope.step = step;
};
$scope.createWhiteoutAccount = function() {
if ($scope.form.$invalid) { if ($scope.form.$invalid) {
return; return;
} }
$scope.busy = true; $scope.busy = true;
$scope.errMsg = undefined; // reset error msg $scope.errMsg = undefined; // reset error msg
$scope.emailAddress = $scope.user + '@' + cfg.wmailDomain;
// call REST api var domain = $scope.emailAddress.split('@')[1];
appCtrl._adminDao.createUser({ var url = cfg.settingsUrl + domain;
emailAddress: $scope.emailAddress,
password: $scope.pass, $http.get(url).success(function(config) {
phone: $scope.phone.replace(/\s+/g, ''), // remove spaces from the phone number
betaCode: $scope.betaCode.toUpperCase()
}, function(err) {
$scope.busy = false; $scope.busy = false;
$scope.state.mailConfig = config;
$scope.state.emailAddress = $scope.emailAddress;
if (err) { // check for gmail/oauth server
$scope.errMsg = err.errMsg || err.message; var hostname = config.imap.hostname;
$scope.$apply(); if (hostname.match(/.gmail.com$/) || hostname.match(/.googlemail.com$/)) {
$scope.connectToGoogle();
return; return;
} }
$scope.goTo(3); }).error(function() {
$scope.$apply(); $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() { $scope.connectToGoogle = function() {
// test for oauth support // test for oauth support
if (appCtrl._auth._oauth.isSupported()) { 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) { if ($scope.useOAuth) {
$scope.emailAddress = auth.emailAddress; $scope.emailAddress = auth.emailAddress;
} else if ($scope.state.emailAddress) {
$scope.emailAddress = $scope.state.emailAddress;
} }
if ($scope.hasProviderPreset) { 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"> <img src="img/whiteout_logo.svg" alt="whiteout.io">
</header> </header>
<main class="page__main"> <main class="page__main">
<h2 class="typo-title">Connect your email account</h2> <h2 class="typo-title">Connect email account</h2>
<p class="typo-paragraph">Enter your email to connect with whiteout.</p> <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"> <form class="form" name="form">
<p class="form__error-message" ng-show="errMsg">{{errMsg}}</p> <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> <p class="form__error-message" ng-show="form.$invalid">Please fill out all required fields!</p>
<div class="form__row"> <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>
<div class="spinner-block" ng-show="busy"> <div class="spinner-block" ng-show="busy">
<span class="spinner spinner--big"></span> <span class="spinner spinner--big"></span>
</div> </div>
<div class="form__row"> <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> </div>
</form> </form>
<p class="typo-paragraph"> <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> </p>
</main> </main>
<div ng-include="'tpl/page-footer.html'"></div> <div ng-include="'tpl/page-footer.html'"></div>

View File

@ -6,14 +6,10 @@
<main class="page__main"> <main class="page__main">
<h2 class="typo-title">Login</h2> <h2 class="typo-title">Login</h2>
<p class="typo-paragraph" ng-hide="useOAuth"> <p class="typo-paragraph" ng-hide="useOAuth">
Please enter your email address and password. 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>
The password is used to authenticate directly
with your mail provider and is not sent to our servers.
</p> </p>
<p class="typo-paragraph" ng-show="useOAuth"> <p class="typo-paragraph" ng-show="useOAuth">
Please confirm your email address. Your account will 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>
authenticate directly with your mail provider. Your
credentials are never sent to our servers.
</p> </p>
<form class="form" name="form"> <form class="form" name="form">

View File

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