Skip to content

Commit

Permalink
Merge pull request #192 from Baihhh/mergeUser
Browse files Browse the repository at this point in the history
feat:user edit
  • Loading branch information
IRONICBo authored Feb 26, 2024
2 parents e95bf2f + afd62ed commit 0f2e440
Show file tree
Hide file tree
Showing 9 changed files with 1,615 additions and 605 deletions.
68 changes: 63 additions & 5 deletions cmd/gopcomm/community_yap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,39 @@ get "/success", ctx => {
}

get "/error", ctx => {
ctx.yap "4xx", {}
var user *core.User
userId := ""
token, err := core.GetToken(ctx)
if err == nil {
user, err = community.GetUser(token.Value)
if err != nil {
xLog.Error("get user error:", err)
} else {
userId = user.Id
}
}
ctx.yap "4xx", {
"UserId": userId,
"User": user,
}
}

get "/failed", ctx => {
ctx.yap "5xx", {}
var user *core.User
userId := ""
token, err := core.GetToken(ctx)
if err == nil {
user, err = community.GetUser(token.Value)
if err != nil {
xLog.Error("get user error:", err)
} else {
userId = user.Id
}
}
ctx.yap "5xx", {
"UserId": userId,
"User": user,
}
}

get "/demo", ctx => {
Expand Down Expand Up @@ -150,18 +178,48 @@ get "/userEdit", ctx => {
if err != nil {
http.Redirect(ctx.ResponseWriter, ctx.Request, "/error", http.StatusTemporaryRedirect)
}
fullUser, _ := gac.GetUser()
appInfo, _ := community.GetApplicationInfo()
appInfoStr, _ := json.Marshal(*appInfo)
binds, _ := json.Marshal(gac.GetProviderBindStatus())
currentUser, _ := json.Marshal(fullUser)
user := gac.GetUserSimple()
ctx.yap "user_edit", {
"UserId": user.Id,
"User": user,
"CurrentUser": string(currentUser),
"Application": string(appInfoStr),
"Binds": string(binds),
}
}

post "/update/user", ctx => {
token, err := core.GetToken(ctx)
uid, err := community.ParseJwtToken(token.Value)
user := &core.UserInfo{
Id: uid,
Name: ctx.param("name"),
Birthday: ctx.param("birthday"),
Gender: ctx.param("gender"),
Phone: ctx.param("phone"),
Email: ctx.param("email"),
Avatar: ctx.param("avatar"),
Owner: ctx.param("owner"),
DisplayName: ctx.param("name"),
}
_, err = community.UpdateUserById(fmt.Sprintf("%s/%s", user.Owner, user.Name), user)
if err != nil {
xLog.Info(err)
ctx.json {
"code": 0,
"msg": "update failed",
}
}
ctx.json {
"code": 200,
}
}

get "/add", ctx => {
var user *core.User
userId := ""
Expand Down Expand Up @@ -218,17 +276,17 @@ get "/medias", ctx => {
if err != nil {
limitInt = limitConst
}
files,count,err := community.ListMediaByUserId(todo, uid, format,pageInt,limitInt)
files, count, err := community.ListMediaByUserId(todo, uid, format,pageInt,limitInt)
if err != nil {
ctx.json {
"code": 0,
"count": count,
"total": count,
"err": err.Error(),
}
} else {
ctx.json {
"code": 200,
"count": count,
"total": count,
"items": files,
}
}
Expand Down
Loading

0 comments on commit 0f2e440

Please sign in to comment.