DaanHoogland commented on code in PR #13209:
URL: https://github.com/apache/cloudstack/pull/13209#discussion_r4093503241
##########
server/src/main/java/org/apache/cloudstack/user/UserPasswordResetManagerImpl.java:
##########
@@ -222,6 +215,44 @@ public void setResetTokenAndSend(UserAccount userAccount) {
userAccount, userAccount.getAccountId(),
userAccount.getDomainId(), email, resetTokenExpiryTime);
}
+ private String getResetLinkDomain(String requestDomain) {
+ if (StringUtils.isNotBlank(requestDomain)) {
+ logger.debug("Searching for GUI theme with common name that
matches the request's domain: [{}]", requestDomain);
+ List<Long> commonNameDetails =
guiThemeDetailsDao.listGuiThemeIdsByCommonName(requestDomain);
+
+ if (!commonNameDetails.isEmpty()) {
+ logger.debug("GUI theme with ID {} was found; using request's
domain for password reset link.", commonNameDetails.get(0));
+ return requestDomain;
+ } else {
+ logger.debug("No GUI theme was found with a common name that
matches the request's domain.");
+ }
+ }
+
+ String configurationDomain = UserPasswordResetDomainURL.value();
+ if (StringUtils.isNotBlank(configurationDomain)) {
+ logger.debug("Defaulting reset link's domain to the [{}]
configuration value: [{}].", UserPasswordResetDomainURL.key(),
UserPasswordResetDomainURL.value());
+ return configurationDomain;
+ }
+
+ logger.debug("Using the first IP address in the [{}] configuration for
the reset password email domain because the [{}] configuration is not
defined.", ManagementServerAddresses.key(), UserPasswordResetDomainURL.key());
+ return ManagementServerAddresses.value().split(",")[0];
+ }
+
+ private String formatResetLinkDomain(String resetLinkDomain) {
+ String protocol = ServerProperties.isHttpsEnabled() ? "https" : "http";
+
+ if (InetAddressUtils.isIPv4Address(resetLinkDomain)) {
+ int port = protocol.equals("https") ?
ServerProperties.getHttpsPort() : ServerProperties.getHttpPort();
+ resetLinkDomain = resetLinkDomain + ":" + port;
+ }
+
+ if (!resetLinkDomain.startsWith("http")) {
+ resetLinkDomain = protocol + "://" + resetLinkDomain;
+ }
+
+ return resetLinkDomain.replaceAll("/+$", "");
+ }
Review Comment:
maybe use ai to generate these trivial tests (they excel at this)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]