generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support arithmetic captcha generation with random operators
- Loading branch information
Showing
9 changed files
with
141 additions
and
33 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
38 changes: 35 additions & 3 deletions
38
src/main/java/run/halo/comment/widget/SettingConfigGetter.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 |
---|---|---|
@@ -1,17 +1,49 @@ | ||
package run.halo.comment.widget; | ||
|
||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
import org.springframework.lang.NonNull; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.comment.widget.captcha.CaptchaType; | ||
|
||
public interface SettingConfigGetter { | ||
|
||
Mono<SecurityConfig> getSecurityConfig(); | ||
|
||
record SecurityConfig(CaptchaConfig captcha) { | ||
@Data | ||
@Accessors(chain = true) | ||
class SecurityConfig { | ||
@Getter(onMethod_ = @NonNull) | ||
private CaptchaConfig captcha; | ||
|
||
public SecurityConfig setCaptcha(CaptchaConfig captcha) { | ||
this.captcha = (captcha == null ? CaptchaConfig.empty() : captcha); | ||
return this; | ||
} | ||
|
||
public static SecurityConfig empty() { | ||
return new SecurityConfig(new CaptchaConfig(false)); | ||
return new SecurityConfig() | ||
.setCaptcha(CaptchaConfig.empty()); | ||
} | ||
} | ||
|
||
record CaptchaConfig(boolean anonymousCommentCaptcha) { | ||
@Data | ||
@Accessors(chain = true) | ||
class CaptchaConfig { | ||
|
||
private boolean anonymousCommentCaptcha; | ||
|
||
@Getter(onMethod_ = @NonNull) | ||
private CaptchaType type = CaptchaType.ALPHANUMERIC; | ||
|
||
public CaptchaConfig setType(CaptchaType type) { | ||
this.type = (type == null ? CaptchaType.ALPHANUMERIC : type); | ||
return this; | ||
} | ||
|
||
public static CaptchaConfig empty() { | ||
return new CaptchaConfig(); | ||
} | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/main/java/run/halo/comment/widget/captcha/CaptchaType.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,6 @@ | ||
package run.halo.comment.widget.captcha; | ||
|
||
public enum CaptchaType { | ||
ALPHANUMERIC, | ||
ARITHMETIC | ||
} |
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