forked from TruthHun/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingController.go
More file actions
147 lines (131 loc) · 4.05 KB
/
SettingController.go
File metadata and controls
147 lines (131 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package controllers
import (
"os"
"path/filepath"
"strings"
"time"
"fmt"
"github.com/TruthHun/BookStack/conf"
"github.com/TruthHun/BookStack/models"
"github.com/TruthHun/BookStack/models/store"
"github.com/TruthHun/BookStack/utils"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"github.com/casdoor/casdoor-go-sdk/auth"
)
type SettingController struct {
BaseController
}
//基本信息
func (this *SettingController) Index() {
this.SetSession("isUpdateUser", 1)
account := this.GetSessionClaims()
if account == nil {
this.Redirect(beego.URLFor("AccountController.Login"), 302)
} else {
myProfileUrl := auth.GetMyProfileUrl(account.AccessToken)
this.Redirect(myProfileUrl, 302)
}
}
//收藏
func (this *SettingController) Star() {
page, _ := this.GetInt("page")
cid, _ := this.GetInt("cid")
if page < 1 {
page = 1
}
sort := this.GetString("sort", "read")
cnt, books, _ := new(models.Star).List(this.Member.MemberId, page, conf.PageSize, cid, sort)
if cnt > 1 {
//this.Data["PageHtml"] = utils.GetPagerHtml(this.Ctx.Request.RequestURI, page, listRows, int(cnt))
this.Data["PageHtml"] = utils.NewPaginations(conf.RollPage, int(cnt), conf.PageSize, page, beego.URLFor("SettingController.Star"), "")
}
this.Data["Pid"] = 0
cates := models.NewCategory().CategoryOfUserCollection(this.Member.MemberId)
for _, cate := range cates {
if cate.Id == cid {
if cate.Pid == 0 {
this.Data["Pid"] = cate.Id
} else {
this.Data["Pid"] = cate.Pid
}
}
}
this.Data["Books"] = books
this.Data["Sort"] = sort
this.Data["SettingStar"] = true
this.Data["SeoTitle"] = "我的收藏 - " + this.Sitename
this.TplName = "setting/star.html"
this.Data["Cid"] = cid
this.Data["Cates"] = cates
}
//二维码
func (this *SettingController) Qrcode() {
if this.Ctx.Input.IsPost() {
file, moreFile, err := this.GetFile("qrcode")
alipay := true
if this.GetString("paytype") == "wxpay" {
alipay = false
}
if err != nil {
beego.Error(err.Error())
this.JsonResult(500, "读取文件异常")
}
defer file.Close()
ext := filepath.Ext(moreFile.Filename)
if !strings.EqualFold(ext, ".png") && !strings.EqualFold(ext, ".jpg") && !strings.EqualFold(ext, ".gif") && !strings.EqualFold(ext, ".jpeg") {
this.JsonResult(500, "不支持的图片格式")
}
savePath := fmt.Sprintf("uploads/qrcode/%v/%v%v", this.Member.MemberId, time.Now().Unix(), ext)
os.MkdirAll(filepath.Dir(savePath), 0777)
if err = this.SaveToFile("qrcode", savePath); err != nil {
this.JsonResult(1, "二维码保存失败", savePath)
}
url := ""
switch utils.StoreType {
case utils.StoreOss:
if err := store.ModelStoreOss.MoveToOss(savePath, savePath, true, false); err != nil {
beego.Error(err.Error())
} else {
url = strings.TrimRight(beego.AppConfig.String("oss::Domain"), "/ ") + "/" + savePath
}
case utils.StoreLocal:
if err := store.ModelStoreLocal.MoveToStore(savePath, savePath); err != nil {
beego.Error(err.Error())
} else {
url = "/" + savePath
}
}
var member models.Member
o := orm.NewOrm()
o.QueryTable("md_members").Filter("member_id", this.Member.MemberId).Filter("member_id", this.Member.MemberId).One(&member, "member_id", "wxpay", "alipay")
if member.MemberId > 0 {
dels := []string{}
if alipay {
dels = append(dels, member.Alipay)
member.Alipay = savePath
} else {
dels = append(dels, member.Wxpay)
member.Wxpay = savePath
}
if _, err := o.Update(&member, "wxpay", "alipay"); err == nil {
switch utils.StoreType {
case utils.StoreOss:
go store.ModelStoreOss.DelFromOss(dels...)
case utils.StoreLocal:
go store.ModelStoreLocal.DelFiles(dels...)
}
}
}
//删除旧的二维码,并更新新的二维码
data := map[string]interface{}{
"url": url,
"alipay": alipay,
}
this.JsonResult(0, "二维码上传成功", data)
}
this.TplName = "setting/qrcode.html"
this.Data["SeoTitle"] = "二维码管理 - " + this.Sitename
this.Data["Qrcode"] = new(models.Member).GetQrcodeByUid(this.Member.MemberId)
this.Data["SettingQrcode"] = true
}