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
f11208d5
authored
Dec 07, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: telegram register
parent
b2e2f37a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
1 deletions
+35
-1
web/src/components/RegisterForm.js
+35
-1
No files found.
web/src/components/RegisterForm.js
View file @
f11208d5
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
React
,
{
use
Context
,
use
Effect
,
useState
}
from
'react'
;
import
{
Link
,
useNavigate
}
from
'react-router-dom'
;
import
{
Link
,
useNavigate
}
from
'react-router-dom'
;
import
{
API
,
getLogo
,
showError
,
showInfo
,
showSuccess
,
updateAPI
}
from
'../helpers'
;
import
{
API
,
getLogo
,
showError
,
showInfo
,
showSuccess
,
updateAPI
}
from
'../helpers'
;
import
Turnstile
from
'react-turnstile'
;
import
Turnstile
from
'react-turnstile'
;
...
@@ -11,6 +11,7 @@ import LinuxDoIcon from './LinuxDoIcon.js';
...
@@ -11,6 +11,7 @@ import LinuxDoIcon from './LinuxDoIcon.js';
import
WeChatIcon
from
'./WeChatIcon.js'
;
import
WeChatIcon
from
'./WeChatIcon.js'
;
import
TelegramLoginButton
from
'react-telegram-login/src'
;
import
TelegramLoginButton
from
'react-telegram-login/src'
;
import
{
setUserData
}
from
'../helpers/data.js'
;
import
{
setUserData
}
from
'../helpers/data.js'
;
import
{
UserContext
}
from
'../context/User/index.js'
;
const
RegisterForm
=
()
=>
{
const
RegisterForm
=
()
=>
{
const
[
inputs
,
setInputs
]
=
useState
({
const
[
inputs
,
setInputs
]
=
useState
({
...
@@ -22,6 +23,7 @@ const RegisterForm = () => {
...
@@ -22,6 +23,7 @@ const RegisterForm = () => {
});
});
const
{
username
,
password
,
password2
}
=
inputs
;
const
{
username
,
password
,
password2
}
=
inputs
;
const
[
showEmailVerification
,
setShowEmailVerification
]
=
useState
(
false
);
const
[
showEmailVerification
,
setShowEmailVerification
]
=
useState
(
false
);
const
[
userState
,
userDispatch
]
=
useContext
(
UserContext
);
const
[
turnstileEnabled
,
setTurnstileEnabled
]
=
useState
(
false
);
const
[
turnstileEnabled
,
setTurnstileEnabled
]
=
useState
(
false
);
const
[
turnstileSiteKey
,
setTurnstileSiteKey
]
=
useState
(
''
);
const
[
turnstileSiteKey
,
setTurnstileSiteKey
]
=
useState
(
''
);
const
[
turnstileToken
,
setTurnstileToken
]
=
useState
(
''
);
const
[
turnstileToken
,
setTurnstileToken
]
=
useState
(
''
);
...
@@ -133,6 +135,38 @@ const RegisterForm = () => {
...
@@ -133,6 +135,38 @@ const RegisterForm = () => {
setLoading
(
false
);
setLoading
(
false
);
};
};
const
onTelegramLoginClicked
=
async
(
response
)
=>
{
const
fields
=
[
'id'
,
'first_name'
,
'last_name'
,
'username'
,
'photo_url'
,
'auth_date'
,
'hash'
,
'lang'
,
];
const
params
=
{};
fields
.
forEach
((
field
)
=>
{
if
(
response
[
field
])
{
params
[
field
]
=
response
[
field
];
}
});
const
res
=
await
API
.
get
(
`/api/oauth/telegram/login`
,
{
params
});
const
{
success
,
message
,
data
}
=
res
.
data
;
if
(
success
)
{
userDispatch
({
type
:
'login'
,
payload
:
data
});
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
));
showSuccess
(
'登录成功!'
);
setUserData
(
data
);
updateAPI
();
navigate
(
'/'
);
}
else
{
showError
(
message
);
}
};
return
(
return
(
<
div
>
<
div
>
<
Layout
>
<
Layout
>
...
...
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