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
01ff3f73
Commit
01ff3f73
authored
Oct 05, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update auth pages
parent
8aae0d00
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
205 additions
and
94 deletions
+205
-94
Header.tsx
web/src/components/Header.tsx
+2
-2
SignIn.tsx
web/src/pages/SignIn.tsx
+57
-86
SignUp.tsx
web/src/pages/SignUp.tsx
+135
-0
index.tsx
web/src/router/index.tsx
+11
-6
No files found.
web/src/components/Header.tsx
View file @
01ff3f73
...
@@ -70,7 +70,7 @@ const Header = () => {
...
@@ -70,7 +70,7 @@ const Header = () => {
title
:
t
(
"common.settings"
),
title
:
t
(
"common.settings"
),
icon
:
<
Icon
.
Settings
className=
"mr-3 w-6 h-auto opacity-70"
/>,
icon
:
<
Icon
.
Settings
className=
"mr-3 w-6 h-auto opacity-70"
/>,
};
};
const
auth
NavLink
:
NavLinkItem
=
{
const
signIn
NavLink
:
NavLinkItem
=
{
id
:
"header-auth"
,
id
:
"header-auth"
,
path
:
"/auth"
,
path
:
"/auth"
,
title
:
t
(
"common.sign-in"
),
title
:
t
(
"common.sign-in"
),
...
@@ -79,7 +79,7 @@ const Header = () => {
...
@@ -79,7 +79,7 @@ const Header = () => {
const
navLinks
:
NavLinkItem
[]
=
user
const
navLinks
:
NavLinkItem
[]
=
user
?
[
homeNavLink
,
dailyReviewNavLink
,
resourcesNavLink
,
exploreNavLink
,
archivedNavLink
,
settingNavLink
]
?
[
homeNavLink
,
dailyReviewNavLink
,
resourcesNavLink
,
exploreNavLink
,
archivedNavLink
,
settingNavLink
]
:
[
exploreNavLink
,
auth
NavLink
];
:
[
exploreNavLink
,
signIn
NavLink
];
return
(
return
(
<
div
<
div
...
...
web/src/pages/
Auth
.tsx
→
web/src/pages/
SignIn
.tsx
View file @
01ff3f73
import
{
Button
,
Divider
,
Input
}
from
"@mui/joy"
;
import
{
Button
,
Divider
,
Input
}
from
"@mui/joy"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
toast
}
from
"react-hot-toast"
;
import
{
toast
}
from
"react-hot-toast"
;
import
{
Link
}
from
"react-router-dom"
;
import
AppearanceSelect
from
"@/components/AppearanceSelect"
;
import
AppearanceSelect
from
"@/components/AppearanceSelect"
;
import
Icon
from
"@/components/Icon"
;
import
LocaleSelect
from
"@/components/LocaleSelect"
;
import
LocaleSelect
from
"@/components/LocaleSelect"
;
import
*
as
api
from
"@/helpers/api"
;
import
*
as
api
from
"@/helpers/api"
;
import
{
absolutifyLink
}
from
"@/helpers/utils"
;
import
{
absolutifyLink
}
from
"@/helpers/utils"
;
...
@@ -10,7 +10,7 @@ import useLoading from "@/hooks/useLoading";
...
@@ -10,7 +10,7 @@ import useLoading from "@/hooks/useLoading";
import
{
useGlobalStore
,
useUserStore
}
from
"@/store/module"
;
import
{
useGlobalStore
,
useUserStore
}
from
"@/store/module"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
const
Auth
=
()
=>
{
const
SignIn
=
()
=>
{
const
t
=
useTranslate
();
const
t
=
useTranslate
();
const
globalStore
=
useGlobalStore
();
const
globalStore
=
useGlobalStore
();
const
userStore
=
useUserStore
();
const
userStore
=
useUserStore
();
...
@@ -57,11 +57,7 @@ const Auth = () => {
...
@@ -57,11 +57,7 @@ const Auth = () => {
const
handleFormSubmit
=
(
e
:
React
.
FormEvent
<
HTMLFormElement
>
)
=>
{
const
handleFormSubmit
=
(
e
:
React
.
FormEvent
<
HTMLFormElement
>
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
if
(
systemStatus
?.
host
)
{
handleSignInButtonClick
();
handleSignInButtonClick
();
}
else
{
handleSignUpButtonClick
();
}
};
};
const
handleSignInButtonClick
=
async
()
=>
{
const
handleSignInButtonClick
=
async
()
=>
{
...
@@ -89,31 +85,6 @@ const Auth = () => {
...
@@ -89,31 +85,6 @@ const Auth = () => {
actionBtnLoadingState
.
setFinish
();
actionBtnLoadingState
.
setFinish
();
};
};
const
handleSignUpButtonClick
=
async
()
=>
{
if
(
username
===
""
||
password
===
""
)
{
return
;
}
if
(
actionBtnLoadingState
.
isLoading
)
{
return
;
}
try
{
actionBtnLoadingState
.
setLoading
();
await
api
.
signup
(
username
,
password
);
const
user
=
await
userStore
.
doSignIn
();
if
(
user
)
{
window
.
location
.
href
=
"/"
;
}
else
{
toast
.
error
(
t
(
"message.signup-failed"
));
}
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toast
.
error
(
error
.
response
.
data
.
message
||
error
.
message
||
t
(
"message.signup-failed"
));
}
actionBtnLoadingState
.
setFinish
();
};
const
handleSignInWithIdentityProvider
=
async
(
identityProvider
:
IdentityProvider
)
=>
{
const
handleSignInWithIdentityProvider
=
async
(
identityProvider
:
IdentityProvider
)
=>
{
const
stateQueryParameter
=
`auth.signin.
${
identityProvider
.
name
}
-
${
identityProvider
.
id
}
`
;
const
stateQueryParameter
=
`auth.signin.
${
identityProvider
.
name
}
-
${
identityProvider
.
id
}
`
;
if
(
identityProvider
.
type
===
"OAUTH2"
)
{
if
(
identityProvider
.
type
===
"OAUTH2"
)
{
...
@@ -132,13 +103,16 @@ const Auth = () => {
...
@@ -132,13 +103,16 @@ const Auth = () => {
<
div
className=
"flex flex-row justify-center items-center w-full h-full dark:bg-zinc-800"
>
<
div
className=
"flex flex-row justify-center items-center w-full h-full dark:bg-zinc-800"
>
<
div
className=
"w-80 max-w-full h-full py-4 flex flex-col justify-start items-center"
>
<
div
className=
"w-80 max-w-full h-full py-4 flex flex-col justify-start items-center"
>
<
div
className=
"w-full py-4 grow flex flex-col justify-center items-center"
>
<
div
className=
"w-full py-4 grow flex flex-col justify-center items-center"
>
<
div
className=
"w-full flex flex-
col justify-center items-center mb-2
"
>
<
div
className=
"w-full flex flex-
row justify-center items-center mb-6
"
>
<
img
className=
"h-
20
w-auto rounded-full shadow"
src=
{
systemStatus
.
customizedProfile
.
logoUrl
}
alt=
""
/>
<
img
className=
"h-
14
w-auto rounded-full shadow"
src=
{
systemStatus
.
customizedProfile
.
logoUrl
}
alt=
""
/>
<
p
className=
"m
t-2 text-3
xl text-black opacity-80 dark:text-gray-200"
>
{
systemStatus
.
customizedProfile
.
name
}
</
p
>
<
p
className=
"m
l-4 text-5
xl text-black opacity-80 dark:text-gray-200"
>
{
systemStatus
.
customizedProfile
.
name
}
</
p
>
</
div
>
</
div
>
{
!
disablePasswordLogin
&&
(
{
!
disablePasswordLogin
&&
(
<>
<
form
className=
"w-full mt-2"
onSubmit=
{
handleFormSubmit
}
>
<
form
className=
"w-full mt-2"
onSubmit=
{
handleFormSubmit
}
>
<
div
className=
"flex flex-col justify-start items-start w-full gap-4"
>
<
div
className=
"flex flex-col justify-start items-start w-full gap-4"
>
<
div
className=
"w-full flex flex-col justify-start items-start gap-2"
>
<
span
className=
"leading-8 text-gray-600"
>
{
t
(
"common.username"
)
}
</
span
>
<
Input
<
Input
className=
"w-full"
className=
"w-full"
size=
"lg"
size=
"lg"
...
@@ -149,6 +123,9 @@ const Auth = () => {
...
@@ -149,6 +123,9 @@ const Auth = () => {
onChange=
{
handleUsernameInputChanged
}
onChange=
{
handleUsernameInputChanged
}
required
required
/>
/>
</
div
>
<
div
className=
"w-full flex flex-col justify-start items-start gap-2"
>
<
span
className=
"leading-8 text-gray-600"
>
{
t
(
"common.password"
)
}
</
span
>
<
Input
<
Input
className=
"w-full"
className=
"w-full"
size=
"lg"
size=
"lg"
...
@@ -160,35 +137,29 @@ const Auth = () => {
...
@@ -160,35 +137,29 @@ const Auth = () => {
required
required
/>
/>
</
div
>
</
div
>
</
div
>
<
div
className=
"flex flex-row justify-end items-center w-full mt-6"
>
<
div
className=
"flex flex-row justify-end items-center w-full mt-6"
>
{
actionBtnLoadingState
.
isLoading
&&
<
Icon
.
Loader
className=
"w-4 h-auto mr-2 animate-spin dark:text-gray-300"
/>
}
<
Button
{
!
systemStatus
.
host
?
(
className=
"w-full"
<
Button
disabled=
{
actionBtnLoadingState
.
isLoading
}
onClick=
{
handleSignUpButtonClick
}
>
type=
"submit"
{
t
(
"common.sign-up"
)
}
disabled=
{
actionBtnLoadingState
.
isLoading
}
</
Button
>
loading=
{
actionBtnLoadingState
.
isLoading
}
)
:
(
onClick=
{
handleSignInButtonClick
}
<>
>
{
systemStatus
?.
allowSignUp
&&
(
<>
<
Button
variant=
{
"plain"
}
disabled=
{
actionBtnLoadingState
.
isLoading
}
onClick=
{
handleSignUpButtonClick
}
>
{
t
(
"common.sign-up"
)
}
</
Button
>
<
span
className=
"mr-2 font-mono text-gray-200"
>
/
</
span
>
</>
)
}
<
Button
type=
"submit"
disabled=
{
actionBtnLoadingState
.
isLoading
}
onClick=
{
handleSignInButtonClick
}
>
{
t
(
"common.sign-in"
)
}
{
t
(
"common.sign-in"
)
}
</
Button
>
</
Button
>
</>
)
}
</
div
>
</
div
>
</
form
>
</
form
>
)
}
{
systemStatus
.
allowSignUp
&&
(
{
!
systemStatus
.
host
&&
(
<
p
className=
"w-full mt-4 text-sm"
>
<
p
className=
"w-full inline-block float-right text-sm mt-4 text-gray-500 text-right whitespace-pre-wrap"
>
<
span
className=
"dark:text-gray-500"
>
{
"Don't have an account yet?"
}
</
span
>
{
t
(
"auth.host-tip"
)
}
<
Link
to=
"/auth/signup"
className=
"cursor-pointer ml-2 text-blue-600 hover:underline"
>
{
t
(
"common.sign-up"
)
}
</
Link
>
</
p
>
</
p
>
)
}
)
}
</>
)
}
{
identityProviderList
.
length
>
0
&&
(
{
identityProviderList
.
length
>
0
&&
(
<>
<>
{
!
disablePasswordLogin
&&
<
Divider
className=
"!my-4"
>
{
t
(
"common.or"
)
}
</
Divider
>
}
{
!
disablePasswordLogin
&&
<
Divider
className=
"!my-4"
>
{
t
(
"common.or"
)
}
</
Divider
>
}
...
@@ -218,4 +189,4 @@ const Auth = () => {
...
@@ -218,4 +189,4 @@ const Auth = () => {
);
);
};
};
export
default
Auth
;
export
default
SignIn
;
web/src/pages/SignUp.tsx
0 → 100644
View file @
01ff3f73
import
{
Button
,
Input
}
from
"@mui/joy"
;
import
{
useState
}
from
"react"
;
import
{
toast
}
from
"react-hot-toast"
;
import
{
Link
}
from
"react-router-dom"
;
import
AppearanceSelect
from
"@/components/AppearanceSelect"
;
import
LocaleSelect
from
"@/components/LocaleSelect"
;
import
*
as
api
from
"@/helpers/api"
;
import
useLoading
from
"@/hooks/useLoading"
;
import
{
useGlobalStore
,
useUserStore
}
from
"@/store/module"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
const
SignUp
=
()
=>
{
const
t
=
useTranslate
();
const
globalStore
=
useGlobalStore
();
const
userStore
=
useUserStore
();
const
actionBtnLoadingState
=
useLoading
(
false
);
const
{
appearance
,
locale
,
systemStatus
}
=
globalStore
.
state
;
const
[
username
,
setUsername
]
=
useState
(
""
);
const
[
password
,
setPassword
]
=
useState
(
""
);
const
handleUsernameInputChanged
=
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
text
=
e
.
target
.
value
as
string
;
setUsername
(
text
);
};
const
handlePasswordInputChanged
=
(
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
text
=
e
.
target
.
value
as
string
;
setPassword
(
text
);
};
const
handleLocaleSelectChange
=
(
locale
:
Locale
)
=>
{
globalStore
.
setLocale
(
locale
);
};
const
handleAppearanceSelectChange
=
(
appearance
:
Appearance
)
=>
{
globalStore
.
setAppearance
(
appearance
);
};
const
handleFormSubmit
=
(
e
:
React
.
FormEvent
<
HTMLFormElement
>
)
=>
{
e
.
preventDefault
();
handleSignUpButtonClick
();
};
const
handleSignUpButtonClick
=
async
()
=>
{
if
(
username
===
""
||
password
===
""
)
{
return
;
}
if
(
actionBtnLoadingState
.
isLoading
)
{
return
;
}
try
{
actionBtnLoadingState
.
setLoading
();
await
api
.
signup
(
username
,
password
);
const
user
=
await
userStore
.
doSignIn
();
if
(
user
)
{
window
.
location
.
href
=
"/"
;
}
else
{
toast
.
error
(
t
(
"message.signup-failed"
));
}
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toast
.
error
(
error
.
response
.
data
.
message
||
error
.
message
||
t
(
"message.signup-failed"
));
}
actionBtnLoadingState
.
setFinish
();
};
return
(
<
div
className=
"flex flex-row justify-center items-center w-full h-full dark:bg-zinc-800"
>
<
div
className=
"w-80 max-w-full h-full py-4 flex flex-col justify-start items-center"
>
<
div
className=
"w-full py-4 grow flex flex-col justify-center items-center"
>
<
div
className=
"w-full flex flex-row justify-center items-center mb-6"
>
<
img
className=
"h-14 w-auto rounded-full shadow"
src=
{
systemStatus
.
customizedProfile
.
logoUrl
}
alt=
""
/>
<
p
className=
"ml-4 text-5xl text-black opacity-80 dark:text-gray-200"
>
{
systemStatus
.
customizedProfile
.
name
}
</
p
>
</
div
>
<
p
className=
"w-full text-2xl mt-6 dark:text-gray-500"
>
Create your account
</
p
>
<
form
className=
"w-full mt-2"
onSubmit=
{
handleFormSubmit
}
>
<
div
className=
"flex flex-col justify-start items-start w-full gap-4"
>
<
div
className=
"w-full flex flex-col justify-start items-start gap-2"
>
<
span
className=
"leading-8 text-gray-600"
>
{
t
(
"common.username"
)
}
</
span
>
<
Input
className=
"w-full"
size=
"lg"
type=
"text"
readOnly=
{
actionBtnLoadingState
.
isLoading
}
placeholder=
{
t
(
"common.username"
)
}
value=
{
username
}
onChange=
{
handleUsernameInputChanged
}
required
/>
</
div
>
<
div
className=
"w-full flex flex-col justify-start items-start gap-2"
>
<
span
className=
"leading-8 text-gray-600"
>
{
t
(
"common.password"
)
}
</
span
>
<
Input
className=
"w-full"
size=
"lg"
type=
"password"
readOnly=
{
actionBtnLoadingState
.
isLoading
}
placeholder=
{
t
(
"common.password"
)
}
value=
{
password
}
onChange=
{
handlePasswordInputChanged
}
required
/>
</
div
>
</
div
>
<
div
className=
"flex flex-row justify-end items-center w-full mt-6"
>
<
Button
className=
"w-full"
type=
"submit"
disabled=
{
actionBtnLoadingState
.
isLoading
}
loading=
{
actionBtnLoadingState
.
isLoading
}
onClick=
{
handleSignUpButtonClick
}
>
{
t
(
"common.sign-up"
)
}
</
Button
>
</
div
>
</
form
>
<
p
className=
"w-full mt-4 text-sm"
>
<
span
className=
"dark:text-gray-500"
>
{
"Already has an account?"
}
</
span
>
<
Link
to=
"/auth"
className=
"cursor-pointer ml-2 text-blue-600 hover:underline"
>
{
t
(
"common.sign-in"
)
}
</
Link
>
</
p
>
</
div
>
<
div
className=
"flex flex-row items-center justify-center w-full gap-2"
>
<
LocaleSelect
value=
{
locale
}
onChange=
{
handleLocaleSelectChange
}
/>
<
AppearanceSelect
value=
{
appearance
}
onChange=
{
handleAppearanceSelectChange
}
/>
</
div
>
</
div
>
</
div
>
);
};
export
default
SignUp
;
web/src/router/index.tsx
View file @
01ff3f73
import
{
lazy
}
from
"react"
;
import
{
lazy
}
from
"react"
;
import
{
createBrowserRouter
,
redirect
}
from
"react-router-dom"
;
import
{
createBrowserRouter
,
redirect
}
from
"react-router-dom"
;
import
App
from
"@/App"
;
import
App
from
"@/App"
;
import
Archived
from
"@/pages/Archived"
;
import
DailyReview
from
"@/pages/DailyReview"
;
import
Resources
from
"@/pages/Resources"
;
import
Setting
from
"@/pages/Setting"
;
import
{
initialGlobalState
,
initialUserState
}
from
"@/store/module"
;
import
{
initialGlobalState
,
initialUserState
}
from
"@/store/module"
;
const
Root
=
lazy
(()
=>
import
(
"@/layouts/Root"
));
const
Root
=
lazy
(()
=>
import
(
"@/layouts/Root"
));
const
Auth
=
lazy
(()
=>
import
(
"@/pages/Auth"
));
const
SignIn
=
lazy
(()
=>
import
(
"@/pages/SignIn"
));
const
SignUp
=
lazy
(()
=>
import
(
"@/pages/SignUp"
));
const
AuthCallback
=
lazy
(()
=>
import
(
"@/pages/AuthCallback"
));
const
AuthCallback
=
lazy
(()
=>
import
(
"@/pages/AuthCallback"
));
const
Explore
=
lazy
(()
=>
import
(
"@/pages/Explore"
));
const
Explore
=
lazy
(()
=>
import
(
"@/pages/Explore"
));
const
Home
=
lazy
(()
=>
import
(
"@/pages/Home"
));
const
Home
=
lazy
(()
=>
import
(
"@/pages/Home"
));
const
UserProfile
=
lazy
(()
=>
import
(
"@/pages/UserProfile"
));
const
UserProfile
=
lazy
(()
=>
import
(
"@/pages/UserProfile"
));
const
MemoDetail
=
lazy
(()
=>
import
(
"@/pages/MemoDetail"
));
const
MemoDetail
=
lazy
(()
=>
import
(
"@/pages/MemoDetail"
));
const
EmbedMemo
=
lazy
(()
=>
import
(
"@/pages/EmbedMemo"
));
const
EmbedMemo
=
lazy
(()
=>
import
(
"@/pages/EmbedMemo"
));
const
Archived
=
lazy
(()
=>
import
(
"@/pages/Archived"
));
const
DailyReview
=
lazy
(()
=>
import
(
"@/pages/DailyReview"
));
const
Resources
=
lazy
(()
=>
import
(
"@/pages/Resources"
));
const
Setting
=
lazy
(()
=>
import
(
"@/pages/Setting"
));
const
NotFound
=
lazy
(()
=>
import
(
"@/pages/NotFound"
));
const
NotFound
=
lazy
(()
=>
import
(
"@/pages/NotFound"
));
const
initialGlobalStateLoader
=
(()
=>
{
const
initialGlobalStateLoader
=
(()
=>
{
...
@@ -58,7 +59,11 @@ const router = createBrowserRouter([
...
@@ -58,7 +59,11 @@ const router = createBrowserRouter([
children
:
[
children
:
[
{
{
path
:
"/auth"
,
path
:
"/auth"
,
element
:
<
Auth
/>,
element
:
<
SignIn
/>,
},
{
path
:
"/auth/signup"
,
element
:
<
SignUp
/>,
},
},
{
{
path
:
"/auth/callback"
,
path
:
"/auth/callback"
,
...
...
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