mirror of https://github.com/portainer/portainer
refactor(auth): remove login retry with $sanitize (#3923)
* refactor(auth): remove update-password view * refactor(auth): remove auth retry with $sanitizepull/3948/head
parent
7c3b83f6e5
commit
0b6dbec305
|
@ -25,8 +25,8 @@
|
||||||
<div
|
<div
|
||||||
id="page-wrapper"
|
id="page-wrapper"
|
||||||
ng-class="{
|
ng-class="{
|
||||||
open: toggle && ['portainer.auth', 'portainer.updatePassword', 'portainer.init.admin', 'portainer.init.endpoint'].indexOf($state.current.name) === -1,
|
open: toggle && ['portainer.auth', 'portainer.init.admin', 'portainer.init.endpoint'].indexOf($state.current.name) === -1,
|
||||||
nopadding: ['portainer.auth', 'portainer.updatePassword', 'portainer.init.admin', 'portainer.init.endpoint'].indexOf($state.current.name) > -1 || applicationState.loading
|
nopadding: ['portainer.auth', 'portainer.init.admin', 'portainer.init.endpoint'].indexOf($state.current.name) > -1 || applicationState.loading
|
||||||
}"
|
}"
|
||||||
ng-cloak
|
ng-cloak
|
||||||
>
|
>
|
||||||
|
|
|
@ -452,18 +452,6 @@ angular.module('portainer.app', []).config([
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var updatePassword = {
|
|
||||||
name: 'portainer.updatePassword',
|
|
||||||
url: '/update-password',
|
|
||||||
views: {
|
|
||||||
'content@': {
|
|
||||||
templateUrl: './views/update-password/updatePassword.html',
|
|
||||||
controller: 'UpdatePasswordController',
|
|
||||||
},
|
|
||||||
'sidebar@': {},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
var users = {
|
var users = {
|
||||||
name: 'portainer.users',
|
name: 'portainer.users',
|
||||||
url: '/users',
|
url: '/users',
|
||||||
|
@ -565,7 +553,6 @@ angular.module('portainer.app', []).config([
|
||||||
$stateRegistryProvider.register(support);
|
$stateRegistryProvider.register(support);
|
||||||
$stateRegistryProvider.register(supportProduct);
|
$stateRegistryProvider.register(supportProduct);
|
||||||
$stateRegistryProvider.register(tags);
|
$stateRegistryProvider.register(tags);
|
||||||
$stateRegistryProvider.register(updatePassword);
|
|
||||||
$stateRegistryProvider.register(users);
|
$stateRegistryProvider.register(users);
|
||||||
$stateRegistryProvider.register(user);
|
$stateRegistryProvider.register(user);
|
||||||
$stateRegistryProvider.register(teams);
|
$stateRegistryProvider.register(teams);
|
||||||
|
|
|
@ -8,7 +8,6 @@ class AuthenticationController {
|
||||||
$scope,
|
$scope,
|
||||||
$state,
|
$state,
|
||||||
$stateParams,
|
$stateParams,
|
||||||
$sanitize,
|
|
||||||
$window,
|
$window,
|
||||||
Authentication,
|
Authentication,
|
||||||
UserService,
|
UserService,
|
||||||
|
@ -26,7 +25,6 @@ class AuthenticationController {
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
this.$stateParams = $stateParams;
|
this.$stateParams = $stateParams;
|
||||||
this.$window = $window;
|
this.$window = $window;
|
||||||
this.$sanitize = $sanitize;
|
|
||||||
this.Authentication = Authentication;
|
this.Authentication = Authentication;
|
||||||
this.UserService = UserService;
|
this.UserService = UserService;
|
||||||
this.EndpointService = EndpointService;
|
this.EndpointService = EndpointService;
|
||||||
|
@ -55,7 +53,6 @@ class AuthenticationController {
|
||||||
this.postLoginSteps = this.postLoginSteps.bind(this);
|
this.postLoginSteps = this.postLoginSteps.bind(this);
|
||||||
|
|
||||||
this.oAuthLoginAsync = this.oAuthLoginAsync.bind(this);
|
this.oAuthLoginAsync = this.oAuthLoginAsync.bind(this);
|
||||||
this.retryLoginSanitizeAsync = this.retryLoginSanitizeAsync.bind(this);
|
|
||||||
this.internalLoginAsync = this.internalLoginAsync.bind(this);
|
this.internalLoginAsync = this.internalLoginAsync.bind(this);
|
||||||
|
|
||||||
this.authenticateUserAsync = this.authenticateUserAsync.bind(this);
|
this.authenticateUserAsync = this.authenticateUserAsync.bind(this);
|
||||||
|
@ -182,15 +179,6 @@ class AuthenticationController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async retryLoginSanitizeAsync(username, password) {
|
|
||||||
try {
|
|
||||||
await this.internalLoginAsync(this.$sanitize(username), this.$sanitize(password));
|
|
||||||
this.$state.go('portainer.updatePassword');
|
|
||||||
} catch (err) {
|
|
||||||
this.error(err, 'Invalid credentials');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async internalLoginAsync(username, password) {
|
async internalLoginAsync(username, password) {
|
||||||
await this.Authentication.login(username, password);
|
await this.Authentication.login(username, password);
|
||||||
await this.postLoginSteps();
|
await this.postLoginSteps();
|
||||||
|
@ -211,13 +199,7 @@ class AuthenticationController {
|
||||||
this.state.loginInProgress = true;
|
this.state.loginInProgress = true;
|
||||||
await this.internalLoginAsync(username, password);
|
await this.internalLoginAsync(username, password);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (this.state.permissionsError) {
|
this.error(err, 'Unable to login');
|
||||||
return;
|
|
||||||
}
|
|
||||||
// This login retry is necessary to avoid conflicts with databases
|
|
||||||
// containing users created before Portainer 1.19.2
|
|
||||||
// See https://github.com/portainer/portainer/issues/2199 for more info
|
|
||||||
await this.retryLoginSanitizeAsync(username, password);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
<div class="page-wrapper">
|
|
||||||
<!-- box -->
|
|
||||||
<div class="container simple-box">
|
|
||||||
<div class="col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1">
|
|
||||||
<!-- panel -->
|
|
||||||
<div class="panel panel-default">
|
|
||||||
<div class="panel-body">
|
|
||||||
<form class="simple-box-form form-horizontal" name="updatePasswordForm">
|
|
||||||
<!-- note -->
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-sm-12">
|
|
||||||
<span class="small text-muted">
|
|
||||||
Your password must be updated.
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- !note -->
|
|
||||||
<!-- current-password-input -->
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="current_password" class="col-sm-4 control-label text-left">Current password</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<input type="password" class="form-control" ng-model="formValues.CurrentPassword" id="current_password" auto-focus required />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- !current-password-input -->
|
|
||||||
<!-- new-password-input -->
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="password" class="col-sm-4 control-label text-left">Password</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<input type="password" class="form-control" ng-model="formValues.Password" id="password" required />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- !new-password-input -->
|
|
||||||
<!-- confirm-password-input -->
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="confirm_password" class="col-sm-4 control-label text-left">Confirm password</label>
|
|
||||||
<div class="col-sm-8">
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="password" class="form-control" ng-model="formValues.ConfirmPassword" id="confirm_password" required />
|
|
||||||
<span class="input-group-addon"
|
|
||||||
><i
|
|
||||||
ng-class="{ true: 'fa fa-check green-icon', false: 'fa fa-times red-icon' }[formValues.Password !== '' && formValues.Password === formValues.ConfirmPassword]"
|
|
||||||
aria-hidden="true"
|
|
||||||
></i
|
|
||||||
></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- !confirm-password-input -->
|
|
||||||
<!-- note -->
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-sm-12">
|
|
||||||
<span class="small text-muted">
|
|
||||||
<i ng-class="{ true: 'fa fa-check green-icon', false: 'fa fa-times red-icon' }[formValues.Password.length >= 8]" aria-hidden="true"></i>
|
|
||||||
The password must be at least 8 characters long
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- !note -->
|
|
||||||
<!-- actions -->
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-sm-12">
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="btn btn-primary btn-sm"
|
|
||||||
ng-disabled="state.actionInProgress || !updatePasswordForm.$valid || formValues.Password.length < 8 || formValues.Password !== formValues.ConfirmPassword"
|
|
||||||
ng-click="updatePassword()"
|
|
||||||
button-spinner="state.actionInProgress"
|
|
||||||
>
|
|
||||||
<span ng-hide="state.actionInProgress">Update password</span>
|
|
||||||
<span ng-show="state.actionInProgress">Updating password...</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- !actions -->
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- ! panel -->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- ! box -->
|
|
||||||
</div>
|
|
|
@ -1,44 +0,0 @@
|
||||||
angular.module('portainer.app').controller('UpdatePasswordController', [
|
|
||||||
'$scope',
|
|
||||||
'$state',
|
|
||||||
'$transition$',
|
|
||||||
'$sanitize',
|
|
||||||
'UserService',
|
|
||||||
'Authentication',
|
|
||||||
'Notifications',
|
|
||||||
function UpdatePasswordController($scope, $state, $transition$, $sanitize, UserService, Authentication, Notifications) {
|
|
||||||
$scope.formValues = {
|
|
||||||
CurrentPassword: '',
|
|
||||||
Password: '',
|
|
||||||
ConfirmPassword: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.state = {
|
|
||||||
actionInProgress: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.updatePassword = function () {
|
|
||||||
var userId = Authentication.getUserDetails().ID;
|
|
||||||
|
|
||||||
$scope.state.actionInProgress = true;
|
|
||||||
UserService.updateUserPassword(userId, $sanitize($scope.formValues.CurrentPassword), $scope.formValues.Password)
|
|
||||||
.then(function success() {
|
|
||||||
$state.go('portainer.home');
|
|
||||||
})
|
|
||||||
.catch(function error(err) {
|
|
||||||
Notifications.error('Failure', err, 'Unable to update password');
|
|
||||||
})
|
|
||||||
.finally(function final() {
|
|
||||||
$scope.state.actionInProgress = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function initView() {
|
|
||||||
if (!Authentication.isAuthenticated()) {
|
|
||||||
$state.go('portainer.auth');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
initView();
|
|
||||||
},
|
|
||||||
]);
|
|
Loading…
Reference in New Issue