Require the user to confirm setting the username

Once the username has been set, it cannot be edited.  This can cause
problems for users who accidentally set the wrong username.

Add a confirmation dialog that warns the user that setting the username
is permanent.  Only set the username when the user confirms.

Bug: Issue 2654
Change-Id: Id8fb7f8e3d984205a60363863fd2ec925ceae105
This commit is contained in:
David Pursehouse
2014-05-13 11:36:55 +09:00
parent 5be2008cb6
commit 21a4dbd047
3 changed files with 21 additions and 2 deletions

View File

@@ -62,6 +62,8 @@ public interface AccountConstants extends Constants {
String userName();
String password();
String buttonSetUserName();
String confirmSetUserNameTitle();
String confirmSetUserName();
String buttonChangeUserName();
String buttonClearPassword();
String buttonGeneratePassword();

View File

@@ -42,6 +42,8 @@ buttonAddSshKey = Add
userName = Username
password = Password
buttonSetUserName = Select Username
confirmSetUserNameTitle = Confirm Setting the Username
confirmSetUserName Setting the Username is permanent. Are you sure?
buttonChangeUserName = Change Username
buttonClearPassword = Clear Password
buttonGeneratePassword = Generate Password

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.client.account;
import com.google.gerrit.client.ConfirmationCallback;
import com.google.gerrit.client.ConfirmationDialog;
import com.google.gerrit.client.ErrorDialog;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.rpc.GerritCallback;
@@ -31,6 +33,7 @@ import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwtexpui.clippy.client.CopyableLabel;
import com.google.gwtexpui.globalkey.client.NpTextBox;
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
import com.google.gwtjsonrpc.common.VoidResult;
class UsernameField extends Composite {
@@ -59,7 +62,7 @@ class UsernameField extends Composite {
@Override
public void onKeyPress(KeyPressEvent event) {
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
doSetUserName();
confirmSetUserName();
}
}
});
@@ -70,7 +73,7 @@ class UsernameField extends Composite {
setUserName.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
doSetUserName();
confirmSetUserName();
}
});
new OnEditEnabler(setUserName, userNameTxt);
@@ -86,6 +89,18 @@ class UsernameField extends Composite {
return Gerrit.getConfig().canEdit(Account.FieldName.USER_NAME);
}
private void confirmSetUserName() {
new ConfirmationDialog(
Util.C.confirmSetUserNameTitle(),
new SafeHtmlBuilder().append(Util.C.confirmSetUserName()),
new ConfirmationCallback() {
@Override
public void onOk() {
doSetUserName();
}
}).center();
}
private void doSetUserName() {
if (!canEditUserName()) {
return;