On init of admin user use email from SSH key file as default email
If DEVELOPMENT_BECOME_ANY_ACCOUNT is used there is an init step for creating the initial admin user. When an SSH key file is given, use the comment of the key as default for the email address if it is a valid email. Change-Id: Ic91442d757065725b0ee6964f15b13ed1f8316fa Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
parent
897d92618c
commit
dddb61aa77
@ -76,9 +76,9 @@ public class InitAdminUser implements InitStep {
|
||||
Account.Id id = new Account.Id(db.nextAccountId());
|
||||
String username = ui.readString("admin", "username");
|
||||
String name = ui.readString("Administrator", "name");
|
||||
String email = readEmail();
|
||||
String httpPassword = ui.readString("secret", "HTTP password");
|
||||
AccountSshKey sshKey = readSshKey(id);
|
||||
String email = readEmail(sshKey);
|
||||
|
||||
AccountExternalId extUser =
|
||||
new AccountExternalId(id, new AccountExternalId.Key(
|
||||
@ -116,11 +116,22 @@ public class InitAdminUser implements InitStep {
|
||||
}
|
||||
}
|
||||
|
||||
private String readEmail() {
|
||||
String email = ui.readString("admin@example.com", "email");
|
||||
private String readEmail(AccountSshKey sshKey) {
|
||||
String defaultEmail = "admin@example.com";
|
||||
if (sshKey != null && sshKey.getComment() != null) {
|
||||
String c = sshKey.getComment().trim();
|
||||
if (EmailValidator.getInstance().isValid(c)) {
|
||||
defaultEmail = c;
|
||||
}
|
||||
}
|
||||
return readEmail(defaultEmail);
|
||||
}
|
||||
|
||||
private String readEmail(String defaultEmail) {
|
||||
String email = ui.readString(defaultEmail, "email");
|
||||
if (email != null && !EmailValidator.getInstance().isValid(email)) {
|
||||
ui.message("error: invalid email address\n");
|
||||
return readEmail();
|
||||
return readEmail(defaultEmail);
|
||||
}
|
||||
return email;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user