KEYCLOAK-7047: Fix RegistrationEmailAsUsername and EditUserNameAllowed (#5122)

on personal info page.
This commit is contained in:
Stan Silvert 2018-04-04 09:31:38 -04:00 committed by GitHub
parent b3b81d6a76
commit 701c318b60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 6 deletions

View file

@ -89,6 +89,8 @@ public class AccountConsole {
map.put("authUrl", session.getContext().getContextPath()); map.put("authUrl", session.getContext().getContextPath());
map.put("baseUrl", session.getContext().getContextPath() + "/realms/" + realm.getName() + "/account"); map.put("baseUrl", session.getContext().getContextPath() + "/realms/" + realm.getName() + "/account");
map.put("realm", realm.getName()); map.put("realm", realm.getName());
map.put("isRegistrationEmailAsUsername", realm.isRegistrationEmailAsUsername());
map.put("isEditUserNameAllowed", realm.isEditUsernameAllowed());
map.put("resourceUrl", Urls.themeRoot(baseUri).getPath() + "/account/" + theme.getName()); map.put("resourceUrl", Urls.themeRoot(baseUri).getPath() + "/account/" + theme.getName());
map.put("resourceVersion", Version.RESOURCES_VERSION); map.put("resourceVersion", Version.RESOURCES_VERSION);

View file

@ -8,6 +8,8 @@
var baseUrl = '${baseUrl}'; var baseUrl = '${baseUrl}';
var realm = '${realm}'; var realm = '${realm}';
var resourceUrl = '${resourceUrl}'; var resourceUrl = '${resourceUrl}';
var isRegistrationEmailAsUsername = ${isRegistrationEmailAsUsername?c};
var isEditUserNameAllowed = ${isEditUserNameAllowed?c};
<#if referrer??> <#if referrer??>
var referrer = '${referrer}'; var referrer = '${referrer}';

View file

@ -15,13 +15,14 @@
<form #formGroup="ngForm" (ngSubmit)="saveAccount()" class="form-horizontal"> <form #formGroup="ngForm" (ngSubmit)="saveAccount()" class="form-horizontal">
<div class="form-group "> <div *ngIf="!isRegistrationEmailAsUsername" class="form-group ">
<div class="col-sm-2 col-md-2"> <div class="col-sm-2 col-md-2">
<label for="username" class="control-label">{{'username' | translate}}</label> <label for="username" class="control-label">{{'username' | translate}}</label><span *ngIf="isEditUserNameAllowed" class="required">*</span>
</div> </div>
<div class="col-sm-10 col-md-10"> <div class="col-sm-10 col-md-10">
<input type="text" class="form-control" id="username" name="username" disabled value="{{username}}" > <input *ngIf="isEditUserNameAllowed" type="text" class="form-control" required ngModel id="username" name="username" value="{{username}}" >
<span *ngIf="!isEditUserNameAllowed">{{ username }}</span>
</div> </div>
</div> </div>

View file

@ -20,18 +20,22 @@ import {FormGroup} from '@angular/forms';
import {AccountServiceClient} from '../../account-service/account.service'; import {AccountServiceClient} from '../../account-service/account.service';
declare const isRegistrationEmailAsUsername: boolean;
declare const isEditUserNameAllowed: boolean;
@Component({ @Component({
selector: 'app-account-page', selector: 'app-account-page',
templateUrl: './account-page.component.html', templateUrl: './account-page.component.html',
styleUrls: ['./account-page.component.css'] styleUrls: ['./account-page.component.css']
}) })
export class AccountPageComponent implements OnInit { export class AccountPageComponent implements OnInit {
private isRegistrationEmailAsUsername: boolean = isRegistrationEmailAsUsername;
private isEditUserNameAllowed: boolean = isEditUserNameAllowed;
@ViewChild('formGroup') private formGroup: FormGroup; @ViewChild('formGroup') private formGroup: FormGroup;
// using ordinary variable here // using ordinary variable here for case where username
// disabled fields not working properly with FormGroup // is not editable and not controlled by formGroup
// FormGroup.getRawValue() causes page refresh. Not sure why?
private username: string; private username: string;
constructor(private accountSvc: AccountServiceClient ) { constructor(private accountSvc: AccountServiceClient ) {