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
fd2379e8
authored
Sep 25, 2024
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 第三方登录注销 #500
parent
55ddd363
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
19 deletions
+25
-19
controller/github.go
+10
-0
controller/user.go
+2
-1
model/user.go
+4
-16
web/src/components/GitHubOAuth.js
+5
-2
web/src/components/LoginForm.js
+4
-0
No files found.
controller/github.go
View file @
fd2379e8
...
@@ -112,7 +112,9 @@ func GitHubOAuth(c *gin.Context) {
...
@@ -112,7 +112,9 @@ func GitHubOAuth(c *gin.Context) {
user
:=
model
.
User
{
user
:=
model
.
User
{
GitHubId
:
githubUser
.
Login
,
GitHubId
:
githubUser
.
Login
,
}
}
// IsGitHubIdAlreadyTaken is unscoped
if
model
.
IsGitHubIdAlreadyTaken
(
user
.
GitHubId
)
{
if
model
.
IsGitHubIdAlreadyTaken
(
user
.
GitHubId
)
{
// FillUserByGitHubId is scoped
err
:=
user
.
FillUserByGitHubId
()
err
:=
user
.
FillUserByGitHubId
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -121,6 +123,14 @@ func GitHubOAuth(c *gin.Context) {
...
@@ -121,6 +123,14 @@ func GitHubOAuth(c *gin.Context) {
})
})
return
return
}
}
// if user.Id == 0 , user has been deleted
if
user
.
Id
==
0
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"用户已注销"
,
})
return
}
}
else
{
}
else
{
if
common
.
RegisterEnabled
{
if
common
.
RegisterEnabled
{
user
.
Username
=
"github_"
+
strconv
.
Itoa
(
model
.
GetMaxUserId
()
+
1
)
user
.
Username
=
"github_"
+
strconv
.
Itoa
(
model
.
GetMaxUserId
()
+
1
)
...
...
controller/user.go
View file @
fd2379e8
...
@@ -159,8 +159,9 @@ func Register(c *gin.Context) {
...
@@ -159,8 +159,9 @@ func Register(c *gin.Context) {
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
"message"
:
err
.
Error
()
,
"message"
:
"数据库错误,请稍后重试"
,
})
})
common
.
SysError
(
fmt
.
Sprintf
(
"CheckUserExistOrDeleted error: %v"
,
err
))
return
return
}
}
if
exist
{
if
exist
{
...
...
model/user.go
View file @
fd2379e8
...
@@ -351,14 +351,6 @@ func (user *User) FillUserByWeChatId() error {
...
@@ -351,14 +351,6 @@ func (user *User) FillUserByWeChatId() error {
return
nil
return
nil
}
}
func
(
user
*
User
)
FillUserByUsername
()
error
{
if
user
.
Username
==
""
{
return
errors
.
New
(
"username 为空!"
)
}
DB
.
Where
(
User
{
Username
:
user
.
Username
})
.
First
(
user
)
return
nil
}
func
(
user
*
User
)
FillUserByTelegramId
()
error
{
func
(
user
*
User
)
FillUserByTelegramId
()
error
{
if
user
.
TelegramId
==
""
{
if
user
.
TelegramId
==
""
{
return
errors
.
New
(
"Telegram id 为空!"
)
return
errors
.
New
(
"Telegram id 为空!"
)
...
@@ -371,23 +363,19 @@ func (user *User) FillUserByTelegramId() error {
...
@@ -371,23 +363,19 @@ func (user *User) FillUserByTelegramId() error {
}
}
func
IsEmailAlreadyTaken
(
email
string
)
bool
{
func
IsEmailAlreadyTaken
(
email
string
)
bool
{
return
DB
.
Where
(
"email = ?"
,
email
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
return
DB
.
Unscoped
()
.
Where
(
"email = ?"
,
email
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
}
}
func
IsWeChatIdAlreadyTaken
(
wechatId
string
)
bool
{
func
IsWeChatIdAlreadyTaken
(
wechatId
string
)
bool
{
return
DB
.
Where
(
"wechat_id = ?"
,
wechatId
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
return
DB
.
Unscoped
()
.
Where
(
"wechat_id = ?"
,
wechatId
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
}
}
func
IsGitHubIdAlreadyTaken
(
githubId
string
)
bool
{
func
IsGitHubIdAlreadyTaken
(
githubId
string
)
bool
{
return
DB
.
Where
(
"github_id = ?"
,
githubId
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
return
DB
.
Unscoped
()
.
Where
(
"github_id = ?"
,
githubId
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
}
func
IsUsernameAlreadyTaken
(
username
string
)
bool
{
return
DB
.
Where
(
"username = ?"
,
username
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
}
}
func
IsTelegramIdAlreadyTaken
(
telegramId
string
)
bool
{
func
IsTelegramIdAlreadyTaken
(
telegramId
string
)
bool
{
return
DB
.
Where
(
"telegram_id = ?"
,
telegramId
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
return
DB
.
Unscoped
()
.
Where
(
"telegram_id = ?"
,
telegramId
)
.
Find
(
&
User
{})
.
RowsAffected
==
1
}
}
func
ResetUserPasswordByEmail
(
email
string
,
password
string
)
error
{
func
ResetUserPasswordByEmail
(
email
string
,
password
string
)
error
{
...
...
web/src/components/GitHubOAuth.js
View file @
fd2379e8
import
React
,
{
useContext
,
useEffect
,
useState
}
from
'react'
;
import
React
,
{
useContext
,
useEffect
,
useState
}
from
'react'
;
import
{
Dimmer
,
Loader
,
Segment
}
from
'semantic-ui-react'
;
import
{
Dimmer
,
Loader
,
Segment
}
from
'semantic-ui-react'
;
import
{
useNavigate
,
useSearchParams
}
from
'react-router-dom'
;
import
{
useNavigate
,
useSearchParams
}
from
'react-router-dom'
;
import
{
API
,
showError
,
showSuccess
}
from
'../helpers'
;
import
{
API
,
showError
,
showSuccess
,
updateAPI
}
from
'../helpers'
;
import
{
UserContext
}
from
'../context/User'
;
import
{
UserContext
}
from
'../context/User'
;
import
{
setUserData
}
from
'../helpers/data.js'
;
const
GitHubOAuth
=
()
=>
{
const
GitHubOAuth
=
()
=>
{
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
();
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
();
...
@@ -23,8 +24,10 @@ const GitHubOAuth = () => {
...
@@ -23,8 +24,10 @@ const GitHubOAuth = () => {
}
else
{
}
else
{
userDispatch
({
type
:
'login'
,
payload
:
data
});
userDispatch
({
type
:
'login'
,
payload
:
data
});
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
));
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
));
setUserData
(
data
);
updateAPI
()
showSuccess
(
'登录成功!'
);
showSuccess
(
'登录成功!'
);
navigate
(
'/'
);
navigate
(
'/
token
'
);
}
}
}
else
{
}
else
{
showError
(
message
);
showError
(
message
);
...
...
web/src/components/LoginForm.js
View file @
fd2379e8
...
@@ -71,6 +71,8 @@ const LoginForm = () => {
...
@@ -71,6 +71,8 @@ const LoginForm = () => {
if
(
success
)
{
if
(
success
)
{
userDispatch
({
type
:
'login'
,
payload
:
data
});
userDispatch
({
type
:
'login'
,
payload
:
data
});
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
));
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
));
setUserData
(
data
);
updateAPI
()
navigate
(
'/'
);
navigate
(
'/'
);
showSuccess
(
'登录成功!'
);
showSuccess
(
'登录成功!'
);
setShowWeChatLoginModal
(
false
);
setShowWeChatLoginModal
(
false
);
...
@@ -143,6 +145,8 @@ const LoginForm = () => {
...
@@ -143,6 +145,8 @@ const LoginForm = () => {
userDispatch
({
type
:
'login'
,
payload
:
data
});
userDispatch
({
type
:
'login'
,
payload
:
data
});
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
));
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
data
));
showSuccess
(
'登录成功!'
);
showSuccess
(
'登录成功!'
);
setUserData
(
data
);
updateAPI
()
navigate
(
'/'
);
navigate
(
'/'
);
}
else
{
}
else
{
showError
(
message
);
showError
(
message
);
...
...
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