Skip to content

Commit

Permalink
feature: allow any locale
Browse files Browse the repository at this point in the history
  • Loading branch information
drallieiv committed Apr 28, 2021
1 parent da8d9f5 commit d5517db
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
public class KcMessageHandler implements MessageHandler {

private static final String POKEMON_DOMAIN = "@pokemon.com";
private static final String ACTIVATION_EXP = "https://club.pokemon.com/us/pokemon-trainer-club/activated/.*";
private static final String EMAIL_CHANGE_EXP = "https://club.pokemon.com/us/pokemon-trainer-club/email-change-approval/[a-zA-Z0-9]+";

private static final String ACTIVATION_EXP = "https://club.pokemon.com/([a-zA-Z\\-]+)/pokemon-trainer-club/activated/.*";
private static final String EMAIL_CHANGE_EXP = "https://club.pokemon.com/([a-zA-Z\\-]+)/pokemon-trainer-club/email-change-approval/[a-zA-Z0-9]+";

private Logger logger = LoggerFactory.getLogger(getClass());

Expand All @@ -47,6 +48,8 @@ public class KcMessageHandler implements MessageHandler {

@Setter
private boolean acceptAllFrom = false;

private String workLocale = "us";

private boolean handleActivation = true;

Expand Down Expand Up @@ -140,7 +143,15 @@ private boolean searchForActivationLink(String content) {
Matcher m = p.matcher(content);
if (m.find()) {
String activationLink = m.group(0);
logger.info("Activation link found for email {} : [{}]", this.recipient, activationLink);
String locale = m.group(1);

logger.info("Activation link found for email {} : [{}]", this.recipient, activationLink);

if(!locale.equals(workLocale)){
logger.info("Attemp converting activation link locale");
activationLink = activationLink.replace("/"+locale+"/", "/"+workLocale+"/");
logger.info("Activation link to use : [{}]", activationLink);
}

// Link activation, may be sync or async
activator.activateLink(new Activation(activationLink, this.recipient));
Expand All @@ -156,7 +167,15 @@ private boolean searchForEmailChangeRequestLink(String content) {
Matcher m = p.matcher(content);
if (m.find()) {
String emailChangeLink = m.group(0);
logger.info("Email Change Request link found for email {} : [{}]", this.recipient, emailChangeLink);
String locale = m.group(1);

logger.info("Email Change Request link found for email {} : [{}]", this.recipient, emailChangeLink);

if(!locale.equals(workLocale)){
logger.info("Attemp converting Email Change Request link locale");
emailChangeLink = emailChangeLink.replace("/"+locale+"/", "/"+workLocale+"/");
logger.info("Email Change Request link to use : [{}]", emailChangeLink);
}

// Email Change acceptation, may be sync or async
emailChanger.acceptChange(new EmailChangeRequest(emailChangeLink, this.recipient));
Expand Down

0 comments on commit d5517db

Please sign in to comment.