Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
love_飞影
Neos
Commits
7eebee43
Commit
7eebee43
authored
Jul 25, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sso login logic
parent
5247e0a3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
68 deletions
+30
-68
neos.config.json
neos.config.json
+1
-0
neos.config.prod.json
neos.config.prod.json
+1
-0
src/stores/index.ts
src/stores/index.ts
+2
-0
src/ui/Sso.tsx
src/ui/Sso.tsx
+16
-28
src/ui/Start/index.tsx
src/ui/Start/index.tsx
+10
-40
No files found.
neos.config.json
View file @
7eebee43
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
"cardsDbUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/cards.cdb"
,
"cardsDbUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/cards.cdb"
,
"stringsUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf"
,
"stringsUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf"
,
"replayUrl"
:
"replay.neos.moe"
,
"replayUrl"
:
"replay.neos.moe"
,
"accountUrl"
:
"https://accounts.moecube.com"
,
"chainALL"
:
false
,
"chainALL"
:
false
,
"streamInterval"
:
20
,
"streamInterval"
:
20
,
"startDelay"
:
1000
,
"startDelay"
:
1000
,
...
...
neos.config.prod.json
View file @
7eebee43
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
"cardsDbUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/cards.cdb"
,
"cardsDbUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/cards.cdb"
,
"stringsUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf"
,
"stringsUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf"
,
"replayUrl"
:
"replay.neos.moe"
,
"replayUrl"
:
"replay.neos.moe"
,
"accountUrl"
:
"https://accounts.moecube.com"
,
"chainALL"
:
false
,
"chainALL"
:
false
,
"streamInterval"
:
20
,
"streamInterval"
:
20
,
"startDelay"
:
1000
,
"startDelay"
:
1000
,
...
...
src/stores/index.ts
View file @
7eebee43
...
@@ -10,6 +10,7 @@ export * from "./replayStore";
...
@@ -10,6 +10,7 @@ export * from "./replayStore";
import
{
devtools
}
from
"
valtio/utils
"
;
import
{
devtools
}
from
"
valtio/utils
"
;
import
{
accountStore
}
from
"
./accountStore
"
;
import
{
cardStore
}
from
"
./cardStore
"
;
import
{
cardStore
}
from
"
./cardStore
"
;
import
{
chatStore
}
from
"
./chatStore
"
;
import
{
chatStore
}
from
"
./chatStore
"
;
import
{
joinStore
}
from
"
./joinStore
"
;
import
{
joinStore
}
from
"
./joinStore
"
;
...
@@ -27,6 +28,7 @@ devtools(matStore, { name: "mat", enabled: true });
...
@@ -27,6 +28,7 @@ devtools(matStore, { name: "mat", enabled: true });
devtools
(
cardStore
,
{
name
:
"
card
"
,
enabled
:
true
});
devtools
(
cardStore
,
{
name
:
"
card
"
,
enabled
:
true
});
devtools
(
placeStore
,
{
name
:
"
place
"
,
enabled
:
true
});
devtools
(
placeStore
,
{
name
:
"
place
"
,
enabled
:
true
});
devtools
(
replayStore
,
{
name
:
"
replay
"
,
enabled
:
true
});
devtools
(
replayStore
,
{
name
:
"
replay
"
,
enabled
:
true
});
devtools
(
accountStore
,
{
name
:
"
account
"
,
enabled
:
true
});
// 重置所有`Store`
// 重置所有`Store`
export
const
resetUniverse
=
()
=>
{
export
const
resetUniverse
=
()
=>
{
...
...
src/ui/Sso.tsx
View file @
7eebee43
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
{
match
,
MatchInfo
}
from
"
@/api
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
accountStore
,
User
}
from
"
@/stores
"
;
interface
SSOParams
{
const
NeosConfig
=
useConfig
();
id
:
string
;
username
:
string
;
name
:
string
;
email
:
string
;
return_sso_url
:
string
;
token
:
string
;
external_id
:
number
;
}
const
Sso
:
React
.
FC
=
()
=>
{
const
Sso
:
React
.
FC
=
()
=>
{
const
sso
=
new
URL
(
location
.
href
).
searchParams
.
get
(
"
sso
"
);
const
sso
=
new
URL
(
location
.
href
).
searchParams
.
get
(
"
sso
"
);
const
ssoParams
:
SSOParams
|
undefined
=
sso
const
user
:
User
|
undefined
=
sso
?
getSSO
Params
(
new
URLSearchParams
(
atob
(
sso
)))
?
getSSO
User
(
new
URLSearchParams
(
atob
(
sso
)))
:
undefined
;
:
undefined
;
const
[
matchInfo
,
setMatchInfo
]
=
useState
<
MatchInfo
|
undefined
>
(
undefined
);
const
onMatch
=
async
()
=>
{
const
[
logined
,
setLogined
]
=
useState
(
false
);
if
(
ssoParams
)
{
setMatchInfo
(
await
match
(
ssoParams
.
username
,
ssoParams
.
external_id
));
}
};
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
!
sso
)
{
if
(
!
sso
)
{
...
@@ -30,18 +19,17 @@ const Sso: React.FC = () => {
...
@@ -30,18 +19,17 @@ const Sso: React.FC = () => {
window
.
location
.
href
=
ssoUrl
;
window
.
location
.
href
=
ssoUrl
;
}
}
if
(
user
)
{
accountStore
.
login
(
user
);
setLogined
(
true
);
// TODO: navigate
}
},
[]);
},
[]);
return
(
return
(
<
div
>
<
div
>
<
p
>
username=
{
ssoParams
?.
username
}
</
p
>
<
p
>
{
logined
?
"
登录成功,正在跳转。。
"
:
"
登陆萌卡账号中。。。
"
}
</
p
>
<
p
>
name=
{
ssoParams
?.
name
}
</
p
>
<
p
>
email=
{
ssoParams
?.
email
}
</
p
>
<
button
onClick=
{
onMatch
}
>
match
</
button
>
<
p
>
match info
</
p
>
<
p
>
address=
{
matchInfo
?.
address
}
</
p
>
<
p
>
port=
{
matchInfo
?.
port
}
</
p
>
<
p
>
password=
{
matchInfo
?.
password
}
</
p
>
</
div
>
</
div
>
);
);
};
};
...
@@ -51,14 +39,14 @@ function getSSOUrl(callbackUrl: string): string {
...
@@ -51,14 +39,14 @@ function getSSOUrl(callbackUrl: string): string {
params
.
set
(
"
return_sso_url
"
,
callbackUrl
);
params
.
set
(
"
return_sso_url
"
,
callbackUrl
);
const
payload
=
btoa
(
params
.
toString
());
const
payload
=
btoa
(
params
.
toString
());
const
url
=
new
URL
(
"
https://accounts.moecube.com
"
);
const
url
=
new
URL
(
NeosConfig
.
accountUrl
);
params
=
url
.
searchParams
;
params
=
url
.
searchParams
;
params
.
set
(
"
sso
"
,
payload
);
params
.
set
(
"
sso
"
,
payload
);
return
url
.
toString
();
return
url
.
toString
();
}
}
function
getSSO
Params
(
searchParams
:
URLSearchParams
):
SSOParams
{
function
getSSO
User
(
searchParams
:
URLSearchParams
):
User
{
const
sso
=
{};
const
sso
=
{};
for
(
const
[
key
,
value
]
of
searchParams
)
{
for
(
const
[
key
,
value
]
of
searchParams
)
{
// @ts-ignore
// @ts-ignore
...
...
src/ui/Start/index.tsx
View file @
7eebee43
import
"
./index.scss
"
;
import
"
./index.scss
"
;
import
React
,
{
useEffect
}
from
"
react
"
;
import
React
from
"
react
"
;
import
{
useNavigate
}
from
"
react-router-dom
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
accountStore
,
User
}
from
"
@/stores
"
;
const
NeosConfig
=
useConfig
();
const
NeosConfig
=
useConfig
();
const
Start
:
React
.
FC
=
()
=>
{
const
Start
:
React
.
FC
=
()
=>
{
const
sso
=
new
URL
(
location
.
href
).
searchParams
.
get
(
"
sso
"
);
const
navigate
=
useNavigate
();
const
user
:
User
|
undefined
=
sso
?
getSSOUser
(
new
URLSearchParams
(
atob
(
sso
)))
:
undefined
;
const
onLogin
=
()
=>
{
const
ssoUrl
=
getSSOUrl
(
location
.
href
);
window
.
location
.
href
=
ssoUrl
;
};
useEffect
(()
=>
{
if
(
user
)
{
accountStore
.
login
(
user
);
// TODO: navigate
}
},
[
user
])
return
(
return
(
<>
<>
<
div
className=
"mycard-header"
>
<
div
className=
"mycard-header"
>
...
@@ -45,7 +31,13 @@ const Start: React.FC = () => {
...
@@ -45,7 +31,13 @@ const Start: React.FC = () => {
alt=
"YGO NEOS"
alt=
"YGO NEOS"
/>
/>
</
h1
>
</
h1
>
<
button
onClick=
{
onLogin
}
>
登陆萌卡进行游玩
</
button
>
<
button
onClick=
{
()
=>
{
navigate
(
"
/sso
"
);
}
}
>
登陆萌卡进行游玩
</
button
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
...
@@ -53,26 +45,4 @@ const Start: React.FC = () => {
...
@@ -53,26 +45,4 @@ const Start: React.FC = () => {
);
);
};
};
function
getSSOUrl
(
callbackUrl
:
string
):
string
{
let
params
=
new
URLSearchParams
();
params
.
set
(
"
return_sso_url
"
,
callbackUrl
);
const
payload
=
btoa
(
params
.
toString
());
const
url
=
new
URL
(
"
https://accounts.moecube.com
"
);
params
=
url
.
searchParams
;
params
.
set
(
"
sso
"
,
payload
);
return
url
.
toString
();
}
function
getSSOUser
(
searchParams
:
URLSearchParams
):
User
{
const
sso
=
{};
for
(
const
[
key
,
value
]
of
searchParams
)
{
// @ts-ignore
sso
[
key
]
=
value
;
}
return
sso
as
any
;
}
export
default
Start
;
export
default
Start
;
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