diff --git a/src/models/api/requestModels.js b/src/models/api/requestModels.js index f74fac6b28..6ae456c21d 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 ade2170484..5acf79a3e3 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 bfa5fbecb6..e2f77743d6 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 0000000000..6c4fb7ac2f --- /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 0000000000..c6f7edaa3d --- /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 0840006873..04adb82d8b 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 afb1eebc53..3d7ab42311 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 fe5ea37247..e2d3574805 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 ab5bfced76..ff2aad7de8 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) {