-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sanity checks on user join and before sending any notification …
…email (#586)
- Loading branch information
Showing
10 changed files
with
81 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
agate-core/src/main/java/org/obiba/agate/validator/EmailValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.obiba.agate.validator; | ||
|
||
import jakarta.mail.internet.InternetAddress; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import static java.util.regex.Pattern.CASE_INSENSITIVE; | ||
|
||
public final class EmailValidator { | ||
|
||
public static boolean isValid(String email) { | ||
if (email == null || email.trim().isEmpty()) { | ||
return false; | ||
} | ||
|
||
// Check length constraints | ||
if (email.length() > 254) { | ||
return false; // Email too long | ||
} | ||
|
||
String[] parts = email.split("@"); | ||
if (parts[0].length() > 64) { | ||
return false; // Local part too long | ||
} | ||
|
||
// Check for common issues | ||
if (email.contains("..") || email.startsWith(".") || email.endsWith(".")) { | ||
return false; // Invalid dot placement | ||
} | ||
|
||
try { | ||
InternetAddress emailAddr = new InternetAddress(email); | ||
emailAddr.validate(); | ||
return true; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
agate-core/src/main/java/org/obiba/agate/validator/NameValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.obiba.agate.validator; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public final class NameValidator { | ||
|
||
// International pattern supporting accents and other characters | ||
private static final Pattern INTERNATIONAL_NAME_PATTERN = Pattern.compile( | ||
"^[\\p{L}][\\p{L}\\s\\-']{1,49}$"); | ||
|
||
public static boolean isValid(String name) { | ||
if (name == null || name.isEmpty()) { | ||
return true; | ||
} | ||
|
||
return INTERNATIONAL_NAME_PATTERN.matcher(name).matches(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters