mirror of
https://github.com/usememos/memos.git
synced 2024-11-28 14:23:15 +03:00
feat: add support for remember sign in (#2402)
This commit is contained in:
parent
37601e5d03
commit
0bfcff676c
@ -28,6 +28,7 @@ var (
|
||||
type SignIn struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Remember bool `json:"remember"`
|
||||
}
|
||||
|
||||
type SSOSignIn struct {
|
||||
@ -104,7 +105,12 @@ func (s *APIV1Service) SignIn(c echo.Context) error {
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, "Incorrect login credentials, please try again")
|
||||
}
|
||||
|
||||
accessToken, err := auth.GenerateAccessToken(user.Username, user.ID, time.Now().Add(auth.AccessTokenDuration), []byte(s.Secret))
|
||||
var expireAt time.Time
|
||||
if !signin.Remember {
|
||||
expireAt = time.Now().Add(auth.AccessTokenDuration)
|
||||
}
|
||||
|
||||
accessToken, err := auth.GenerateAccessToken(user.Username, user.ID, expireAt, []byte(s.Secret))
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("failed to generate tokens, err: %s", err)).SetInternal(err)
|
||||
}
|
||||
|
@ -17,10 +17,11 @@ export function vacuumDatabase() {
|
||||
return axios.post("/api/v1/system/vacuum");
|
||||
}
|
||||
|
||||
export function signin(username: string, password: string) {
|
||||
export function signin(username: string, password: string, remember: boolean) {
|
||||
return axios.post("/api/v1/auth/signin", {
|
||||
username,
|
||||
password,
|
||||
remember,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
"explore": "Explore",
|
||||
"sign-in": "Sign in",
|
||||
"sign-in-with": "Sign in with {{provider}}",
|
||||
"remember-me": "Remember me",
|
||||
"or": "or",
|
||||
"sign-up": "Sign up",
|
||||
"sign-out": "Sign out",
|
||||
|
@ -56,6 +56,7 @@
|
||||
"pin": "置顶",
|
||||
"preview": "预览",
|
||||
"profile": "个人资料",
|
||||
"remember-me": "保持登录",
|
||||
"rename": "改名",
|
||||
"reset": "重置",
|
||||
"resources": "资源库",
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Button, Divider, Input } from "@mui/joy";
|
||||
import { Button, Checkbox, Divider, Input } from "@mui/joy";
|
||||
import { useEffect, useState } from "react";
|
||||
import { toast } from "react-hot-toast";
|
||||
import { Link } from "react-router-dom";
|
||||
@ -19,6 +19,7 @@ const SignIn = () => {
|
||||
const mode = systemStatus.profile.mode;
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [remember, setRemember] = useState(true);
|
||||
const disablePasswordLogin = systemStatus.disablePasswordLogin;
|
||||
const [identityProviderList, setIdentityProviderList] = useState<IdentityProvider[]>([]);
|
||||
|
||||
@ -71,7 +72,7 @@ const SignIn = () => {
|
||||
|
||||
try {
|
||||
actionBtnLoadingState.setLoading();
|
||||
await api.signin(username, password);
|
||||
await api.signin(username, password, remember);
|
||||
const user = await userStore.doSignIn();
|
||||
if (user) {
|
||||
window.location.href = "/";
|
||||
@ -138,6 +139,9 @@ const SignIn = () => {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-row justify-start items-center w-full mt-6">
|
||||
<Checkbox label={t("common.remember-me")} checked={remember} onChange={(e) => setRemember(e.target.checked)} />
|
||||
</div>
|
||||
<div className="flex flex-row justify-end items-center w-full mt-6">
|
||||
<Button
|
||||
className="w-full"
|
||||
|
Loading…
Reference in New Issue
Block a user