1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

accept org invite. return state for login

This commit is contained in:
Kyle Spearrin 2017-03-23 16:57:47 -04:00
parent 0b875fc6f7
commit 9f1ab6f961
7 changed files with 118 additions and 10 deletions

View File

@ -3,6 +3,7 @@ angular
.controller('accountsLoginController', function ($scope, $rootScope, $cookies, apiService, cryptoService, authService,
$state, appSettings, $analytics) {
var returnState = $state.params.returnState;
var rememberedEmail = $cookies.get(appSettings.rememberedEmailCookieName);
if (rememberedEmail) {
$scope.model = {
@ -36,11 +37,11 @@ angular
masterPassword = model.masterPassword;
$analytics.eventTrack('Logged In To Two-step');
$state.go('frontend.login.twoFactor');
$state.go('frontend.login.twoFactor', { returnState: returnState });
}
else {
$analytics.eventTrack('Logged In');
$state.go('backend.user.vault');
loggedInGo();
}
});
};
@ -51,7 +52,16 @@ angular
$scope.twoFactorPromise.then(function () {
$analytics.eventTrack('Logged In From Two-step');
$state.go('backend.user.vault');
loggedInGo();
});
};
function loggedInGo() {
if (returnState) {
$state.go(returnState.name, returnState.params);
}
else {
$state.go('backend.user.vault');
}
}
});

View File

@ -0,0 +1,46 @@
angular
.module('bit.accounts')
.controller('accountsOrganizationAcceptController', function ($scope, $state, apiService, authService, toastr) {
$scope.state = {
name: $state.current.name,
params: $state.params
};
if (!$state.params.organizationId || !$state.params.organizationUserId || !$state.params.token) {
$state.go('frontend.login.info').then(function () {
toastr.error('Invalid parameters.');
});
return;
}
$scope.$on('$viewContentLoaded', function () {
if (authService.isAuthenticated()) {
$scope.accepting = true;
apiService.organizationUsers.accept(
{
orgId: $state.params.organizationId,
id: $state.params.organizationUserId
},
{
token: $state.params.token
}, function () {
$state.go('backend.user.vault', null, { location: 'replace' }).then(function () {
toastr.success('You can access this organization once an administrator confirms your membership.' +
' We\'ll send an email when that happens.', 'Invite Accepted');
});
}, function () {
$state.go('backend.user.vault', null, { location: 'replace' }).then(function () {
toastr.error('Unable to accept invitation.', 'Error');
});
});
}
else {
$scope.loading = false;
}
});
$scope.submit = function (model) {
};
});

View File

@ -1,9 +1,11 @@
angular
.module('bit.accounts')
.controller('accountsRegisterController', function ($scope, $location, apiService, cryptoService, validationService, $analytics) {
.controller('accountsRegisterController', function ($scope, $location, apiService, cryptoService, validationService,
$analytics, $state) {
var params = $location.search();
$scope.returnState = $state.params.returnState;
$scope.success = false;
$scope.model = {
email: params.email

View File

@ -0,0 +1,29 @@
<div class="login-box">
<div class="login-logo">
<i class="fa fa-shield"></i> <b>bit</b>warden
</div>
<div class="login-box-body">
<div ng-show="loading">
Loading...
</div>
<div ng-show="accepting">
Accepting invitation...
</div>
<div ng-show="!loading && !accepting">
<p class="login-box-msg">Join Organization</p>
<p>
You've been invited to join the ____ organization. To accept the invitation, you need to log in or
create a new bitwarden account.
</p>
<hr />
<div class="row">
<div class="col-sm-6">
<p><a ui-sref="frontend.login.info({returnState: state})" class="btn btn-primary btn-block btn-flat">Log In</a></p>
</div>
<div class="col-sm-6">
<p><a ui-sref="frontend.register({returnState: state})" class="btn btn-primary btn-block btn-flat">Create Account</a></p>
</div>
</div>
</div>
</div>
</div>

View File

@ -9,7 +9,7 @@
<h4>Account Created!</h4>
<p>You may now log in to your new account.</p>
</div>
<a ui-sref="frontend.login.info">Ready to log in?</a>
<a ui-sref="frontend.login.info({returnState: returnState})">Ready to log in?</a>
</div>
<form name="registerForm" ng-submit="registerForm.$valid && register(registerForm)" ng-show="!success"
api-form="registerPromise">
@ -60,7 +60,7 @@
</div>
<div class="row">
<div class="col-xs-7">
<a ui-sref="frontend.login.info">Already have an account?</a>
<a ui-sref="frontend.login.info({returnState: returnState})">Already have an account?</a>
</div>
<div class="col-xs-5">
<button type="submit" class="btn btn-primary btn-block btn-flat" ng-disabled="registerForm.$loading">

View File

@ -149,6 +149,9 @@ angular
.state('frontend.login', {
templateUrl: 'app/accounts/views/accountsLogin.html',
controller: 'accountsLoginController',
params: {
returnState: null
},
data: {
bodyClass: 'login-page'
}
@ -197,21 +200,38 @@ angular
url: '^/register',
templateUrl: 'app/accounts/views/accountsRegister.html',
controller: 'accountsRegisterController',
params: {
returnState: null
},
data: {
pageTitle: 'Register',
bodyClass: 'register-page'
}
})
.state('frontend.organizationAccept', {
url: '^/accept-organization?organizationId&organizationUserId&token',
templateUrl: 'app/accounts/views/accountsOrganizationAccept.html',
controller: 'accountsOrganizationAcceptController',
data: {
pageTitle: 'Accept Organization Invite',
bodyClass: 'login-page',
skipAuthorize: true
}
});
})
.run(function ($rootScope, authService, $state) {
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
if (!toState.data || !toState.data.authorize) {
if (authService.isAuthenticated()) {
event.preventDefault();
$state.go('backend.user.vault');
if (toState.data && toState.data.skipAuthorize) {
return;
}
return;
if (!authService.isAuthenticated()) {
return;
}
event.preventDefault();
$state.go('backend.user.vault');
}
if (!authService.isAuthenticated()) {

View File

@ -108,6 +108,7 @@
<script src="app/accounts/accountsRegisterController.js"></script>
<script src="app/accounts/accountsPasswordHintController.js"></script>
<script src="app/accounts/accountsRecoverController.js"></script>
<script src="app/accounts/accountsOrganizationAcceptController.js"></script>
<script src="app/vault/vaultModule.js"></script>
<script src="app/vault/vaultController.js"></script>