Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bind account #148

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ go.work
# gop_autogen.go
dist/
node_modules/
.vscode/
97 changes: 60 additions & 37 deletions cmd/gopcomm/community_yap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -120,22 +121,43 @@ get "/user/:id", ctx => {
"UserId": user.Id,
}
}

get "/userEdit", ctx => {
var user *core.User
get "/userUnlink", ctx => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest to use /user/unlink instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yap now support this type of router?

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 => {
LiusCraft marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

@IRONICBo IRONICBo Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get /page/user-info

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),
}
}

Expand All @@ -149,7 +171,7 @@ get "/add", ctx => {
}
}
ctx.yap "edit", {
"User": user,
"User": user,
}
}

Expand Down Expand Up @@ -347,15 +369,15 @@ 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",
}
}
uid, err := community.ParseJwtToken(token.Value)
if err != nil {
xLog.Info("uid",err)
xLog.Info("uid", err)
ctx.json {
"code": 0,
"err": err.Error(),
Expand All @@ -367,11 +389,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)
Expand Down Expand Up @@ -450,26 +472,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 {
Expand Down Expand Up @@ -539,7 +561,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 = "/"
}

Expand All @@ -563,6 +585,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 {
println("error", err)
http.Redirect(w, r, "/failed", http.StatusFound)
}
}()
Expand Down
Loading
Loading