Fix: sql not support ProviderUserID uint64

pull/31/head
zijiren233 2 years ago
parent c96abd2927
commit 3122f53e76

@ -19,7 +19,7 @@ func WithRole(role model.Role) CreateUserConfig {
}
}
func CreateUser(username string, p provider.OAuth2Provider, puid uint64, conf ...CreateUserConfig) (*model.User, error) {
func CreateUser(username string, p provider.OAuth2Provider, puid string, conf ...CreateUserConfig) (*model.User, error) {
u := &model.User{
Username: username,
Role: model.RoleUser,
@ -41,7 +41,7 @@ func CreateUser(username string, p provider.OAuth2Provider, puid uint64, conf ..
}
// 只有当provider和puid没有找到对应的user时才会创建
func CreateOrLoadUser(username string, p provider.OAuth2Provider, puid uint64, conf ...CreateUserConfig) (*model.User, error) {
func CreateOrLoadUser(username string, p provider.OAuth2Provider, puid string, conf ...CreateUserConfig) (*model.User, error) {
var user model.User
var userProvider model.UserProvider
@ -60,7 +60,7 @@ func CreateOrLoadUser(username string, p provider.OAuth2Provider, puid uint64, c
return &user, nil
}
func GetProviderUserID(p provider.OAuth2Provider, puid uint64) (string, error) {
func GetProviderUserID(p provider.OAuth2Provider, puid string) (string, error) {
var userProvider model.UserProvider
if err := db.Where("provider = ? AND provider_user_id = ?", p, puid).First(&userProvider).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {

@ -8,7 +8,7 @@ import (
type UserProvider struct {
Provider provider.OAuth2Provider `gorm:"not null;primarykey"`
ProviderUserID uint64 `gorm:"not null;primarykey;autoIncrement:false"`
ProviderUserID string `gorm:"not null;primarykey;autoIncrement:false"`
CreatedAt time.Time
UpdatedAt time.Time
UserID string `gorm:"not null;index"`

@ -43,7 +43,7 @@ func GetUserById(id string) (*User, error) {
return u2, userCache.SetWithExpire(id, u2, time.Hour)
}
func CreateUser(username string, p provider.OAuth2Provider, pid uint64, conf ...db.CreateUserConfig) (*User, error) {
func CreateUser(username string, p provider.OAuth2Provider, pid string, conf ...db.CreateUserConfig) (*User, error) {
if username == "" {
return nil, errors.New("username cannot be empty")
}
@ -59,7 +59,7 @@ func CreateUser(username string, p provider.OAuth2Provider, pid uint64, conf ...
return u2, userCache.SetWithExpire(u.ID, u2, time.Hour)
}
func CreateOrLoadUser(username string, p provider.OAuth2Provider, pid uint64, conf ...db.CreateUserConfig) (*User, error) {
func CreateOrLoadUser(username string, p provider.OAuth2Provider, pid string, conf ...db.CreateUserConfig) (*User, error) {
if username == "" {
return nil, errors.New("username cannot be empty")
}
@ -75,7 +75,7 @@ func CreateOrLoadUser(username string, p provider.OAuth2Provider, pid uint64, co
return u2, userCache.SetWithExpire(u.ID, u2, time.Hour)
}
func GetUserByProvider(p provider.OAuth2Provider, pid uint64) (*User, error) {
func GetUserByProvider(p provider.OAuth2Provider, pid string) (*User, error) {
uid, err := db.GetProviderUserID(p, pid)
if err != nil {
return nil, err

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/http"
"strconv"
plugin "github.com/hashicorp/go-plugin"
"github.com/synctv-org/synctv/internal/provider"
@ -75,7 +76,7 @@ func (p *GiteeProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pro
}
return &provider.UserInfo{
Username: ui.Login,
ProviderUserID: ui.ID,
ProviderUserID: strconv.FormatUint(ui.ID, 10),
}, nil
}

@ -56,7 +56,7 @@ func (s *GRPCServer) GetUserInfo(ctx context.Context, req *providerpb.GetUserInf
}
resp := &providerpb.GetUserInfoResp{
Username: userInfo.Username,
ProviderUserId: uint64(userInfo.ProviderUserID),
ProviderUserId: userInfo.ProviderUserID,
}
return resp, nil
}

@ -10,7 +10,7 @@ type OAuth2Provider string
type UserInfo struct {
Username string
ProviderUserID uint64
ProviderUserID string
}
type Oauth2Option struct {

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"strconv"
json "github.com/json-iterator/go"
"github.com/synctv-org/synctv/internal/provider"
@ -63,7 +64,7 @@ func (p *BaiduNetDiskProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token
}
return &provider.UserInfo{
Username: ui.BaiduName,
ProviderUserID: ui.Uk,
ProviderUserID: strconv.FormatUint(ui.Uk, 10),
}, nil
}

@ -3,7 +3,6 @@ package providers
import (
"context"
"fmt"
"hash/crc64"
"net/http"
json "github.com/json-iterator/go"
@ -61,7 +60,7 @@ func (p *BaiduProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pro
}
return &provider.UserInfo{
Username: ui.Uname,
ProviderUserID: crc64.Checksum([]byte(ui.Openid), crc64.MakeTable(crc64.ECMA)),
ProviderUserID: ui.Openid,
}, nil
}

@ -3,6 +3,7 @@ package providers
import (
"context"
"net/http"
"strconv"
json "github.com/json-iterator/go"
"github.com/synctv-org/synctv/internal/provider"
@ -58,7 +59,7 @@ func (p *GiteeProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pro
}
return &provider.UserInfo{
Username: ui.Login,
ProviderUserID: ui.ID,
ProviderUserID: strconv.FormatUint(ui.ID, 10),
}, nil
}

@ -3,6 +3,7 @@ package providers
import (
"context"
"net/http"
"strconv"
json "github.com/json-iterator/go"
"github.com/synctv-org/synctv/internal/provider"
@ -56,7 +57,7 @@ func (p *GithubProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pr
}
return &provider.UserInfo{
Username: ui.Login,
ProviderUserID: ui.ID,
ProviderUserID: strconv.FormatUint(ui.ID, 10),
}, nil
}

@ -65,6 +65,6 @@ func init() {
}
type googleUserInfo struct {
ID uint64 `json:"id,string"`
ID string `json:"id"`
Name string `json:"name"`
}

@ -2,12 +2,10 @@ package providers
import (
"context"
"hash/crc64"
"net/http"
json "github.com/json-iterator/go"
"github.com/synctv-org/synctv/internal/provider"
"github.com/zijiren233/stream"
"golang.org/x/oauth2"
"golang.org/x/oauth2/microsoft"
)
@ -58,7 +56,7 @@ func (p *MicrosoftProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (
}
return &provider.UserInfo{
Username: ui.DisplayName,
ProviderUserID: crc64.Checksum(stream.StringToBytes(ui.ID), crc64.MakeTable(crc64.ECMA)),
ProviderUserID: ui.ID,
}, nil
}

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strconv"
json "github.com/json-iterator/go"
"github.com/synctv-org/synctv/internal/provider"
@ -59,7 +58,7 @@ func (p *QQProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*provid
return nil, err
}
return &provider.UserInfo{
Username: strconv.FormatUint(ui.Openid, 10),
Username: ui.Openid,
ProviderUserID: ui.Openid,
}, nil
}
@ -70,5 +69,5 @@ func init() {
type qqProviderUserInfo struct {
ClientID string `json:"client_id"`
Openid uint64 `json:"openid,string"`
Openid string `json:"openid"`
}

@ -489,7 +489,7 @@ type GetUserInfoResp struct {
unknownFields protoimpl.UnknownFields
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
ProviderUserId uint64 `protobuf:"varint,2,opt,name=provider_user_id,json=providerUserId,proto3" json:"provider_user_id,omitempty"`
ProviderUserId string `protobuf:"bytes,2,opt,name=provider_user_id,json=providerUserId,proto3" json:"provider_user_id,omitempty"`
}
func (x *GetUserInfoResp) Reset() {
@ -531,11 +531,11 @@ func (x *GetUserInfoResp) GetUsername() string {
return ""
}
func (x *GetUserInfoResp) GetProviderUserId() uint64 {
func (x *GetUserInfoResp) GetProviderUserId() string {
if x != nil {
return x.ProviderUserId
}
return 0
return ""
}
type Enpty struct {
@ -620,7 +620,7 @@ var file_proto_provider_plugin_proto_rawDesc = []byte{
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72,
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72,
0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0e,
0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e,
0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x07,
0x0a, 0x05, 0x45, 0x6e, 0x70, 0x74, 0x79, 0x32, 0xd7, 0x02, 0x0a, 0x0c, 0x4f, 0x61, 0x75, 0x74,
0x68, 0x32, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x26, 0x0a, 0x04, 0x49, 0x6e, 0x69, 0x74,

@ -32,7 +32,7 @@ message GetUserInfoReq { Token token = 1; }
message GetUserInfoResp {
string username = 1;
uint64 provider_user_id = 2;
string provider_user_id = 2;
}
message Enpty {}

Loading…
Cancel
Save