diff --git a/.gitignore b/.gitignore index e501aeb..188b368 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ go.work # gop_autogen.go dist/ node_modules/ +.vscode/ diff --git a/cmd/gopcomm/community_yap.gox b/cmd/gopcomm/community_yap.gox index 31e3529..986310d 100644 --- a/cmd/gopcomm/community_yap.gox +++ b/cmd/gopcomm/community_yap.gox @@ -11,6 +11,7 @@ import ( "github.com/goplus/community/internal/core" "github.com/goplus/community/translation" _ "github.com/joho/godotenv/autoload" + gopaccountsdk "github.com/liuscraft/gop-casdoor-account-sdk" "github.com/qiniu/x/xlog" language "golang.org/x/text/language" ) @@ -74,10 +75,10 @@ get "/p/:id", ctx => { "Title": article.Title, "Content": article.Content, // "HtmlUrl": article.HtmlUrl, - "Tags": article.Tags, - "Cover": article.Cover, - "Mtime": article.Mtime.Format(layoutUS), - "Author": article.User, + "Tags": article.Tags, + "Cover": article.Cover, + "Mtime": article.Mtime.Format(layoutUS), + "Author": article.User, // "User": article.User, } } @@ -120,22 +121,43 @@ get "/user/:id", ctx => { "UserId": user.Id, } } - -get "/userEdit", ctx => { - var user *core.User +get "/userUnlink", ctx => { + pv := ctx.param("pv") token, err := core.GetToken(ctx) + if err != nil { + http.Redirect(ctx.ResponseWriter, ctx.Request, "/login", http.StatusTemporaryRedirect) + return + } + switch pv { + case "Twitter": + case "Facebook": + case "Github": + case "WeChat": + default: + pv = "" + } + gac, err := gopaccountsdk.GetClient(token.Value) if err == nil { - user, err = community.GetUser(token.Value) - if err != nil { - xLog.Error("get user error:", err) - } + gac.UnLink(pv) } - + http.Redirect(ctx.ResponseWriter, ctx.Request, "/userEdit", http.StatusTemporaryRedirect) +} +get "/userEdit", ctx => { + token, err := core.GetToken(ctx) if err != nil { http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) } + gac, err := gopaccountsdk.GetClient(token.Value) + if err != nil { + http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect) + } + appInfo, _ := community.GetApplicationInfo() + appInfoStr, _ := json.Marshal(*appInfo) + binds, _ := json.Marshal(gac.GetProviderBindStatus()) ctx.yap "user_edit", { - "User": user, + "User": gac.GetUserSimple(), + "Application": string(appInfoStr), + "Binds": string(binds), } } @@ -149,7 +171,7 @@ get "/add", ctx => { } } ctx.yap "edit", { - "User": user, + "User": user, } } @@ -359,7 +381,7 @@ post "/commit", ctx => { // get user id token, err := core.GetToken(ctx) if err != nil { - xLog.Info("token",err) + xLog.Info("token", err) ctx.json { "code": 0, "err": "no token", @@ -367,7 +389,7 @@ post "/commit", ctx => { } uid, err := community.ParseJwtToken(token.Value) if err != nil { - xLog.Info("uid",err) + xLog.Info("uid", err) ctx.json { "code": 0, "err": err.Error(), @@ -379,11 +401,11 @@ post "/commit", ctx => { ID: id, Title: ctx.param("title"), UId: uid, - Cover: ctx.param("cover"), + Cover: ctx.param("cover"), Tags: ctx.param("tags"), Abstract: ctx.param("abstract"), }, - Content: mdData, + Content: mdData, TransContent: transData, } id, _ = community.PutArticle(todo, uid, article) @@ -462,26 +484,26 @@ get "/getMediaUrl/:id", ctx => { get "/getVideoAndSubtitle/:id", ctx => { id := ctx.param("id") fileKey, err := community.GetMediaUrl(todo, id) - m:=make(map[string]string,2) - format,err:=community.GetMediaType(todo,id) - if err!=nil { - ctx.json { - "code": 500, - "err": err.Error(), - } + m := make(map[string]string, 2) + format, err := community.GetMediaType(todo, id) + if err != nil { + ctx.json { + "code": 500, + "err": err.Error(), + } } if format == "video/mp4" { - subtitle,err:=community.GetVideoSubtitle(todo,id) - if err!=nil{ - if err != nil { - ctx.json { - "code": 500, - "err": err.Error(), - } - } - return - } - m["subtitle"] = domain+subtitle + subtitle, err := community.GetVideoSubtitle(todo, id) + if err != nil { + if err != nil { + ctx.json { + "code": 500, + "err": err.Error(), + } + } + return + } + m["subtitle"] = domain + subtitle } htmlUrl := fmt.Sprintf("%s%s", domain, fileKey) if err != nil { @@ -551,7 +573,7 @@ get "/callback", ctx => { origin_path := ctx.URL.Query().Get("origin_path") unurl, err := url.QueryUnescape(origin_path) if err != nil { - xLog.Info("Unurl error",err) + xLog.Info("Unurl error", err) unurl = "/" } @@ -575,6 +597,7 @@ run(endpoint, func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer func() { if err := recover(); err != nil { + xLog.Error(err) http.Redirect(w, r, "/failed", http.StatusFound) } }() diff --git a/cmd/gopcomm/gop_autogen.go b/cmd/gopcomm/gop_autogen.go index 8aa5744..bc3ba59 100644 --- a/cmd/gopcomm/gop_autogen.go +++ b/cmd/gopcomm/gop_autogen.go @@ -662,4 +662,4 @@ func (this *community_yap) MainEntry() { } func main() { yap.Gopt_App_Main(new(community_yap)) -} +} \ No newline at end of file diff --git a/cmd/gopcomm/yap/article_yap.html b/cmd/gopcomm/yap/article_yap.html index fbb4b07..6707c96 100644 --- a/cmd/gopcomm/yap/article_yap.html +++ b/cmd/gopcomm/yap/article_yap.html @@ -37,7 +37,7 @@ - + @@ -51,7 +51,9 @@ - + + + @@ -23,6 +23,9 @@ + + + + - + - + - + + - + @@ -66,15 +71,15 @@ New Article + class="ml-2">Article Add Edit Article + class="ml-2">Article Editor - @@ -140,24 +145,18 @@ }"> - + + - +
- - click or drag a file here to upload -
@@ -182,16 +181,98 @@ + +
+
+
+
+
+ +
+
+

Please fill in the article title + and content! +

+

Your article information is incomplete.

+
+
+ + + +
+
+
+
+
+
+
+
+ +
+
+

Please fill in the article title! +

+

Your article information is incomplete.

+
+
+ + + +
+
+
+
+
+
+
+
+ +
+
+

Please fill in the article + content! +

+

Your article information is incomplete.

+
+
+ + + +
+
+
+
+ + \ No newline at end of file diff --git a/cmd/gopcomm/yap/markdown-vue/src/components/MarkdownViewer.vue b/cmd/gopcomm/yap/markdown-vue/src/components/MarkdownViewer.vue index 0dacbdb..b1169f5 100644 --- a/cmd/gopcomm/yap/markdown-vue/src/components/MarkdownViewer.vue +++ b/cmd/gopcomm/yap/markdown-vue/src/components/MarkdownViewer.vue @@ -9,6 +9,9 @@ diff --git a/cmd/gopcomm/yap/user_yap.html b/cmd/gopcomm/yap/user_yap.html index 599eca9..5825d3a 100644 --- a/cmd/gopcomm/yap/user_yap.html +++ b/cmd/gopcomm/yap/user_yap.html @@ -63,12 +63,15 @@ -

- ${ CurrentUser.gender } -

, born on ${ CurrentUser.birthday }

-

-
+

gender is empty

+

${ CurrentUser.gender}

+ + + +

birthday is empty

+

${ CurrentUser.birthday}

+
@@ -78,13 +81,16 @@ -

${ CurrentUser.email }

+

email is empty

+

${ CurrentUser.email}

-

${ CurrentUser.phone }

+ +

phone is empty

+

${ CurrentUser.phone}

diff --git a/go.mod b/go.mod index de6b3bf..d399c9a 100644 --- a/go.mod +++ b/go.mod @@ -21,6 +21,8 @@ require ( golang.org/x/oauth2 v0.17.0 ) +require github.com/liuscraft/gop-casdoor-account-sdk v1.1.0 + require ( github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect diff --git a/go.sum b/go.sum index a838185..157a532 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/liuscraft/gop-casdoor-account-sdk v1.1.0 h1:9z4D/0N5GhskVtLtmeveq6LEufxd6G5G3/wsId862BM= +github.com/liuscraft/gop-casdoor-account-sdk v1.1.0/go.mod h1:ebIZkkTGZIGPY78BPlbU1NFtB0OBGuCHnQxgrA12nYI= github.com/onsi/ginkgo/v2 v2.12.0 h1:UIVDowFPwpg6yMUpPjGkYvf06K3RAiJXUhCxEwQVHRI= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= diff --git a/gop.mod b/gop.mod index bea9cd0..30f5ac9 100644 --- a/gop.mod +++ b/gop.mod @@ -1,3 +1 @@ gop 1.1 - -import github.com/goplus/yap diff --git a/internal/core/community.go b/internal/core/community.go index 56f1bc7..6698d47 100644 --- a/internal/core/community.go +++ b/internal/core/community.go @@ -547,3 +547,12 @@ func (a *Community) Share(ip, platform, userId, articleId string) { a.xLog.Printf("user: %s, ip: %s, share to platform: %s, articleId: %s", userId, ip, platform, articleId) }(ip, platform, userId, articleId) } + +// get community application information +func (a *Community) GetApplicationInfo() (*casdoorsdk.Application, error) { + a2, err := casdoorsdk.GetApplication("application_x8aevk") + if err != nil { + a.xLog.Error(err) + } + return a2, err +} diff --git a/internal/core/user.go b/internal/core/user.go index ad55f31..12749a4 100644 --- a/internal/core/user.go +++ b/internal/core/user.go @@ -1,10 +1,11 @@ package core import ( - "github.com/goplus/yap" "net/http" "os" + "github.com/goplus/yap" + "github.com/casdoor/casdoor-go-sdk/casdoorsdk" ) @@ -63,6 +64,7 @@ func (p *Community) GetUserClaim(uid string) (claim *casdoorsdk.User, err error) p.xLog.Error(err) return &casdoorsdk.User{}, ErrNotExist } + claim.Properties["oauth_Wechat_extra"] = "" return } @@ -73,11 +75,20 @@ func (p *Community) GetUserById(uid string) (user *User, err error) { p.xLog.Error(err) return &User{}, ErrNotExist } - user = &User{ - Name: claim.Name, - Avatar: claim.Avatar, - Id: claim.Id, + if claim == nil { + user = &User{ + Name: "unknown", + Avatar: "", + Id: "", + } + } else { + user = &User{ + Name: claim.Name, + Avatar: claim.Avatar, + Id: claim.Id, + } } + return }