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 @@ + + + + - + - + - + + - +
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.
+