Skip to content

Commit

Permalink
KEYCLOAK-7047: Fix RegistrationEmailAsUsername and EditUserNameAllowed (
Browse files Browse the repository at this point in the history
keycloak#5122)

on personal info page.
  • Loading branch information
ssilvert authored Apr 4, 2018
1 parent b3b81d6 commit 701c318
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public Response getMainPage() throws URISyntaxException, IOException, FreeMarker
map.put("authUrl", session.getContext().getContextPath());
map.put("baseUrl", session.getContext().getContextPath() + "/realms/" + realm.getName() + "/account");
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("resourceVersion", Version.RESOURCES_VERSION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
var baseUrl = '${baseUrl}';
var realm = '${realm}';
var resourceUrl = '${resourceUrl}';
var isRegistrationEmailAsUsername = ${isRegistrationEmailAsUsername?c};
var isEditUserNameAllowed = ${isEditUserNameAllowed?c};
<#if referrer??>
var referrer = '${referrer}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ <h1>{{'editAccountHtmlTitle' | translate}}</h1>

<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">
<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 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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ import {FormGroup} from '@angular/forms';

import {AccountServiceClient} from '../../account-service/account.service';

declare const isRegistrationEmailAsUsername: boolean;
declare const isEditUserNameAllowed: boolean;

@Component({
selector: 'app-account-page',
templateUrl: './account-page.component.html',
styleUrls: ['./account-page.component.css']
})
export class AccountPageComponent implements OnInit {
private isRegistrationEmailAsUsername: boolean = isRegistrationEmailAsUsername;
private isEditUserNameAllowed: boolean = isEditUserNameAllowed;

@ViewChild('formGroup') private formGroup: FormGroup;

// using ordinary variable here
// disabled fields not working properly with FormGroup
// FormGroup.getRawValue() causes page refresh. Not sure why?
// using ordinary variable here for case where username
// is not editable and not controlled by formGroup
private username: string;

constructor(private accountSvc: AccountServiceClient ) {
Expand Down

0 comments on commit 701c318

Please sign in to comment.