Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
0bfcff67
Unverified
Commit
0bfcff67
authored
Oct 19, 2023
by
Athurg Gooth
Committed by
GitHub
Oct 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add support for remember sign in (#2402)
parent
37601e5d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
4 deletions
+17
-4
auth.go
api/v1/auth.go
+7
-1
api.ts
web/src/helpers/api.ts
+2
-1
en.json
web/src/locales/en.json
+1
-0
zh-Hans.json
web/src/locales/zh-Hans.json
+1
-0
SignIn.tsx
web/src/pages/SignIn.tsx
+6
-2
No files found.
api/v1/auth.go
View file @
0bfcff67
...
...
@@ -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
)
}
...
...
web/src/helpers/api.ts
View file @
0bfcff67
...
...
@@ -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
,
});
}
...
...
web/src/locales/en.json
View file @
0bfcff67
...
...
@@ -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"
,
...
...
web/src/locales/zh-Hans.json
View file @
0bfcff67
...
...
@@ -56,6 +56,7 @@
"pin"
:
"置顶"
,
"preview"
:
"预览"
,
"profile"
:
"个人资料"
,
"remember-me"
:
"保持登录"
,
"rename"
:
"改名"
,
"reset"
:
"重置"
,
"resources"
:
"资源库"
,
...
...
web/src/pages/SignIn.tsx
View file @
0bfcff67
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"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment