mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
change admin password after first login
This commit is contained in:
@@ -11,10 +11,15 @@ export class LoginCtrl {
|
||||
password: '',
|
||||
};
|
||||
|
||||
$scope.command = {};
|
||||
$scope.result = '';
|
||||
|
||||
contextSrv.sidemenu = false;
|
||||
|
||||
$scope.oauth = config.oauth;
|
||||
$scope.oauthEnabled = _.keys(config.oauth).length > 0;
|
||||
$scope.ldapEnabled = config.ldapEnabled;
|
||||
$scope.authProxyEnabled = config.authProxyEnabled;
|
||||
|
||||
$scope.disableLoginForm = config.disableLoginForm;
|
||||
$scope.disableUserSignUp = config.disableUserSignUp;
|
||||
@@ -39,6 +44,43 @@ export class LoginCtrl {
|
||||
}
|
||||
};
|
||||
|
||||
$scope.changeView = function() {
|
||||
let loginView = document.querySelector('#login-view');
|
||||
let changePasswordView = document.querySelector('#change-password-view');
|
||||
|
||||
loginView.className += ' add';
|
||||
setTimeout(() => {
|
||||
loginView.className += ' hidden';
|
||||
}, 250);
|
||||
setTimeout(() => {
|
||||
changePasswordView.classList.remove('hidden');
|
||||
}, 251);
|
||||
setTimeout(() => {
|
||||
changePasswordView.classList.remove('remove');
|
||||
}, 301);
|
||||
|
||||
setTimeout(() => {
|
||||
document.getElementById('newPassword').focus();
|
||||
}, 400);
|
||||
};
|
||||
|
||||
$scope.changePassword = function() {
|
||||
$scope.command.oldPassword = 'admin';
|
||||
|
||||
if ($scope.command.newPassword !== $scope.command.confirmNew) {
|
||||
$scope.appEvent('alert-warning', ['New passwords do not match', '']);
|
||||
return;
|
||||
}
|
||||
|
||||
backendSrv.put('/api/user/password', $scope.command).then(function() {
|
||||
$scope.toGrafana();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.skip = function() {
|
||||
$scope.toGrafana();
|
||||
};
|
||||
|
||||
$scope.loginModeChanged = function(newValue) {
|
||||
$scope.submitBtnText = newValue ? 'Log in' : 'Sign up';
|
||||
};
|
||||
@@ -65,18 +107,28 @@ export class LoginCtrl {
|
||||
}
|
||||
|
||||
backendSrv.post('/login', $scope.formModel).then(function(result) {
|
||||
var params = $location.search();
|
||||
$scope.result = result;
|
||||
|
||||
if (params.redirect && params.redirect[0] === '/') {
|
||||
window.location.href = config.appSubUrl + params.redirect;
|
||||
} else if (result.redirectUrl) {
|
||||
window.location.href = result.redirectUrl;
|
||||
} else {
|
||||
window.location.href = config.appSubUrl + '/';
|
||||
if ($scope.formModel.password !== 'admin' || $scope.ldapEnabled || $scope.authProxyEnabled) {
|
||||
$scope.toGrafana();
|
||||
return;
|
||||
}
|
||||
$scope.changeView();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.toGrafana = function() {
|
||||
var params = $location.search();
|
||||
|
||||
if (params.redirect && params.redirect[0] === '/') {
|
||||
window.location.href = config.appSubUrl + params.redirect;
|
||||
} else if ($scope.result.redirectUrl) {
|
||||
window.location.href = $scope.result.redirectUrl;
|
||||
} else {
|
||||
window.location.href = config.appSubUrl + '/';
|
||||
}
|
||||
};
|
||||
|
||||
$scope.init();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user