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 @@ +
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 @@Log in or create a new account to access your secure vault.