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