feat: full support for wechat official account login (#2677)

* feat: full support for wechat official account login

* feat: improve provider edit page

* fix: improve i18n format
This commit is contained in:
DacongDA
2024-02-07 00:00:10 +08:00
committed by GitHub
parent 3a19d4c7c8
commit 97db54b6b9
28 changed files with 235 additions and 78 deletions

View File

@ -24,7 +24,6 @@ import (
"net/url"
"strconv"
"strings"
"sync"
"github.com/casdoor/casdoor/captcha"
"github.com/casdoor/casdoor/conf"
@ -37,11 +36,6 @@ import (
"golang.org/x/oauth2"
)
var (
wechatCacheMap map[string]idp.WechatCacheMapValue
lock sync.RWMutex
)
func codeToResponse(code *object.Code) *Response {
if code.Code == "" {
return &Response{Status: "error", Msg: code.Message, Data: code.Code}
@ -972,15 +966,15 @@ func (c *ApiController) HandleOfficialAccountEvent() {
return
}
lock.Lock()
if wechatCacheMap == nil {
wechatCacheMap = make(map[string]idp.WechatCacheMapValue)
idp.Lock.Lock()
if idp.WechatCacheMap == nil {
idp.WechatCacheMap = make(map[string]idp.WechatCacheMapValue)
}
wechatCacheMap[data.Ticket] = idp.WechatCacheMapValue{
IsScanned: true,
WechatOpenId: data.FromUserName,
idp.WechatCacheMap[data.Ticket] = idp.WechatCacheMapValue{
IsScanned: true,
WechatUnionId: data.FromUserName,
}
lock.Unlock()
idp.Lock.Unlock()
c.Ctx.WriteString("")
}
@ -994,18 +988,15 @@ func (c *ApiController) HandleOfficialAccountEvent() {
func (c *ApiController) GetWebhookEventType() {
ticket := c.Input().Get("ticket")
lock.RLock()
wechatMsg, ok := wechatCacheMap[ticket]
lock.RUnlock()
idp.Lock.RLock()
_, ok := idp.WechatCacheMap[ticket]
idp.Lock.RUnlock()
if !ok {
c.ResponseError("ticket not found")
return
}
lock.Lock()
delete(wechatCacheMap, ticket)
lock.Unlock()
c.ResponseOk("SCAN", wechatMsg.IsScanned)
c.ResponseOk("SCAN", ticket)
}
// GetQRCode