mirror of
https://github.com/yanislav-igonin/micrach
synced 2025-07-01 17:01:14 +03:00
feat: add captcha is active env var
This commit is contained in:
parent
d4f703acb6
commit
ea94ed15db
@ -4,4 +4,5 @@ SEED_DB=true
|
||||
IS_RATE_LIMITER_ENABLED=true
|
||||
THREADS_MAX_COUNT=50
|
||||
POSTGRES_URL=postgres://localhost/micrach?pool_max_conns=5
|
||||
THREAD_BUMP_LIMIT=500
|
||||
THREAD_BUMP_LIMIT=500
|
||||
IS_CAPTCHA_ACTIVE=true
|
@ -14,6 +14,7 @@ type AppConfig struct {
|
||||
IsRateLimiterEnabled bool
|
||||
ThreadsMaxCount int
|
||||
ThreadBumpLimit int
|
||||
IsCaptchaActive bool
|
||||
}
|
||||
|
||||
type DbConfig struct {
|
||||
@ -52,6 +53,7 @@ func getAppConfig() AppConfig {
|
||||
isRateLimiterEnabled := getValueOrDefaultBoolean(os.Getenv("IS_RATE_LIMITER_ENABLED"), true)
|
||||
threadsMaxCount := getValueOrDefaultInt(os.Getenv("THREADS_MAX_COUNT"), 50)
|
||||
threadBumpLimit := getValueOrDefaultInt(os.Getenv("THREAD_BUMP_LIMIT"), 500)
|
||||
isCaptchaActive := getValueOrDefaultBoolean(os.Getenv("IS_CAPTCHA_ACTIVE"), true)
|
||||
|
||||
return AppConfig{
|
||||
Env: env,
|
||||
@ -60,6 +62,7 @@ func getAppConfig() AppConfig {
|
||||
IsRateLimiterEnabled: isRateLimiterEnabled,
|
||||
ThreadsMaxCount: threadsMaxCount,
|
||||
ThreadBumpLimit: threadBumpLimit,
|
||||
IsCaptchaActive: isCaptchaActive,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,8 @@ func GetThreads(c *gin.Context) {
|
||||
PagesCount: pagesCount,
|
||||
Page: page,
|
||||
FormData: Repositories.HtmlFormData{
|
||||
CaptchaID: captchaID,
|
||||
CaptchaID: captchaID,
|
||||
IsCaptchaActive: Config.App.IsCaptchaActive,
|
||||
},
|
||||
}
|
||||
c.HTML(http.StatusOK, "index.html", htmlData)
|
||||
@ -87,8 +88,9 @@ func GetThread(c *gin.Context) {
|
||||
htmlData := Repositories.GetThreadHtmlData{
|
||||
Thread: thread,
|
||||
FormData: Repositories.HtmlFormData{
|
||||
FirstPostID: firstPost.ID,
|
||||
CaptchaID: captchaID,
|
||||
FirstPostID: firstPost.ID,
|
||||
CaptchaID: captchaID,
|
||||
IsCaptchaActive: Config.App.IsCaptchaActive,
|
||||
},
|
||||
}
|
||||
c.HTML(http.StatusOK, "thread.html", htmlData)
|
||||
|
@ -34,8 +34,9 @@ type File struct {
|
||||
|
||||
// post-form.html
|
||||
type HtmlFormData struct {
|
||||
FirstPostID int
|
||||
CaptchaID string
|
||||
FirstPostID int
|
||||
CaptchaID string
|
||||
IsCaptchaActive bool
|
||||
}
|
||||
|
||||
// thread.html
|
||||
|
@ -15,11 +15,13 @@
|
||||
<textarea class="form-control" id="postText" rows="5" placeholder="Text" name="text"></textarea>
|
||||
<input class="form-control" type="file" id="postFiles" multiple name="files">
|
||||
|
||||
{{ if .IsCaptchaActive }}
|
||||
<div class="captcha-container text-center">
|
||||
<img src="/captcha/{{ .CaptchaID }}" alt="Captcha">
|
||||
</div>
|
||||
<input class="form-control" type="hidden" name="captchaId" value="{{ .CaptchaID }}">
|
||||
<input class="form-control" id="postCaptcha" type="tel" pattern="\d+" placeholder="Captcha" name="captcha">
|
||||
{{ end }}
|
||||
|
||||
<div class="row">
|
||||
{{ if ne .FirstPostID 0 }}
|
||||
|
Loading…
Reference in New Issue
Block a user