mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-17 16:06:38 +08:00
fix: 第三方登录注销 #500
This commit is contained in:
parent
0f95502b04
commit
972ac1ee0f
@ -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) {
|
|||||||
})
|
})
|
||||||
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)
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
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 = () => {
|
|||||||
} 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);
|
||||||
|
@ -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 = () => {
|
|||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user