Pull creds into license form if available via settings

This commit is contained in:
mabashian
2019-08-29 15:15:50 -04:00
committed by Ryan Petrello
parent 900fcbf87e
commit 2474a3a2ea
4 changed files with 74 additions and 37 deletions

View File

@@ -183,3 +183,9 @@
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
} }
.License-label {
color: @field-label;
font-weight: 400;
margin-top: 10px;
}

View File

@@ -7,11 +7,10 @@
import {N_} from "../i18n"; import {N_} from "../i18n";
export default export default
['Wait', '$state', '$scope', '$rootScope', ['Wait', '$state', '$scope', '$rootScope', 'ProcessErrors', 'CheckLicense', 'moment', 'Rest',
'ProcessErrors', 'CheckLicense', 'moment','$window', '$window', 'ConfigService', 'pendoService', 'insightsEnablementService', 'i18n', 'config', 'GetBasePath',
'ConfigService', 'pendoService', 'insightsEnablementService', 'i18n', 'config', function(Wait, $state, $scope, $rootScope, ProcessErrors, CheckLicense, moment, Rest,
function(Wait, $state, $scope, $rootScope, ProcessErrors, CheckLicense, moment, $window, ConfigService, pendoService, insightsEnablementService, i18n, config, GetBasePath) {
$window, ConfigService, pendoService, insightsEnablementService, i18n, config) {
const calcDaysRemaining = function(seconds) { const calcDaysRemaining = function(seconds) {
// calculate the number of days remaining on the license // calculate the number of days remaining on the license
@@ -34,11 +33,10 @@ export default
const reset = function() { const reset = function() {
document.getElementById('License-form').reset(); document.getElementById('License-form').reset();
$scope.rhPassword = null; $scope.rhCreds = {};
$scope.rhUsername = null;
}; };
const init = function(config) { const initVars = (config) => {
// license/license.partial.html compares fileName // license/license.partial.html compares fileName
$scope.fileName = N_("No file selected."); $scope.fileName = N_("No file selected.");
@@ -59,8 +57,29 @@ export default
pendo: true, pendo: true,
insights: true insights: true
}; };
$scope.rhCreds = {};
}; };
const init = (config) => {
Rest.setUrl(`${GetBasePath('settings')}system/`);
Rest.get()
.then(({data}) => {
initVars(config);
if (data.REDHAT_USERNAME && data.REDHAT_USERNAME !== "") {
$scope.rhCreds.username = data.REDHAT_USERNAME;
}
if (data.REDHAT_PASSWORD && data.REDHAT_PASSWORD !== "") {
$scope.rhCreds.password = data.REDHAT_PASSWORD;
$scope.hasPasswordFromSettings = true;
}
}).catch(() => {
initVars(config);
});
};
init(config); init(config);
$scope.getKey = function(event) { $scope.getKey = function(event) {
@@ -89,7 +108,7 @@ export default
// HTML5 spec doesn't provide a way to customize file input css // HTML5 spec doesn't provide a way to customize file input css
// So we hide the default input, show our own, and simulate clicks to the hidden input // So we hide the default input, show our own, and simulate clicks to the hidden input
$scope.fakeClick = function() { $scope.fakeClick = function() {
if($scope.user_is_superuser && (!$scope.rhUsername || $scope.rhUsername === '') && (!$scope.rhPassword || $scope.rhPassword === '')) { if($scope.user_is_superuser && (!$scope.rhCreds.username || $scope.rhCreds.username === '') && (!$scope.rhCreds.password || $scope.rhCreds.password === '')) {
$('#License-file').click(); $('#License-file').click();
} }
}; };
@@ -104,10 +123,10 @@ export default
let payload = {}; let payload = {};
if ($scope.newLicense.file) { if ($scope.newLicense.file) {
payload = $scope.newLicense.file; payload = $scope.newLicense.file;
} else if ($scope.rhUsername && $scope.rhPassword) { } else if ($scope.rhCreds.username && $scope.rhCreds.password) {
payload = { payload = {
rh_password: $scope.rhPassword, rh_password: $scope.rhCreds.password,
rh_username: $scope.rhUsername rh_username: $scope.rhCreds.username
}; };
} }
CheckLicense.post(payload, $scope.newLicense.eula) CheckLicense.post(payload, $scope.newLicense.eula)

View File

@@ -8,7 +8,7 @@
<div class="License-field--label" translate>License</div> <div class="License-field--label" translate>License</div>
<div class="License-field--content"> <div class="License-field--content">
<span class="License-greenText" ng-show='compliant'><i class="fa fa-circle License-greenText"></i><translate>Valid License</translate></span> <span class="License-greenText" ng-show='compliant'><i class="fa fa-circle License-greenText"></i><translate>Valid License</translate></span>
<span class="License-redText" ng-show='!compliant'><i class="fa fa-circle License-redText"></i><translate>Invalid License</translate></span> <span class="License-redText" ng-show='compliant !== undefined && !compliant'><i class="fa fa-circle License-redText"></i><translate>Invalid License</translate></span>
</div> </div>
</div> </div>
<div class="License-field"> <div class="License-field">
@@ -94,7 +94,7 @@
2 2
</span> </span>
<span class="License-helperText"> <span class="License-helperText">
<translate>Choose your license file or provide your Red Hat subscription credentials, agree to the End User License Agreement, and click submit.</translate> <translate>Choose your license file or provide your Red Hat customer credentials, agree to the End User License Agreement, and click submit.</translate>
</span> </span>
</div> </div>
@@ -108,7 +108,7 @@
<div class="d-block w-100"> <div class="d-block w-100">
<div class="License-helperText License-licenseStepHelp" translate>Upload a license file</div> <div class="License-helperText License-licenseStepHelp" translate>Upload a license file</div>
<div class="License-filePicker"> <div class="License-filePicker">
<span class="btn btn-primary" ng-click="fakeClick()" ng-disabled="!user_is_superuser || (rhUsername && rhUsername.length > 0) || (rhPassword && rhPassword.length > 0)" translate>Browse</span> <span class="btn btn-primary" ng-click="fakeClick()" ng-disabled="!user_is_superuser || (rhCreds.username && rhCreds.username.length > 0) || (rhCreds.password && rhCreds.password.length > 0)" translate>Browse</span>
<span class="License-fileName" ng-class="{'License-helperText' : fileName == 'No file selected.'}">{{fileName|translate}}</span> <span class="License-fileName" ng-class="{'License-helperText' : fileName == 'No file selected.'}">{{fileName|translate}}</span>
<input id="License-file" class="form-control" type="file" file-on-change="getKey"/> <input id="License-file" class="form-control" type="file" file-on-change="getKey"/>
</div> </div>
@@ -121,15 +121,26 @@
</div> </div>
<div class="License-file--right"> <div class="License-file--right">
<div class="d-block w-100"> <div class="d-block w-100">
<div class="License-helperText License-licenseStepHelp" translate>Provide your Red Hat subscription credentials</div> <div class="License-helperText License-licenseStepHelp" translate>Provide your Red Hat customer credentials</div>
<div> <div>
<label class="LoginModal-label d-block" translate>USERNAME</label> <label class="License-label d-block" translate>USERNAME</label>
<input class="w-100" type="text" ng-model="rhUsername" ng-disabled="newLicense.file" /> <input class="form-control Form-textInput" type="text" ng-model="rhCreds.username" ng-disabled="!user_is_superuser || newLicense.file" />
</div> </div>
<div> <div>
<label class="LoginModal-label d-block" translate>PASSWORD</label> <label class="License-label d-block" translate>PASSWORD</label>
<input class="w-100" type="password" ng-model="rhPassword" ng-disabled="newLicense.file" /> <div class="input-group Form-mixedInputGroup" ng-if="hasPasswordFromSettings">
<span class="input-group-btn input-group-prepend">
<button aw-password-toggle id="rh_license_pass_show_input_button" class="btn btn-default show_input_button Form-passwordButton" type="button" ng-disabled="!user_is_superuser || newLicense.file" aw-tool-tip="Toggle the display of plaintext." aw-tip-placement="top">Hide</button>
</span>
<input id="rh_license_pass" class="form-control Form-textInput" type="text" ng-model="rhCreds.password" ng-disabled="!user_is_superuser || newLicense.file" />
</div> </div>
<div class="input-group Form-mixedInputGroup" ng-if="!hasPasswordFromSettings">
<span class="input-group-btn input-group-prepend">
<button aw-password-toggle id="rh_license_pass_show_input_button" class="btn btn-default show_input_button Form-passwordButton" type="button" ng-disabled="!user_is_superuser || newLicense.file" aw-tool-tip="Toggle the display of plaintext." aw-tip-placement="top">Show</button>
</span>
<input id="rh_license_pass" class="form-control Form-textInput" type="password" ng-model="rhCreds.password" ng-disabled="!user_is_superuser || newLicense.file" />
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@@ -167,7 +178,7 @@
</div> </div>
</div> </div>
<div> <div>
<button ng-click="submit()" class="btn btn-success pull-right" ng-disabled="(!newLicense.file && (!rhUsername || !rhPassword)) || (newLicense.file && newLicense.file.license_key == null) || newLicense.eula == null || !user_is_superuser" translate>Submit</button> <button ng-click="submit()" class="btn btn-success pull-right" ng-disabled="(!newLicense.file && (!rhCreds.username || !rhCreds.password)) || (newLicense.file && newLicense.file.license_key == null) || newLicense.eula == null || !user_is_superuser" translate>Submit</button>
<span ng-show="success == true" class="License-greenText License-submit--success pull-right" translate>Save successful!</span> <span ng-show="success == true" class="License-greenText License-submit--success pull-right" translate>Save successful!</span>
<span ng-show="licenseError == true" class="License-redText License-submit--failure pull-right" translate>Invalid License - Save unsuccessful</span> <span ng-show="licenseError == true" class="License-redText License-submit--failure pull-right" translate>Invalid License - Save unsuccessful</span>
</div> </div>

View File

@@ -17,30 +17,31 @@ export default {
ncyBreadcrumb: { ncyBreadcrumb: {
label: N_('LICENSE') label: N_('LICENSE')
}, },
onEnter: ['$state', 'ConfigService', (state, configService) => { onEnter: ['$state', 'ConfigService', (state, configService) => {
return configService.getConfig() return configService.getConfig()
.then(config => { .then(config => {
if (_.get(config, 'license_info.license_type') === 'open') { if (_.get(config, 'license_info.license_type') === 'open') {
return state.go('setup'); return state.go('setup');
} }
}); });
}], }],
resolve: { resolve: {
features: ['CheckLicense', '$rootScope', features: ['CheckLicense', '$rootScope',
function(CheckLicense, $rootScope) { function(CheckLicense, $rootScope) {
if($rootScope.licenseMissing === undefined){ if($rootScope.licenseMissing === undefined){
return CheckLicense.notify(); return CheckLicense.notify();
} }
}
}], ],
config: ['ConfigService', 'CheckLicense', '$rootScope', config: ['ConfigService', 'CheckLicense', '$rootScope',
function(ConfigService, CheckLicense, $rootScope) { function(ConfigService, CheckLicense, $rootScope) {
ConfigService.delete(); ConfigService.delete();
return ConfigService.getConfig() return ConfigService.getConfig()
.then(function(config){ .then(function(config){
$rootScope.licenseMissing = (CheckLicense.valid(config.license_info) === false) ? true : false; $rootScope.licenseMissing = (CheckLicense.valid(config.license_info) === false) ? true : false;
return config; return config;
}); });
}] }
]
}, },
}; };