From ee4548a84aab0e1002c88757ff8c04e211badd6a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 20 Sep 2016 19:57:24 -0400 Subject: [PATCH] registration --- src/models/api/requestModels.js | 8 +-- .../app/accounts/accountsLoginController.js | 14 ++++- src/popup/app/accounts/accountsModule.js | 2 +- .../accounts/accountsRegisterController.js | 33 ++++++++++++ .../app/accounts/views/accountsRegister.html | 54 +++++++++++++++++++ src/popup/app/config.js | 9 +++- src/popup/app/global/home.html | 2 +- src/popup/index.html | 1 + src/services/apiService.js | 21 ++++---- 9 files changed, 124 insertions(+), 20 deletions(-) create mode 100644 src/popup/app/accounts/accountsRegisterController.js create mode 100644 src/popup/app/accounts/views/accountsRegister.html diff --git a/src/models/api/requestModels.js b/src/models/api/requestModels.js index f74fac6b..6ae456c2 100644 --- a/src/models/api/requestModels.js +++ b/src/models/api/requestModels.js @@ -21,11 +21,11 @@ var TokenRequest = function (email, masterPasswordHash, device) { this.device = null; }; -var RegisterRequest = function () { +var RegisterRequest = function (email, masterPasswordHash, masterPasswordHint) { this.name = null; - this.email = null; - this.masterPasswordHash = null; - this.masterPasswordHint = null; + this.email = email; + this.masterPasswordHash = masterPasswordHash; + this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null; }; var PasswordHintRequest = function (email) { diff --git a/src/popup/app/accounts/accountsLoginController.js b/src/popup/app/accounts/accountsLoginController.js index ade21704..5acf79a3 100644 --- a/src/popup/app/accounts/accountsLoginController.js +++ b/src/popup/app/accounts/accountsLoginController.js @@ -1,9 +1,19 @@ angular .module('bit.accounts') - .controller('accountsLoginController', function ($scope, $state, loginService, userService) { + .controller('accountsLoginController', function ($scope, $state, $stateParams, loginService, userService) { popupUtils.initListSectionItemListeners(); - $('#email').focus(); + + if ($stateParams.email) { + $('#master-password').focus(); + } + else { + $('#email').focus(); + } + + $scope.model = { + email: $stateParams.email + }; $scope.loginPromise = null; $scope.login = function (model) { diff --git a/src/popup/app/accounts/accountsModule.js b/src/popup/app/accounts/accountsModule.js index bfa5fbec..e2f77743 100644 --- a/src/popup/app/accounts/accountsModule.js +++ b/src/popup/app/accounts/accountsModule.js @@ -1,2 +1,2 @@ angular - .module('bit.accounts', ['toastr']); + .module('bit.accounts', ['toastr', 'ngAnimate']); diff --git a/src/popup/app/accounts/accountsRegisterController.js b/src/popup/app/accounts/accountsRegisterController.js new file mode 100644 index 00000000..6c4fb7ac --- /dev/null +++ b/src/popup/app/accounts/accountsRegisterController.js @@ -0,0 +1,33 @@ +angular + .module('bit.accounts') + + .controller('accountsRegisterController', function ($scope, $state, cryptoService, toastr, $q, apiService) { + popupUtils.initListSectionItemListeners(); + $('#email').focus(); + + $scope.submitPromise = null; + $scope.submit = function (model) { + var email = model.email.toLowerCase(); + var key = cryptoService.makeKey(model.masterPassword, email); + $scope.submitPromise = registerPromise(key, model.masterPassword, email, model.hint); + $scope.submitPromise.then(function () { + toastr.success('Your new account has been created! You may now log in.'); + $state.go('login', { email: email, animation: 'in-slide-left' }); + }); + }; + + function registerPromise(key, masterPassword, email, hint) { + return $q(function (resolve, reject) { + cryptoService.hashPassword(masterPassword, key, function (hashedPassword) { + var request = new RegisterRequest(email, hashedPassword, hint); + apiService.postRegister(request, + function () { + resolve(); + }, + function (error) { + reject(error); + }); + }); + }); + } + }); diff --git a/src/popup/app/accounts/views/accountsRegister.html b/src/popup/app/accounts/views/accountsRegister.html new file mode 100644 index 00000000..c6f7edaa --- /dev/null +++ b/src/popup/app/accounts/views/accountsRegister.html @@ -0,0 +1,54 @@ +
+
+
+ Cancel +
+
+ + +
+
Create Account
+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +
+
+ + + +
+
+ +
+
+
+
diff --git a/src/popup/app/config.js b/src/popup/app/config.js index 08400068..04adb82d 100644 --- a/src/popup/app/config.js +++ b/src/popup/app/config.js @@ -53,7 +53,7 @@ controller: 'accountsLoginController', templateUrl: 'app/accounts/views/accountsLogin.html', data: { authorize: false }, - params: { animation: null } + params: { animation: null, email: null } }) .state('hint', { url: '/hint', @@ -69,6 +69,13 @@ data: { authorize: false }, params: { animation: null } }) + .state('register', { + url: '/register', + controller: 'accountsRegisterController', + templateUrl: 'app/accounts/views/accountsRegister.html', + data: { authorize: false }, + params: { animation: null } + }) .state('tabs', { url: '/tab', diff --git a/src/popup/app/global/home.html b/src/popup/app/global/home.html index afb1eebc..3d7ab423 100644 --- a/src/popup/app/global/home.html +++ b/src/popup/app/global/home.html @@ -3,7 +3,7 @@ bitwarden

Log in or create a new account to access your secure vault.

- + Create Account diff --git a/src/popup/index.html b/src/popup/index.html index fe5ea372..e2d35748 100644 --- a/src/popup/index.html +++ b/src/popup/index.html @@ -53,6 +53,7 @@ + diff --git a/src/services/apiService.js b/src/services/apiService.js index ab5bfced..ff2aad7d 100644 --- a/src/services/apiService.js +++ b/src/services/apiService.js @@ -14,7 +14,7 @@ function initApiService() { type: 'POST', url: self.baseUrl + '/auth/token', data: JSON.stringify(tokenRequest), - contentType: "application/json; charset=utf-8", + contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (response) { success(new TokenResponse(response)) @@ -31,7 +31,7 @@ function initApiService() { type: 'POST', url: self.baseUrl + '/auth/token/two-factor', data: JSON.stringify(twoFactorTokenRequest), - contentType: "application/json; charset=utf-8", + contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (response) { success(new TokenResponse(response)) @@ -67,7 +67,7 @@ function initApiService() { type: 'POST', url: self.baseUrl + '/accounts/password-hint', data: JSON.stringify(request), - contentType: "application/json; charset=utf-8", + contentType: 'application/json; charset=utf-8', success: function (response) { success(); }, @@ -77,14 +77,13 @@ function initApiService() { }); }; - ApiService.prototype.register = function (request, success, error) { + ApiService.prototype.postRegister = function (request, success, error) { var self = this; $.ajax({ type: 'POST', url: self.baseUrl + '/accounts/register', data: JSON.stringify(request), - contentType: "application/json; charset=utf-8", - dataType: 'json', + contentType: 'application/json; charset=utf-8', success: function (response) { success(); }, @@ -120,7 +119,7 @@ function initApiService() { type: 'POST', url: self.baseUrl + '/sites?access_token=' + token, data: JSON.stringify(siteRequest), - contentType: "application/json; charset=utf-8", + contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (response) { success(new SiteResponse(response)) @@ -139,7 +138,7 @@ function initApiService() { type: 'POST', url: self.baseUrl + '/sites/' + id + '?access_token=' + token, data: JSON.stringify(siteRequest), - contentType: "application/json; charset=utf-8", + contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (response) { success(new SiteResponse(response)) @@ -177,7 +176,7 @@ function initApiService() { type: 'POST', url: self.baseUrl + '/folders?access_token=' + token, data: JSON.stringify(folderRequest), - contentType: "application/json; charset=utf-8", + contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (response) { success(new FolderResponse(response)) @@ -196,7 +195,7 @@ function initApiService() { type: 'POST', url: self.baseUrl + '/folders/' + id + '?access_token=' + token, data: JSON.stringify(folderRequest), - contentType: "application/json; charset=utf-8", + contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (response) { success(new FolderResponse(response)) @@ -255,7 +254,7 @@ function initApiService() { $.ajax({ type: 'POST', url: self.baseUrl + '/ciphers/' + id + '/delete?access_token=' + token, - contentType: "application/json; charset=utf-8", + contentType: 'application/json; charset=utf-8', dataType: 'json', success: success, error: function (jqXHR, textStatus, errorThrown) {