开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 1.2K

LC/BookStack

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
标签 (18)
master
dev
v2.8
v2.7
v2.6
v2.5
v2.4
v2.3
v2.2
v2.1
v2.0
v2.0-beta
v1.7
v1.6
v1.5
v1.4
v1.3.1
v1.3
v1.2
v1.1
master
分支 (2)
标签 (18)
master
dev
v2.8
v2.7
v2.6
v2.5
v2.4
v2.3
v2.2
v2.1
v2.0
v2.0-beta
v1.7
v1.6
v1.5
v1.4
v1.3.1
v1.3
v1.2
v1.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
标签 (18)
master
dev
v2.8
v2.7
v2.6
v2.5
v2.4
v2.3
v2.2
v2.1
v2.0
v2.0-beta
v1.7
v1.6
v1.5
v1.4
v1.3.1
v1.3
v1.2
v1.1
BookStack
/
controllers
/
ManagerController.go
BookStack
/
controllers
/
ManagerController.go
ManagerController.go 30.04 KB
一键复制 编辑 原始数据 按行查看 历史
TruthHun 提交于 2019年12月23日 12:41 +08:00 . 修改排行榜时间区间不正确的问题
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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
package controllers
import (
"encoding/json"
"html/template"
"net/http"
"regexp"
"strings"
"github.com/araddon/dateparse"
"path/filepath"
"strconv"
"fmt"
"time"
"os"
"github.com/TruthHun/BookStack/commands"
"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/logs"
"github.com/astaxie/beego/orm"
)
type ManagerController struct {
BaseController
}
func (this *ManagerController) Prepare() {
this.BaseController.Prepare()
if !this.Member.IsAdministrator() {
this.Abort("404")
}
}
func (this *ManagerController) Index() {
this.TplName = "manager/index.html"
this.Data["Model"] = models.NewDashboard().Query()
this.GetSeoByPage("manage_dashboard", map[string]string{
"title": "仪表盘 - " + this.Sitename,
"keywords": "仪表盘",
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
this.Data["IsDashboard"] = true
}
// 用户列表.
func (this *ManagerController) Users() {
this.TplName = "manager/users.html"
this.Data["IsUsers"] = true
wd := this.GetString("wd")
role, err := this.GetInt("role")
if err != nil {
role = -1
}
pageIndex, _ := this.GetInt("page", 0)
this.GetSeoByPage("manage_users", map[string]string{
"title": "用户管理 - " + this.Sitename,
"keywords": "用户管理",
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
members, totalCount, err := models.NewMember().FindToPager(pageIndex, conf.PageSize, wd, role)
if err != nil {
this.Data["ErrorMessage"] = err.Error()
return
}
if totalCount > 0 {
this.Data["PageHtml"] = utils.NewPaginations(conf.RollPage, int(totalCount), conf.PageSize, pageIndex, beego.URLFor("ManagerController.Users"), "")
} else {
this.Data["PageHtml"] = ""
}
b, err := json.Marshal(members)
if err != nil {
this.Data["Result"] = template.JS("[]")
} else {
this.Data["Result"] = template.JS(string(b))
}
this.Data["Role"] = role
this.Data["Wd"] = wd
}
// 标签管理.
func (this *ManagerController) Tags() {
this.TplName = "manager/tags.html"
this.Data["IsTag"] = true
size := 150
wd := this.GetString("wd")
pageIndex, _ := this.GetInt("page", 1)
tags, totalCount, err := models.NewLabel().FindToPager(pageIndex, size, wd)
if err != nil {
this.Data["ErrorMessage"] = err.Error()
return
}
if totalCount > 0 {
this.Data["PageHtml"] = utils.NewPaginations(conf.RollPage, int(totalCount), size, pageIndex, beego.URLFor("ManagerController.Tags"), "")
} else {
this.Data["PageHtml"] = ""
}
this.Data["Total"] = totalCount
this.Data["Tags"] = tags
this.Data["Wd"] = wd
}
func (this *ManagerController) AddTags() {
tags := this.GetString("tags")
if tags != "" {
tags = strings.Join(strings.Split(tags, "\n"), ",")
models.NewLabel().InsertOrUpdateMulti(tags)
}
this.JsonResult(0, "新增标签成功")
}
func (this *ManagerController) DelTags() {
id, _ := this.GetInt("id")
if id > 0 {
orm.NewOrm().QueryTable(models.NewLabel()).Filter("label_id", id).Delete()
}
this.JsonResult(0, "标签删除成功")
}
// 添加用户.
func (this *ManagerController) CreateMember() {
account := strings.TrimSpace(this.GetString("account"))
nickname := strings.TrimSpace(this.GetString("nickname"))
password1 := strings.TrimSpace(this.GetString("password1"))
password2 := strings.TrimSpace(this.GetString("password2"))
email := strings.TrimSpace(this.GetString("email"))
phone := strings.TrimSpace(this.GetString("phone"))
role, _ := this.GetInt("role", 1)
//status, _ := this.GetInt("status", 0)
if ok, err := regexp.MatchString(conf.RegexpAccount, account); account == "" || !ok || err != nil {
this.JsonResult(6001, "账号只能由英文字母数字组成,且在3-50个字符")
}
if l := strings.Count(nickname, "") - 1; l < 2 || l > 20 {
this.JsonResult(6001, "昵称限制在2-20个字符")
}
if l := strings.Count(password1, ""); password1 == "" || l > 50 || l < 6 {
this.JsonResult(6002, "密码必须在6-50个字符之间")
}
if password1 != password2 {
this.JsonResult(6003, "确认密码不正确")
}
if ok, err := regexp.MatchString(conf.RegexpEmail, email); !ok || err != nil || email == "" {
this.JsonResult(6004, "邮箱格式不正确")
}
if role != 0 && role != 1 && role != 2 {
role = 1
}
member := models.NewMember()
if _, err := member.FindByAccount(account); err == nil && member.MemberId > 0 {
this.JsonResult(6005, "账号已存在")
}
member.Account = account
member.Password = password1
member.Role = role
member.Avatar = conf.GetDefaultAvatar()
member.CreateAt = this.Member.MemberId
member.Email = email
member.Nickname = nickname
if phone != "" {
member.Phone = phone
}
if err := member.Add(); err != nil {
beego.Error(err.Error())
this.JsonResult(6006, "注册失败,可能昵称已存在")
}
this.JsonResult(0, "ok", member)
}
//更新用户状态.
func (this *ManagerController) UpdateMemberStatus() {
memberId, _ := this.GetInt("member_id", 0)
status, _ := this.GetInt("status", 0)
if memberId <= 0 {
this.JsonResult(6001, "参数错误")
}
if status != 0 && status != 1 {
status = 0
}
member := models.NewMember()
if _, err := member.Find(memberId); err != nil {
this.JsonResult(6002, "用户不存在")
}
if member.MemberId == this.Member.MemberId {
this.JsonResult(6004, "不能变更自己的状态")
}
if member.Role == conf.MemberSuperRole {
this.JsonResult(6005, "不能变更超级管理员的状态")
}
member.Status = status
if err := member.Update(); err != nil {
logs.Error("", err)
this.JsonResult(6003, "用户状态设置失败")
}
this.JsonResult(0, "ok", member)
}
//变更用户权限.
func (this *ManagerController) ChangeMemberRole() {
memberId, _ := this.GetInt("member_id", 0)
role, _ := this.GetInt("role", 0)
if memberId <= 0 {
this.JsonResult(6001, "参数错误")
}
if role != conf.MemberAdminRole && role != conf.MemberGeneralRole && role != conf.MemberEditorRole {
this.JsonResult(6001, "用户权限不正确")
}
member := models.NewMember()
if _, err := member.Find(memberId); err != nil {
this.JsonResult(6002, "用户不存在")
}
if member.MemberId == this.Member.MemberId {
this.JsonResult(6004, "不能变更自己的权限")
}
if member.Role == conf.MemberSuperRole {
this.JsonResult(6005, "不能变更超级管理员的权限")
}
member.Role = role
if err := member.Update(); err != nil {
logs.Error("", err)
this.JsonResult(6003, "用户权限设置失败")
}
member.ResolveRoleName()
this.JsonResult(0, "ok", member)
}
//编辑用户信息.
func (this *ManagerController) EditMember() {
memberId, _ := this.GetInt(":id", 0)
if memberId <= 0 {
this.Abort("404")
}
member, err := models.NewMember().Find(memberId)
if err != nil {
beego.Error(err)
this.Abort("404")
}
if this.Ctx.Input.IsPost() {
password1 := this.GetString("password1")
password2 := this.GetString("password2")
email := this.GetString("email")
phone := this.GetString("phone")
description := this.GetString("description")
member.Email = email
member.Phone = phone
member.Description = description
if password1 != "" && password2 != password1 {
this.JsonResult(6001, "确认密码不正确")
}
if password1 != "" && member.AuthMethod != conf.AuthMethodLDAP {
member.Password = password1
}
if err := member.Valid(password1 == ""); err != nil {
this.JsonResult(6002, err.Error())
}
if password1 != "" {
password, err := utils.PasswordHash(password1)
if err != nil {
beego.Error(err)
this.JsonResult(6003, "对用户密码加密时出错")
}
member.Password = password
}
if err := member.Update(); err != nil {
beego.Error(err)
this.JsonResult(6004, "保存失败")
}
this.JsonResult(0, "ok")
}
this.GetSeoByPage("manage_users_edit", map[string]string{
"title": "用户编辑 - " + this.Sitename,
"keywords": "用户标记",
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
this.Data["IsUsers"] = true
this.Data["Model"] = member
this.TplName = "manager/edit_users.html"
}
//删除一个用户,并将该用户的所有信息转移到超级管理员上.
func (this *ManagerController) DeleteMember() {
memberId, _ := this.GetInt("id", 0)
if memberId <= 0 {
this.JsonResult(404, "参数错误")
}
member, err := models.NewMember().Find(memberId)
if err != nil {
beego.Error(err)
this.JsonResult(500, "用户不存在")
}
if member.Role == conf.MemberSuperRole {
this.JsonResult(500, "不能删除超级管理员")
}
superMember, err := models.NewMember().FindByFieldFirst("role", 0)
if err != nil {
beego.Error(err)
this.JsonResult(5001, "未能找到超级管理员")
}
err = models.NewMember().Delete(memberId, superMember.MemberId)
if err != nil {
beego.Error(err)
this.JsonResult(5002, "删除失败")
}
this.JsonResult(0, "ok")
}
//项目列表.
func (this *ManagerController) Books() {
pageIndex, _ := this.GetInt("page", 1)
private, _ := this.GetInt("private")
books, totalCount, err := models.NewBookResult().FindToPager(pageIndex, conf.PageSize, private)
if err != nil {
this.Abort("404")
}
if totalCount > 0 {
this.Data["PageHtml"] = utils.NewPaginations(conf.RollPage, totalCount, conf.PageSize, pageIndex, beego.URLFor("ManagerController.Books"), fmt.Sprintf("&private=%v", private))
} else {
this.Data["PageHtml"] = ""
}
this.Data["Lists"] = books
this.Data["IsBooks"] = true
this.GetSeoByPage("manage_project_list", map[string]string{
"title": "项目管理 - " + this.Sitename,
"keywords": "项目管理",
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
this.Data["Private"] = private
this.TplName = "manager/books.html"
}
//编辑项目.
func (this *ManagerController) EditBook() {
identify := this.GetString(":key")
if identify == "" {
this.Abort("404")
}
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
this.Abort("404")
}
if this.Ctx.Input.IsPost() {
bookName := strings.TrimSpace(this.GetString("book_name"))
description := strings.TrimSpace(this.GetString("description", ""))
commentStatus := this.GetString("comment_status")
tag := strings.TrimSpace(this.GetString("label"))
orderIndex, _ := this.GetInt("order_index", 0)
pin, _ := this.GetInt("pin", 0)
if strings.Count(description, "") > 500 {
this.JsonResult(6004, "项目描述不能大于500字")
}
if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" {
commentStatus = "closed"
}
if tag != "" {
tags := strings.Split(tag, ";")
if len(tags) > 10 {
this.JsonResult(6005, "最多允许添加10个标签")
}
}
book.BookName = bookName
book.Description = description
book.CommentStatus = commentStatus
book.Label = tag
book.OrderIndex = orderIndex
book.Pin = pin
if err := book.Update(); err != nil {
this.JsonResult(6006, "保存失败")
}
go func() {
es := models.ElasticSearchData{
Id: book.BookId,
BookId: 0,
Title: book.BookName,
Keywords: book.Label,
Content: book.Description,
Vcnt: book.Vcnt,
Private: book.PrivatelyOwned,
}
client := models.NewElasticSearchClient()
if errSearch := client.BuildIndex(es); errSearch != nil && client.On {
beego.Error(err.Error())
}
}()
this.JsonResult(0, "ok")
}
if book.PrivateToken != "" {
book.PrivateToken = this.BaseUrl() + beego.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)
}
this.Data["Model"] = book
this.GetSeoByPage("manage_project_edit", map[string]string{
"title": "项目设置 - " + this.Sitename,
"keywords": "项目设置",
"description": this.Sitename + "专注于文档在线写作、协作、分享、阅读与托管,让每个人更方便地发布、分享和获得知识。",
})
this.TplName = "manager/edit_book.html"
}
// 删除项目.
func (this *ManagerController) DeleteBook() {
bookId, _ := this.GetInt("book_id", 0)
if bookId <= 0 {
this.JsonResult(6001, "参数错误")
}
//用户密码
pwd := this.GetString("password")
if m, err := models.NewMember().Login(this.Member.Account, pwd); err != nil || m.MemberId == 0 {
this.JsonResult(1, "项目删除失败,您的登录密码不正确")
}
book := models.NewBook()
b, _ := book.Find(bookId)
if b.Identify != this.GetString("identify") {
this.JsonResult(1, "项目删除失败,您输入的文档标识不正确")
}
err := book.ThoroughDeleteBook(bookId)
if err == orm.ErrNoRows {
this.JsonResult(6002, "项目不存在")
}
if err != nil {
logs.Error("DeleteBook => ", err)
this.JsonResult(6003, "删除失败")
}
go func() {
client := models.NewElasticSearchClient()
if errDel := client.DeleteIndex(bookId, true); errDel != nil && client.On {
beego.Error(errDel.Error())
}
}()
this.JsonResult(0, "项目删除成功")
}
// CreateToken 创建访问来令牌.
func (this *ManagerController) CreateToken() {
if this.forbidGeneralRole() {
this.JsonResult(6001, "您的角色非作者和管理员,无法创建访问令牌")
}
action := this.GetString("action")
identify := this.GetString("identify")
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
this.JsonResult(6001, "项目不存在")
}
if action == "create" {
if book.PrivatelyOwned == 0 {
this.JsonResult(6001, "公开项目不能创建阅读令牌")
}
book.PrivateToken = string(utils.Krand(conf.GetTokenSize(), utils.KC_RAND_KIND_ALL))
if err := book.Update(); err != nil {
logs.Error("生成阅读令牌失败 => ", err)
this.JsonResult(6003, "生成阅读令牌失败")
}
this.JsonResult(0, "ok", this.BaseUrl()+beego.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken))
}
book.PrivateToken = ""
if err := book.Update(); err != nil {
beego.Error("CreateToken => ", err)
this.JsonResult(6004, "删除令牌失败")
}
this.JsonResult(0, "ok", "")
}
func (this *ManagerController) Setting() {
options, err := models.NewOption().All()
if err != nil {
this.Abort("404")
}
if this.Ctx.Input.IsPost() {
for _, item := range options {
item.OptionValue = this.GetString(item.OptionName)
item.InsertOrUpdate()
}
if err := models.NewElasticSearchClient().Init(); err != nil {
this.JsonResult(1, err.Error())
}
models.NewSign().UpdateSignRule()
models.NewReadRecord().UpdateReadingRule()
this.JsonResult(0, "ok")
}
for _, item := range options {
if item.OptionName == "APP_PAGE" {
this.Data["APP_PAGE"] = item.OptionValue
this.Data["M_APP_PAGE"] = item
} else {
this.Data[item.OptionName] = item
}
}
this.Data["SITE_TITLE"] = this.Option["SITE_NAME"]
this.Data["IsSetting"] = true
this.Data["SeoTitle"] = "配置管理"
this.TplName = "manager/setting.html"
}
// Transfer 转让项目.
func (this *ManagerController) Transfer() {
account := this.GetString("account")
if account == "" {
this.JsonResult(6004, "接受者账号不能为空")
}
member, err := models.NewMember().FindByAccount(account)
if err != nil {
beego.Error("FindByAccount => ", err)
this.JsonResult(6005, "接受用户不存在")
}
if member.Status != 0 {
this.JsonResult(6006, "接受用户已被禁用")
}
if !this.Member.IsAdministrator() {
this.Abort("404")
}
identify := this.GetString("identify")
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
this.JsonResult(6001, err.Error())
}
rel, err := models.NewRelationship().FindFounder(book.BookId)
if err != nil {
beego.Error("FindFounder => ", err)
this.JsonResult(6009, "查询项目创始人失败")
}
if member.MemberId == rel.MemberId {
this.JsonResult(6007, "不能转让给自己")
}
err = models.NewRelationship().Transfer(book.BookId, rel.MemberId, member.MemberId)
if err != nil {
beego.Error("Transfer => ", err)
this.JsonResult(6008, err.Error())
}
this.JsonResult(0, "ok")
}
func (this *ManagerController) Comments() {
status := this.GetString("status", "0")
statusNum, _ := strconv.Atoi(status)
p, _ := this.GetInt("page", 1)
size, _ := this.GetInt("size", 10)
m := models.NewComments()
if status == "" {
this.Data["Comments"], _ = m.Comments(p, size, 0)
} else {
this.Data["Comments"], _ = m.Comments(p, size, 0, statusNum)
}
this.Data["IsComments"] = true
this.Data["Status"] = status
count, _ := m.Count(0, statusNum)
this.Data["Count"] = count
if count > 0 {
html := utils.GetPagerHtml(this.Ctx.Request.RequestURI, p, size, int(count))
this.Data["PageHtml"] = html
}
this.TplName = "manager/comments.html"
}
func (this *ManagerController) ClearComments() {
uid, _ := this.GetInt("uid")
if uid > 0 {
models.NewComments().ClearComments(uid)
}
this.JsonResult(0, "清除成功")
}
func (this *ManagerController) DeleteComment() {
id, _ := this.GetInt("id")
if id > 0 {
models.NewComments().DeleteComment(id)
}
this.JsonResult(0, "删除成功")
}
func (this *ManagerController) SetCommentStatus() {
id, _ := this.GetInt("id")
status, _ := this.GetInt("value")
field := this.GetString("field")
if id > 0 && field == "status" {
if err := models.NewComments().SetCommentStatus(id, status); err != nil {
this.JsonResult(1, err.Error())
}
}
this.JsonResult(0, "设置成功")
}
//设置项目私有状态.
func (this *ManagerController) PrivatelyOwned() {
status := this.GetString("status")
identify := this.GetString("identify")
if status != "open" && status != "close" {
this.JsonResult(6003, "参数错误")
}
state := 0
if status == "open" {
state = 0
} else {
state = 1
}
if !this.Member.IsAdministrator() {
this.Abort("404")
}
book, err := models.NewBook().FindByFieldFirst("identify", identify)
if err != nil {
this.JsonResult(6001, err.Error())
}
book.PrivatelyOwned = state
beego.Info("", state, status)
err = book.Update()
if err != nil {
beego.Error("PrivatelyOwned => ", err)
this.JsonResult(6004, "保存失败")
}
go func() {
models.CountCategory()
public := true
if state == 1 {
public = false
}
client := models.NewElasticSearchClient()
if errSet := client.SetBookPublic(book.BookId, public); errSet != nil && client.On {
beego.Error(errSet.Error())
}
}()
this.JsonResult(0, "ok")
}
//附件列表.
func (this *ManagerController) AttachList() {
pageIndex, _ := this.GetInt("page", 1)
attachList, totalCount, err := models.NewAttachment().FindToPager(pageIndex, conf.PageSize)
if err != nil {
this.Abort("404")
}
if totalCount > 0 {
html := utils.GetPagerHtml(this.Ctx.Request.RequestURI, pageIndex, conf.PageSize, int(totalCount))
this.Data["PageHtml"] = html
} else {
this.Data["PageHtml"] = ""
}
for _, item := range attachList {
p := filepath.Join(commands.WorkingDirectory, item.FilePath)
item.IsExist = utils.FileExists(p)
}
this.Data["Lists"] = attachList
this.Data["IsAttach"] = true
this.TplName = "manager/attach_list.html"
}
//附件详情.
func (this *ManagerController) AttachDetailed() {
attachId, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
if attachId <= 0 {
this.Abort("404")
}
attach, err := models.NewAttachmentResult().Find(attachId)
if err != nil {
beego.Error("AttachDetailed => ", err)
if err == orm.ErrNoRows {
this.Abort("404")
}
this.Abort("404")
}
attach.FilePath = filepath.Join(commands.WorkingDirectory, attach.FilePath)
attach.HttpPath = this.BaseUrl() + attach.HttpPath
attach.IsExist = utils.FileExists(attach.FilePath)
this.Data["Model"] = attach
this.TplName = "manager/attach_detailed.html"
}
//删除附件.
func (this *ManagerController) AttachDelete() {
attachId, _ := this.GetInt("attach_id")
if attachId <= 0 {
this.Abort("404")
}
attach, err := models.NewAttachment().Find(attachId)
if err != nil {
beego.Error("AttachDelete => ", err)
this.JsonResult(6001, err.Error())
}
if err := attach.Delete(); err != nil {
beego.Error("AttachDelete => ", err)
this.JsonResult(6002, err.Error())
}
this.JsonResult(0, "ok")
}
//SEO管理
func (this *ManagerController) Seo() {
o := orm.NewOrm()
if this.Ctx.Input.IsPost() { //SEO更新
rows, err := o.QueryTable(models.TableSeo).Filter("id", this.GetString("id")).Update(map[string]interface{}{
this.GetString("field"): this.GetString("value"),
})
if err != nil {
beego.Error(err.Error())
this.JsonResult(1, "更新失败,请求错误")
}
if rows > 0 {
this.JsonResult(0, "更新成功")
}
this.JsonResult(1, "更新失败,您未对内容做更改")
}
//SEO展示
var seos []models.Seo
o.QueryTable(models.TableSeo).All(&seos)
this.Data["Lists"] = seos
this.Data["IsManagerSeo"] = true
this.TplName = "manager/seo.html"
}
func (this *ManagerController) UpdateAds() {
id, _ := this.GetInt("id")
field := this.GetString("field")
value := this.GetString("value")
if field == "" {
this.JsonResult(1, "字段不能为空")
}
_, err := orm.NewOrm().QueryTable(models.NewAdsCont()).Filter("id", id).Update(orm.Params{field: value})
if err != nil {
this.JsonResult(1, err.Error())
}
go models.UpdateAdsCache()
this.JsonResult(0, "操作成功")
}
func (this *ManagerController) DelAds() {
id, _ := this.GetInt("id")
_, err := orm.NewOrm().QueryTable(models.NewAdsCont()).Filter("id", id).Delete()
if err != nil {
this.JsonResult(1, err.Error())
}
go models.UpdateAdsCache()
this.JsonResult(0, "删除成功")
}
//广告管理
func (this *ManagerController) Ads() {
if this.Ctx.Request.Method == http.MethodPost {
pid, _ := this.GetInt("pid")
if pid <= 0 {
this.JsonResult(1, "请选择广告位")
}
ads := &models.AdsCont{
Title: this.GetString("title"),
Code: this.GetString("code"),
Status: true,
Pid: pid,
}
start, err := dateparse.ParseAny(this.GetString("start"))
if err != nil {
start = time.Now()
}
end, err := dateparse.ParseAny(this.GetString("end"))
if err != nil {
end = time.Now().Add(24 * time.Hour * 730)
}
ads.Start = int(start.Unix())
ads.End = int(end.Unix())
_, err = orm.NewOrm().Insert(ads)
if err != nil {
this.JsonResult(1, err.Error())
}
go models.UpdateAdsCache()
this.JsonResult(0, "新增广告成功")
} else {
layout := "2006-01-02"
this.Data["Mobile"] = this.GetString("mobile", "0")
this.Data["Positions"] = models.NewAdsCont().GetPositions()
this.Data["Lists"] = models.NewAdsCont().Lists(this.GetString("mobile", "0") == "1")
this.Data["IsAds"] = true
this.Data["Now"] = time.Now().Format(layout)
this.Data["Next"] = time.Now().Add(time.Hour * 24 * 730).Format(layout)
this.TplName = "manager/ads.html"
}
}
//更行书籍项目的排序
func (this *ManagerController) UpdateBookSort() {
bookId, _ := this.GetInt("book_id")
orderIndex, _ := this.GetInt("value")
if bookId > 0 {
if _, err := orm.NewOrm().QueryTable("md_books").Filter("book_id", bookId).Update(orm.Params{
"order_index": orderIndex,
}); err != nil {
this.JsonResult(1, err.Error())
}
}
this.JsonResult(0, "排序更新成功")
}
func (this *ManagerController) Sitemap() {
baseUrl := this.Ctx.Input.Scheme() + "://" + this.Ctx.Request.Host
if host := beego.AppConfig.String("sitemap_host"); len(host) > 0 {
baseUrl = this.Ctx.Input.Scheme() + "://" + host
}
go models.SitemapUpdate(baseUrl)
this.JsonResult(0, "站点地图更新提交成功,已交由后台执行更新,请耐心等待。")
}
//分类管理
func (this *ManagerController) Category() {
Model := new(models.Category)
if strings.ToLower(this.Ctx.Request.Method) == "post" {
//新增分类
pid, _ := this.GetInt("pid")
if err := Model.AddCates(pid, this.GetString("cates")); err != nil {
this.JsonResult(1, "新增失败:"+err.Error())
}
this.JsonResult(0, "新增成功")
}
//查询所有分类
cates, err := Model.GetCates(-1, -1)
if err != nil {
beego.Error(err)
}
var parents []models.Category
for idx, item := range cates {
if strings.TrimSpace(item.Icon) == "" { //赋值为默认图片
item.Icon = "/static/images/icon.png"
} else {
item.Icon = utils.ShowImg(item.Icon)
}
if item.Pid == 0 {
parents = append(parents, item)
}
cates[idx] = item
}
this.Data["Parents"] = parents
this.Data["Cates"] = cates
this.Data["IsCategory"] = true
this.TplName = "manager/category.html"
}
//更新分类字段内容
func (this *ManagerController) UpdateCate() {
field := this.GetString("field")
val := this.GetString("value")
id, _ := this.GetInt("id")
if err := new(models.Category).UpdateByField(id, field, val); err != nil {
this.JsonResult(1, "更新失败:"+err.Error())
}
this.JsonResult(0, "更新成功")
}
//删除分类
func (this *ManagerController) DelCate() {
var err error
if id, _ := this.GetInt("id"); id > 0 {
err = new(models.Category).Del(id)
}
if err != nil {
this.JsonResult(1, err.Error())
}
this.JsonResult(0, "删除成功")
}
//更新分类的图标
func (this *ManagerController) UpdateCateIcon() {
var err error
id, _ := this.GetInt("id")
if id == 0 {
this.JsonResult(1, "参数不正确")
}
model := new(models.Category)
if cate := model.Find(id); cate.Id > 0 {
cate.Icon = strings.TrimLeft(cate.Icon, "/")
f, h, err1 := this.GetFile("icon")
if err1 != nil {
err = err1
}
defer f.Close()
tmpFile := fmt.Sprintf("uploads/icons/%v%v"+filepath.Ext(h.Filename), id, time.Now().Unix())
os.MkdirAll(filepath.Dir(tmpFile), os.ModePerm)
if err = this.SaveToFile("icon", tmpFile); err == nil {
switch utils.StoreType {
case utils.StoreOss:
store.ModelStoreOss.MoveToOss(tmpFile, tmpFile, true, false)
store.ModelStoreOss.DelFromOss(cate.Icon)
case utils.StoreLocal:
store.ModelStoreLocal.DelFiles(cate.Icon)
}
err = model.UpdateByField(cate.Id, "icon", "/"+tmpFile)
}
}
if err != nil {
this.JsonResult(1, err.Error())
}
this.JsonResult(0, "更新成功")
}
//友情链接
func (this *ManagerController) FriendLink() {
this.Data["SeoTitle"] = "友链管理"
this.Data["Links"] = new(models.FriendLink).GetList(true)
this.Data["IsFriendlink"] = true
this.TplName = "manager/friendlink.html"
}
//添加友链
func (this *ManagerController) AddFriendlink() {
if err := new(models.FriendLink).Add(this.GetString("title"), this.GetString("link")); err != nil {
this.JsonResult(1, "新增友链失败:"+err.Error())
}
this.JsonResult(0, "新增友链成功")
}
//更新友链
func (this *ManagerController) UpdateFriendlink() {
id, _ := this.GetInt("id")
if err := new(models.FriendLink).Update(id, this.GetString("field"), this.GetString("value")); err != nil {
this.JsonResult(1, "操作失败:"+err.Error())
}
this.JsonResult(0, "操作成功")
}
//删除友链
func (this *ManagerController) DelFriendlink() {
id, _ := this.GetInt("id")
if err := new(models.FriendLink).Del(id); err != nil {
this.JsonResult(1, "删除失败:"+err.Error())
}
this.JsonResult(0, "删除成功")
}
// 重建全量索引
func (this *ManagerController) RebuildAllIndex() {
go models.NewElasticSearchClient().RebuildAllIndex()
this.JsonResult(0, "提交成功,请耐心等待")
}
func (this *ManagerController) Banners() {
this.Data["SeoTitle"] = "横幅管理"
this.TplName = "manager/banners.html"
this.Data["Banners"], _ = models.NewBanner().All()
this.Data["IsBanner"] = true
}
func (this *ManagerController) DeleteBanner() {
id, _ := this.GetInt("id")
if id > 0 {
err := models.NewBanner().Delete(id)
if err != nil {
this.JsonResult(1, err.Error())
}
}
this.JsonResult(0, "删除成功")
}
func (this *ManagerController) UpdateBanner() {
id, _ := this.GetInt("id")
field := this.GetString("field")
value := this.GetString("value")
if id > 0 {
err := models.NewBanner().Update(id, field, value)
if err != nil {
this.JsonResult(1, err.Error())
}
}
this.JsonResult(0, "更新成功")
}
func (this *ManagerController) UploadBanner() {
f, h, err := this.GetFile("image")
if err != nil {
this.JsonResult(1, err.Error())
}
ext := strings.ToLower(filepath.Ext(strings.ToLower(h.Filename)))
tmpFile := fmt.Sprintf("uploads/tmp/banner-%v-%v%v", this.Member.MemberId, time.Now().Unix(), ext)
destFile := fmt.Sprintf("uploads/banners/%v.%v%v", this.Member.MemberId, time.Now().Unix(), ext)
defer func() {
f.Close()
os.Remove(tmpFile)
if err != nil {
utils.DeleteFile(destFile)
}
}()
os.MkdirAll(filepath.Dir(tmpFile), os.ModePerm)
err = this.SaveToFile("image", tmpFile)
if err != nil {
this.JsonResult(1, err.Error())
}
err = utils.UploadFile(tmpFile, destFile)
if err != nil {
this.JsonResult(1, err.Error())
}
banner := &models.Banner{
Image: "/" + destFile,
Type: this.GetString("type"),
Title: this.GetString("title"),
Link: this.GetString("link"),
Status: true,
CreatedAt: time.Now(),
}
banner.Sort, _ = this.GetInt("sort")
_, err = orm.NewOrm().Insert(banner)
if err != nil {
this.JsonResult(1, err.Error())
}
this.JsonResult(0, "横幅上传成功")
}
func (this *ManagerController) SubmitBook() {
this.TplName = "manager/submit_book.html"
m := models.NewSubmitBooks()
page, _ := this.GetInt("page", 1)
size, _ := this.GetInt("size", 100)
books, total, _ := m.Lists(page, size)
if total > 0 {
this.Data["PageHtml"] = utils.NewPaginations(conf.RollPage, int(total), size, page, beego.URLFor("ManagerController.SubmitBook"), "")
} else {
this.Data["PageHtml"] = ""
}
this.Data["Books"] = books
this.Data["IsSubmitBook"] = true
}
func (this *ManagerController) DeleteSubmitBook() {
id, _ := this.GetInt("id")
orm.NewOrm().QueryTable(models.NewSubmitBooks()).Filter("id", id).Delete()
this.JsonResult(0, "删除成功")
}
func (this *ManagerController) UpdateSubmitBook() {
field := this.GetString("field")
value := this.GetString("value")
id, _ := this.GetInt("id")
if id > 0 {
_, err := orm.NewOrm().QueryTable(models.NewSubmitBooks()).Filter("id", id).Update(orm.Params{field: value})
if err != nil {
this.JsonResult(1, err.Error())
}
}
this.JsonResult(0, "更新成功")
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

BookStack,基于MinDoc,使用Beego开发的在线文档管理系统,功能类似Gitbook和看云。
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/tinyLC/BookStack.git
git@gitee.com:tinyLC/BookStack.git
tinyLC
BookStack
BookStack
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /