Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4a46fef3
authored
Nov 11, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: LinuxDo OAuth
parent
12de1fac
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
web/src/App.js
+9
-0
web/src/components/LinuxDoOAuth.js
+61
-0
No files found.
web/src/App.js
View file @
4a46fef3
...
@@ -26,6 +26,7 @@ import Midjourney from './pages/Midjourney';
...
@@ -26,6 +26,7 @@ import Midjourney from './pages/Midjourney';
import
Pricing
from
'./pages/Pricing/index.js'
;
import
Pricing
from
'./pages/Pricing/index.js'
;
import
Task
from
"./pages/Task/index.js"
;
import
Task
from
"./pages/Task/index.js"
;
import
Playground
from
'./components/Playground.js'
;
import
Playground
from
'./components/Playground.js'
;
import
LinuxDoOAuth
from
'./components/LinuxDoOAuth.js'
;
const
Home
=
lazy
(()
=>
import
(
'./pages/Home'
));
const
Home
=
lazy
(()
=>
import
(
'./pages/Home'
));
const
Detail
=
lazy
(()
=>
import
(
'./pages/Detail'
));
const
Detail
=
lazy
(()
=>
import
(
'./pages/Detail'
));
...
@@ -182,6 +183,14 @@ function App() {
...
@@ -182,6 +183,14 @@ function App() {
}
}
/
>
/
>
<
Route
<
Route
path
=
'/oauth/linuxdo'
element
=
{
<
Suspense
fallback
=
{
<
Loading
><
/Loading>}
>
<
LinuxDoOAuth
/>
<
/Suspense
>
}
/
>
<
Route
path
=
'/setting'
path
=
'/setting'
element
=
{
element
=
{
<
PrivateRoute
>
<
PrivateRoute
>
...
...
web/src/components/LinuxDoOAuth.js
0 → 100644
View file @
4a46fef3
import
React
,
{
useContext
,
useEffect
,
useState
}
from
'react'
;
import
{
Dimmer
,
Loader
,
Segment
}
from
'semantic-ui-react'
;
import
{
useNavigate
,
useSearchParams
}
from
'react-router-dom'
;
import
{
API
,
showError
,
showSuccess
,
updateAPI
}
from
'../helpers'
;
import
{
UserContext
}
from
'../context/User'
;
import
{
setUserData
}
from
'../helpers/data.js'
;
const
LinuxDoOAuth
=
()
=>
{
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
();
const
[
userState
,
userDispatch
]
=
useContext
(
UserContext
);
const
[
prompt
,
setPrompt
]
=
useState
(
'处理中...'
);
const
[
processing
,
setProcessing
]
=
useState
(
true
);
let
navigate
=
useNavigate
();
const
sendCode
=
async
(
code
,
state
,
count
)
=>
{
const
res
=
await
API
.
get
(
`/api/oauth/linuxdo?code=
${
code
}
&state=
${
state
}
`
);
const
{
success
,
message
,
data
}
=
res
.
data
;
if
(
success
)
{
if
(
message
===
'bind'
)
{
showSuccess
(
'绑定成功!'
);
navigate
(
'/setting'
);
}
else
{
userDispatch
({
type
:
'login'
,
payload
:
data
});
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
));
setUserData
(
data
);
updateAPI
()
showSuccess
(
'登录成功!'
);
navigate
(
'/token'
);
}
}
else
{
showError
(
message
);
if
(
count
===
0
)
{
setPrompt
(
`操作失败,重定向至登录界面中...`
);
navigate
(
'/setting'
);
// in case this is failed to bind GitHub
return
;
}
count
++
;
setPrompt
(
`出现错误,第
${
count
}
次重试中...`
);
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
count
*
2000
));
await
sendCode
(
code
,
state
,
count
);
}
};
useEffect
(()
=>
{
let
code
=
searchParams
.
get
(
'code'
);
let
state
=
searchParams
.
get
(
'state'
);
sendCode
(
code
,
state
,
0
).
then
();
},
[]);
return
(
<
Segment
style
=
{{
minHeight
:
'300px'
}}
>
<
Dimmer
active
inverted
>
<
Loader
size
=
'large'
>
{
prompt
}
<
/Loader
>
<
/Dimmer
>
<
/Segment
>
);
};
export
default
LinuxDoOAuth
;
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