From c76ea45ca9bcf71b569d53d324a01acc462f2a22 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Sun, 5 Sep 2021 22:50:15 +0300 Subject: [PATCH] Replaced relogin rejection with a notice and proper redirect. --- public/style.css | 4 ++++ public/themes/dark/theme.css | 1 + public/themes/light/theme.css | 1 + src/rawdata/scss/_notices.scss | 4 ++++ src/rawdata/scss/themes/dark/_variables.scss | 1 + src/rawdata/scss/themes/light/_variables.scss | 1 + src/website/auth.go | 10 ++++++---- 7 files changed, 18 insertions(+), 4 deletions(-) diff --git a/public/style.css b/public/style.css index 7fd5e99..1de12d9 100644 --- a/public/style.css +++ b/public/style.css @@ -9415,6 +9415,10 @@ span.icon-rss::before { background-color: #43a52f; background-color: var(--notice-success-color); } +.notice-warn { + background-color: #aa7d30; + background-color: var(--notice-warn-color); } + .notice-failure { background-color: #b42222; background-color: var(--notice-failure-color); } diff --git a/public/themes/dark/theme.css b/public/themes/dark/theme.css index 7a9a401..5a2b8fa 100644 --- a/public/themes/dark/theme.css +++ b/public/themes/dark/theme.css @@ -244,6 +244,7 @@ pre, code, .codeblock { --notice-lts-color: #2a681d; --notice-lts-reqd-color: #876327; --notice-success-color: #2a681d; + --notice-warn-color: #876327; --notice-failure-color: #7a2020; --optionbar-border-color: #333; --tab-background: #181818; diff --git a/public/themes/light/theme.css b/public/themes/light/theme.css index 50355b2..627dfdf 100644 --- a/public/themes/light/theme.css +++ b/public/themes/light/theme.css @@ -262,6 +262,7 @@ pre, code, .codeblock { --notice-lts-color: #43a52f; --notice-lts-reqd-color: #aa7d30; --notice-success-color: #43a52f; + --notice-warn-color: #aa7d30; --notice-failure-color: #b42222; --optionbar-border-color: #ccc; --tab-background: #fff; diff --git a/src/rawdata/scss/_notices.scss b/src/rawdata/scss/_notices.scss index 6b4efdf..3da627f 100644 --- a/src/rawdata/scss/_notices.scss +++ b/src/rawdata/scss/_notices.scss @@ -36,6 +36,10 @@ @include usevar(background-color, notice-success-color); } +.notice-warn { + @include usevar(background-color, notice-warn-color); +} + .notice-failure { @include usevar(background-color, notice-failure-color); } diff --git a/src/rawdata/scss/themes/dark/_variables.scss b/src/rawdata/scss/themes/dark/_variables.scss index 4ca3469..da90969 100644 --- a/src/rawdata/scss/themes/dark/_variables.scss +++ b/src/rawdata/scss/themes/dark/_variables.scss @@ -46,6 +46,7 @@ $vars: ( notice-lts-color: #2a681d, notice-lts-reqd-color: #876327, notice-success-color: #2a681d, + notice-warn-color: #876327, notice-failure-color: #7a2020, optionbar-border-color: #333, diff --git a/src/rawdata/scss/themes/light/_variables.scss b/src/rawdata/scss/themes/light/_variables.scss index e47035a..22a0ecb 100644 --- a/src/rawdata/scss/themes/light/_variables.scss +++ b/src/rawdata/scss/themes/light/_variables.scss @@ -46,6 +46,7 @@ $vars: ( notice-lts-color: #43a52f, notice-lts-reqd-color: #aa7d30, notice-success-color: #43a52f, + notice-warn-color: #aa7d30, notice-failure-color: #b42222, optionbar-border-color: #ccc, diff --git a/src/website/auth.go b/src/website/auth.go index 7f86f1e..57a6c30 100644 --- a/src/website/auth.go +++ b/src/website/auth.go @@ -41,10 +41,6 @@ func LoginPage(c *RequestContext) ResponseData { } func Login(c *RequestContext) ResponseData { - if c.CurrentUser != nil { - return RejectRequest(c, "You are already logged in.") - } - form, err := c.GetFormValues() if err != nil { return c.ErrorResponse(http.StatusBadRequest, NewSafeError(err, "request must contain form data")) @@ -55,6 +51,12 @@ func Login(c *RequestContext) ResponseData { redirect = "/" } + if c.CurrentUser != nil { + res := c.Redirect(redirect, http.StatusSeeOther) + res.AddFutureNotice("warn", fmt.Sprintf("You are already logged in as %s.", c.CurrentUser.Username)) + return res + } + username := form.Get("username") password := form.Get("password") if username == "" || password == "" {