feat(login): allow-show-hide-password-in-login-screen EE-3885 (#7433)

* feat(login): allow show/hide password EE-3885
pull/6738/head
Ali 2022-08-10 16:07:24 +12:00 committed by GitHub
parent b6852b5e30
commit fb3a31a4fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 10 deletions

View File

@ -881,3 +881,11 @@ json-tree .branch-preview {
color: var(--text-link-hover-color); color: var(--text-link-hover-color);
text-decoration-line: underline; text-decoration-line: underline;
} }
input[style*='background-image: url("data:image/png'] + [data-cy='auth-passwordInputToggle'] {
right: 20px;
}
input[style*='background-image: url("data:image/png'] {
padding-right: 60px;
}

View File

@ -70,18 +70,33 @@
<!-- password input --> <!-- password input -->
<div ng-if="ctrl.state.showStandardLogin"> <div ng-if="ctrl.state.showStandardLogin">
<div class="pb-2">Password</div> <div class="pb-2">Password</div>
<div class="relative">
<input <input
id="password" id="password"
type="password" ng-attr-type="{{ ctrl.state.passwordInputType }}"
class="form-control" class="form-control pr-10"
name="password" name="password"
ng-model="ctrl.formValues.Password" ng-model="ctrl.formValues.Password"
autocomplete="off"
data-cy="auth-passwordInput" data-cy="auth-passwordInput"
placeholder="Enter your password" placeholder="Enter your password"
/> />
<button
data-cy="auth-passwordInputToggle"
type="button"
ng-click="ctrl.toggleShowPassword()"
class="absolute top-0 right-0 h-[34px] w-[50px] border-none flex justify-center items-center bg-transparent"
tooltip-append-to-body="true"
tooltip-placement="top"
tooltip-class="portainer-tooltip"
uib-tooltip="{{ ctrl.state.passwordInputType === 'password' ? 'Show password' : 'Hide password' }}"
>
<pr-icon icon="ctrl.state.passwordInputType === 'password' ? 'eye-off' : 'eye'" feather="true" size="'md'"></pr-icon>
</button>
</div>
</div> </div>
<div class="form-group" ng-if="ctrl.state.showStandardLogin"> <div class="form-group overflow-auto" ng-if="ctrl.state.showStandardLogin">
<!-- login button --> <!-- login button -->
<div class="col-sm-12 d-flex"> <div class="col-sm-12 d-flex">
<button <button

View File

@ -41,6 +41,7 @@ class AuthenticationController {
Password: '', Password: '',
}; };
this.state = { this.state = {
passwordInputType: 'password',
showOAuthLogin: false, showOAuthLogin: false,
showStandardLogin: false, showStandardLogin: false,
AuthenticationError: '', AuthenticationError: '',
@ -65,6 +66,16 @@ class AuthenticationController {
* UTILS FUNCTIONS SECTION * UTILS FUNCTIONS SECTION
*/ */
toggleShowPassword() {
this.state.passwordInputType = this.state.passwordInputType === 'text' ? 'password' : 'text';
}
// set the password input type to password, so that browser autofills don't treat the input as text
setPasswordInputType(inputType) {
this.state.passwordInputType = inputType;
document.getElementById('password').setAttribute('type', inputType);
}
logout(error) { logout(error) {
this.Authentication.logout(); this.Authentication.logout();
this.state.loginInProgress = false; this.state.loginInProgress = false;
@ -185,6 +196,7 @@ class AuthenticationController {
} }
authenticateUser() { authenticateUser() {
this.setPasswordInputType('password');
return this.$async(this.authenticateUserAsync); return this.$async(this.authenticateUserAsync);
} }