From 0f312495347f2c567cc608b34556b7be3f46a05a Mon Sep 17 00:00:00 2001 From: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Date: Sun, 1 Sep 2024 21:52:11 +0200 Subject: [PATCH 1/2] Update lint config (#813) --- .golangci.yml | 6 +++--- pkg/api/server.go | 1 + pkg/models/sql_translate.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index fc20ef940..c0daccb95 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,21 +14,21 @@ linters: - govet - ineffassign - staticcheck - - typecheck - unused + - typecheck # additional - gofmt - revive - dogsled - errorlint - exhaustive - - exportloopref + - copyloopvar - gocritic - #- goerr113 - misspell - noctx - rowserrcheck - sqlclosecheck + #- err113 linters-settings: revive: diff --git a/pkg/api/server.go b/pkg/api/server.go index b2914112a..8f3bbcf98 100644 --- a/pkg/api/server.go +++ b/pkg/api/server.go @@ -245,6 +245,7 @@ func makeTLSConfig() *tls.Config { } tlsConfig := &tls.Config{ Certificates: certs, + MinVersion: tls.VersionTLS13, } return tlsConfig diff --git a/pkg/models/sql_translate.go b/pkg/models/sql_translate.go index 870721869..289eb3220 100644 --- a/pkg/models/sql_translate.go +++ b/pkg/models/sql_translate.go @@ -49,7 +49,7 @@ func CopyFull(target interface{}, source interface{}) { case field.Type == sourceField.Type: // direct copy targetFieldValue.Set(sourceFieldValue) - case reflect.PtrTo(field.Type) == sourceField.Type: + case reflect.PointerTo(field.Type) == sourceField.Type: // source field is pointer, target field is value // if nil, then set to zero value, otherwise copy if sourceFieldValue.IsNil() { From 84bd28fd2985a0db6cdf86c3a7aac7b1a61f02b8 Mon Sep 17 00:00:00 2001 From: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Date: Sun, 1 Sep 2024 22:16:54 +0200 Subject: [PATCH 2/2] Redirect to previous page on login (#812) --- frontend/src/Login.tsx | 7 ++++++- frontend/src/Main.tsx | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/src/Login.tsx b/frontend/src/Login.tsx index c8965eb40..2c9fdd594 100644 --- a/frontend/src/Login.tsx +++ b/frontend/src/Login.tsx @@ -29,6 +29,7 @@ const Login: FC = () => { const navigate = useNavigate(); const [loginError, setLoginError] = useState(""); const msg = new URLSearchParams(location.search).get("msg"); + const redirect = new URLSearchParams(location.search).get("redirect"); const Auth = useContext(AuthContext); const { register, @@ -42,15 +43,19 @@ const Login: FC = () => { const onSubmit = async (formData: LoginFormData) => { setLoading(true); + const body = new FormData(); body.append("username", formData.username); body.append("password", formData.password); + const res = await fetch(`${getPlatformURL()}login`, { method: "POST", body, credentials: getCredentialsSetting(), }).finally(() => setLoading(false)); - if (res.ok) window.location.replace("/"); + + const returnURL = decodeURIComponent(redirect ?? "") || "/"; + if (res.ok) window.location.replace(returnURL); else setLoginError("Access denied"); }; diff --git a/frontend/src/Main.tsx b/frontend/src/Main.tsx index 2287ea328..6377b8ba6 100644 --- a/frontend/src/Main.tsx +++ b/frontend/src/Main.tsx @@ -50,7 +50,11 @@ const Main: FC = ({ children }) => { location.pathname !== ROUTE_FORGOT_PASSWORD && location.pathname !== ROUTE_RESET_PASSWORD ) { - navigate(ROUTE_LOGIN); + const redirect = + location.pathname === "/" + ? "" + : `?redirect=${encodeURIComponent(location.pathname)}`; + navigate(`${ROUTE_LOGIN}${redirect}`); } }, [loading, user, location, navigate]);