DocumentController.go 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  1. package controllers
  2. import (
  3. "container/list"
  4. "encoding/json"
  5. "html/template"
  6. "net/http"
  7. "os"
  8. "path/filepath"
  9. "regexp"
  10. "strconv"
  11. "strings"
  12. "time"
  13. "net/url"
  14. "image/png"
  15. "fmt"
  16. "bytes"
  17. "github.com/PuerkitoBio/goquery"
  18. "github.com/astaxie/beego"
  19. "github.com/astaxie/beego/orm"
  20. "github.com/boombuler/barcode"
  21. "github.com/boombuler/barcode/qr"
  22. "github.com/lifei6671/mindoc/conf"
  23. "github.com/lifei6671/mindoc/models"
  24. "github.com/lifei6671/mindoc/utils"
  25. "github.com/lifei6671/mindoc/utils/pagination"
  26. "gopkg.in/russross/blackfriday.v2"
  27. "github.com/lifei6671/mindoc/utils/cryptil"
  28. "github.com/lifei6671/mindoc/utils/filetil"
  29. "github.com/lifei6671/mindoc/utils/gopool"
  30. "github.com/astaxie/beego/logs"
  31. )
  32. // DocumentController struct
  33. type DocumentController struct {
  34. BaseController
  35. }
  36. // 文档首页
  37. func (c *DocumentController) Index() {
  38. c.Prepare()
  39. identify := c.Ctx.Input.Param(":key")
  40. token := c.GetString("token")
  41. if identify == "" {
  42. c.ShowErrorPage(404, "项目不存在或已删除")
  43. }
  44. // 如果没有开启匿名访问则跳转到登录
  45. if !c.EnableAnonymous && !isUserLoggedIn(c) {
  46. promptUserToLogIn(c)
  47. return
  48. }
  49. bookResult := isReadable(identify, token, c)
  50. c.TplName = "document/" + bookResult.Theme + "_read.tpl"
  51. selected := 0
  52. if bookResult.IsUseFirstDocument {
  53. doc, err := bookResult.FindFirstDocumentByBookId(bookResult.BookId)
  54. if err == nil {
  55. selected = doc.DocumentId
  56. c.Data["Title"] = doc.DocumentName
  57. c.Data["Content"] = template.HTML(doc.Release)
  58. c.Data["Description"] = utils.AutoSummary(doc.Release, 120)
  59. }
  60. } else {
  61. c.Data["Title"] = "概要"
  62. c.Data["Content"] = template.HTML(blackfriday.Run([]byte(bookResult.Description)))
  63. }
  64. tree, err := models.NewDocument().CreateDocumentTreeForHtml(bookResult.BookId, selected)
  65. if err != nil {
  66. if err == orm.ErrNoRows {
  67. c.ShowErrorPage(404, "当前项目没有文档")
  68. } else {
  69. beego.Error("生成项目文档树时出错 -> ", err)
  70. c.ShowErrorPage(500, "生成项目文档树时出错")
  71. }
  72. }
  73. c.Data["Model"] = bookResult
  74. c.Data["Result"] = template.HTML(tree)
  75. }
  76. // 阅读文档
  77. func (c *DocumentController) Read() {
  78. c.Prepare()
  79. identify := c.Ctx.Input.Param(":key")
  80. token := c.GetString("token")
  81. id := c.GetString(":id")
  82. c.Data["DocumentId"] = id
  83. if identify == "" || id == "" {
  84. c.ShowErrorPage(404, "项目不存或已删除")
  85. }
  86. // 如果没有开启匿名访问则跳转到登录
  87. if !c.EnableAnonymous && !isUserLoggedIn(c) {
  88. promptUserToLogIn(c)
  89. return
  90. }
  91. bookResult := isReadable(identify, token, c)
  92. c.TplName = fmt.Sprintf("document/%s_read.tpl", bookResult.Theme)
  93. doc := models.NewDocument()
  94. if docId, err := strconv.Atoi(id); err == nil {
  95. doc, err = doc.FromCacheById(docId)
  96. if err != nil {
  97. beego.Error("从缓存中读取文档时失败 ->", err)
  98. c.ShowErrorPage(404, "文档不存在或已删除")
  99. }
  100. } else {
  101. doc, err = doc.FromCacheByIdentify(id, bookResult.BookId)
  102. if err != nil {
  103. if err == orm.ErrNoRows {
  104. c.ShowErrorPage(404, "文档不存在或已删除")
  105. } else {
  106. beego.Error("从缓存查询文档时出错 ->", err)
  107. c.ShowErrorPage(500, "未知异常")
  108. }
  109. }
  110. }
  111. if doc.BookId != bookResult.BookId {
  112. c.ShowErrorPage(404, "文档不存在或已删除")
  113. }
  114. doc.Processor()
  115. attach, err := models.NewAttachment().FindListByDocumentId(doc.DocumentId)
  116. if err == nil {
  117. doc.AttachList = attach
  118. }
  119. if c.IsAjax() {
  120. var data struct {
  121. DocTitle string `json:"doc_title"`
  122. Body string `json:"body"`
  123. Title string `json:"title"`
  124. Version int64 `json:"version"`
  125. }
  126. data.DocTitle = doc.DocumentName
  127. data.Body = doc.Release
  128. data.Title = doc.DocumentName + " - Powered by MinDoc"
  129. data.Version = doc.Version
  130. c.JsonResult(0, "ok", data)
  131. }
  132. tree, err := models.NewDocument().CreateDocumentTreeForHtml(bookResult.BookId, doc.DocumentId)
  133. if err != nil && err != orm.ErrNoRows {
  134. beego.Error("生成项目文档树时出错 ->", err)
  135. c.ShowErrorPage(500, "生成项目文档树时出错")
  136. }
  137. c.Data["Description"] = utils.AutoSummary(doc.Release, 120)
  138. c.Data["Model"] = bookResult
  139. c.Data["Result"] = template.HTML(tree)
  140. c.Data["Title"] = doc.DocumentName
  141. c.Data["Content"] = template.HTML(doc.Release)
  142. }
  143. // 编辑文档
  144. func (c *DocumentController) Edit() {
  145. c.Prepare()
  146. identify := c.Ctx.Input.Param(":key")
  147. if identify == "" {
  148. c.ShowErrorPage(404, "无法解析项目标识")
  149. }
  150. bookResult := models.NewBookResult()
  151. var err error
  152. // 如果是超级管理者,则不判断权限
  153. if c.Member.IsAdministrator() {
  154. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  155. if err != nil {
  156. c.JsonResult(6002, "项目不存在或权限不足")
  157. }
  158. bookResult = models.NewBookResult().ToBookResult(*book)
  159. } else {
  160. bookResult, err = models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  161. if err != nil {
  162. if err == orm.ErrNoRows {
  163. c.ShowErrorPage(403, "项目不存在或没有权限")
  164. } else {
  165. beego.Error("查询项目时出错 -> ", err)
  166. c.ShowErrorPage(500, "查询项目时出错")
  167. }
  168. }
  169. if bookResult.RoleId == conf.BookObserver {
  170. c.JsonResult(6002, "项目不存在或权限不足")
  171. }
  172. }
  173. // 根据不同编辑器类型加载编辑器
  174. if bookResult.Editor == "markdown" {
  175. c.TplName = "document/markdown_edit_template.tpl"
  176. } else if bookResult.Editor == "html" {
  177. c.TplName = "document/new_html_edit_template.tpl"
  178. } else {
  179. c.TplName = "document/" + bookResult.Editor + "_edit_template.tpl"
  180. }
  181. c.Data["Model"] = bookResult
  182. r, _ := json.Marshal(bookResult)
  183. c.Data["ModelResult"] = template.JS(string(r))
  184. c.Data["Result"] = template.JS("[]")
  185. trees, err := models.NewDocument().FindDocumentTree(bookResult.BookId)
  186. if err != nil {
  187. beego.Error("FindDocumentTree => ", err)
  188. } else {
  189. if len(trees) > 0 {
  190. if jtree, err := json.Marshal(trees); err == nil {
  191. c.Data["Result"] = template.JS(string(jtree))
  192. }
  193. } else {
  194. c.Data["Result"] = template.JS("[]")
  195. }
  196. }
  197. c.Data["BaiDuMapKey"] = beego.AppConfig.DefaultString("baidumapkey", "")
  198. if conf.GetUploadFileSize() > 0 {
  199. c.Data["UploadFileSize"] = conf.GetUploadFileSize()
  200. }else{
  201. c.Data["UploadFileSize"] = "undefined";
  202. }
  203. }
  204. // 创建一个文档
  205. func (c *DocumentController) Create() {
  206. identify := c.GetString("identify")
  207. docIdentify := c.GetString("doc_identify")
  208. docName := c.GetString("doc_name")
  209. parentId, _ := c.GetInt("parent_id", 0)
  210. docId, _ := c.GetInt("doc_id", 0)
  211. isOpen, _ := c.GetInt("is_open", 0)
  212. if identify == "" {
  213. c.JsonResult(6001, "参数错误")
  214. }
  215. if docName == "" {
  216. c.JsonResult(6004, "文档名称不能为空")
  217. }
  218. bookId := 0
  219. // 如果是超级管理员则不判断权限
  220. if c.Member.IsAdministrator() {
  221. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  222. if err != nil {
  223. beego.Error(err)
  224. c.JsonResult(6002, "项目不存在或权限不足")
  225. }
  226. bookId = book.BookId
  227. } else {
  228. bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  229. if err != nil || bookResult.RoleId == conf.BookObserver {
  230. beego.Error("FindByIdentify => ", err)
  231. c.JsonResult(6002, "项目不存在或权限不足")
  232. }
  233. bookId = bookResult.BookId
  234. }
  235. if docIdentify != "" {
  236. if ok, err := regexp.MatchString(`[a-z]+[a-zA-Z0-9_.\-]*$`, docIdentify); !ok || err != nil {
  237. c.JsonResult(6003, "文档标识只能包含小写字母、数字,以及“-”、“.”和“_”符号")
  238. }
  239. d, _ := models.NewDocument().FindByIdentityFirst(docIdentify, bookId)
  240. if d.DocumentId > 0 && d.DocumentId != docId {
  241. c.JsonResult(6006, "文档标识已被使用")
  242. }
  243. }
  244. if parentId > 0 {
  245. doc, err := models.NewDocument().Find(parentId)
  246. if err != nil || doc.BookId != bookId {
  247. c.JsonResult(6003, "父分类不存在")
  248. }
  249. }
  250. document, _ := models.NewDocument().Find(docId)
  251. document.MemberId = c.Member.MemberId
  252. document.BookId = bookId
  253. document.Identify = docIdentify
  254. document.Version = time.Now().Unix()
  255. document.DocumentName = docName
  256. document.ParentId = parentId
  257. if isOpen == 1 {
  258. document.IsOpen = 1
  259. } else {
  260. document.IsOpen = 0
  261. }
  262. if err := document.InsertOrUpdate(); err != nil {
  263. beego.Error("添加或更新文档时出错 -> ", err)
  264. c.JsonResult(6005, "保存失败")
  265. } else {
  266. c.JsonResult(0, "ok", document)
  267. }
  268. }
  269. // 上传附件或图片
  270. func (c *DocumentController) Upload() {
  271. identify := c.GetString("identify")
  272. docId, _ := c.GetInt("doc_id")
  273. isAttach := true
  274. if identify == "" {
  275. c.JsonResult(6001, "参数错误")
  276. }
  277. name := "editormd-file-file"
  278. file, moreFile, err := c.GetFile(name)
  279. if err == http.ErrMissingFile {
  280. name = "editormd-image-file"
  281. file, moreFile, err = c.GetFile(name)
  282. if err == http.ErrMissingFile {
  283. c.JsonResult(6003, "没有发现需要上传的文件")
  284. }
  285. }
  286. if err != nil {
  287. c.JsonResult(6002, err.Error())
  288. }
  289. defer file.Close()
  290. type Size interface {
  291. Size() int64
  292. }
  293. if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() {
  294. c.JsonResult(6009, "文件大小超过了限定的最大值")
  295. }
  296. ext := filepath.Ext(moreFile.Filename)
  297. //文件必须带有后缀名
  298. if ext == "" {
  299. c.JsonResult(6003, "无法解析文件的格式")
  300. }
  301. //如果文件类型设置为 * 标识不限制文件类型
  302. if conf.IsAllowUploadFileExt(ext) == false {
  303. c.JsonResult(6004, "不允许的文件类型")
  304. }
  305. bookId := 0
  306. // 如果是超级管理员,则不判断权限
  307. if c.Member.IsAdministrator() {
  308. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  309. if err != nil {
  310. c.JsonResult(6006, "文档不存在或权限不足")
  311. }
  312. bookId = book.BookId
  313. } else {
  314. book, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  315. if err != nil {
  316. beego.Error("DocumentController.Edit => ", err)
  317. if err == orm.ErrNoRows {
  318. c.JsonResult(6006, "权限不足")
  319. }
  320. c.JsonResult(6001, err.Error())
  321. }
  322. // 如果没有编辑权限
  323. if book.RoleId != conf.BookEditor && book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder {
  324. c.JsonResult(6006, "权限不足")
  325. }
  326. bookId = book.BookId
  327. }
  328. if docId > 0 {
  329. doc, err := models.NewDocument().Find(docId)
  330. if err != nil {
  331. c.JsonResult(6007, "文档不存在")
  332. }
  333. if doc.BookId != bookId {
  334. c.JsonResult(6008, "文档不属于指定的项目")
  335. }
  336. }
  337. fileName := "m_" + cryptil.UniqueId() + "_r"
  338. filePath := filepath.Join(conf.WorkingDirectory, "uploads", identify)
  339. //将图片和文件分开存放
  340. if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, ".png") || strings.EqualFold(ext, ".gif") {
  341. filePath = filepath.Join(filePath, "images", fileName+ext)
  342. } else {
  343. filePath = filepath.Join(filePath, "files", fileName+ext)
  344. }
  345. path := filepath.Dir(filePath)
  346. os.MkdirAll(path, os.ModePerm)
  347. err = c.SaveToFile(name, filePath)
  348. if err != nil {
  349. beego.Error("保存文件失败 -> ", err)
  350. c.JsonResult(6005, "保存文件失败")
  351. }
  352. attachment := models.NewAttachment()
  353. attachment.BookId = bookId
  354. attachment.FileName = moreFile.Filename
  355. attachment.CreateAt = c.Member.MemberId
  356. attachment.FileExt = ext
  357. attachment.FilePath = strings.TrimPrefix(filePath, conf.WorkingDirectory)
  358. attachment.DocumentId = docId
  359. if fileInfo, err := os.Stat(filePath); err == nil {
  360. attachment.FileSize = float64(fileInfo.Size())
  361. }
  362. if docId > 0 {
  363. attachment.DocumentId = docId
  364. }
  365. if strings.EqualFold(ext, ".jpg") || strings.EqualFold(ext, ".jpeg") || strings.EqualFold(ext, ".png") || strings.EqualFold(ext, ".gif") {
  366. attachment.HttpPath = "/" + strings.Replace(strings.TrimPrefix(filePath, conf.WorkingDirectory), "\\", "/", -1)
  367. if strings.HasPrefix(attachment.HttpPath, "//") {
  368. attachment.HttpPath = conf.URLForWithCdnImage(string(attachment.HttpPath[1:]))
  369. }
  370. isAttach = false
  371. }
  372. err = attachment.Insert()
  373. if err != nil {
  374. os.Remove(filePath)
  375. beego.Error("文件保存失败 ->", err)
  376. c.JsonResult(6006, "文件保存失败")
  377. }
  378. if attachment.HttpPath == "" {
  379. attachment.HttpPath = conf.URLFor("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId)
  380. if err := attachment.Update(); err != nil {
  381. beego.Error("保存文件失败 ->", err)
  382. c.JsonResult(6005, "保存文件失败")
  383. }
  384. }
  385. result := map[string]interface{}{
  386. "errcode": 0,
  387. "success": 1,
  388. "message": "ok",
  389. "url": attachment.HttpPath,
  390. "alt": attachment.FileName,
  391. "is_attach": isAttach,
  392. "attach": attachment,
  393. }
  394. c.Ctx.Output.JSON(result, true, false)
  395. c.StopRun()
  396. }
  397. // 下载附件
  398. func (c *DocumentController) DownloadAttachment() {
  399. c.Prepare()
  400. identify := c.Ctx.Input.Param(":key")
  401. attachId, _ := strconv.Atoi(c.Ctx.Input.Param(":attach_id"))
  402. token := c.GetString("token")
  403. memberId := 0
  404. if c.Member != nil {
  405. memberId = c.Member.MemberId
  406. }
  407. bookId := 0
  408. // 判断用户是否参与了项目
  409. bookResult, err := models.NewBookResult().FindByIdentify(identify, memberId)
  410. if err != nil {
  411. // 判断项目公开状态
  412. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  413. if err != nil {
  414. if err == orm.ErrNoRows {
  415. c.ShowErrorPage(404, "项目不存在或已删除")
  416. } else {
  417. beego.Error("查找项目时出错 ->", err)
  418. c.ShowErrorPage(500, "系统错误")
  419. }
  420. }
  421. // 如果不是超级管理员则判断权限
  422. if c.Member == nil || c.Member.Role != conf.MemberSuperRole {
  423. // 如果项目是私有的,并且 token 不正确
  424. if (book.PrivatelyOwned == 1 && token == "") || (book.PrivatelyOwned == 1 && book.PrivateToken != token) {
  425. c.ShowErrorPage(403, "权限不足")
  426. }
  427. }
  428. bookId = book.BookId
  429. } else {
  430. bookId = bookResult.BookId
  431. }
  432. // 查找附件
  433. attachment, err := models.NewAttachment().Find(attachId)
  434. if err != nil {
  435. beego.Error("查找附件时出错 -> ", err)
  436. if err == orm.ErrNoRows {
  437. c.ShowErrorPage(404, "附件不存在或已删除")
  438. } else {
  439. c.ShowErrorPage(500, "查找附件时出错")
  440. }
  441. }
  442. if attachment.BookId != bookId {
  443. c.ShowErrorPage(404, "附件不存在或已删除")
  444. }
  445. c.Ctx.Output.Download(filepath.Join(conf.WorkingDirectory, attachment.FilePath), attachment.FileName)
  446. c.StopRun()
  447. }
  448. // 删除附件
  449. func (c *DocumentController) RemoveAttachment() {
  450. c.Prepare()
  451. attachId, _ := c.GetInt("attach_id")
  452. if attachId <= 0 {
  453. c.JsonResult(6001, "参数错误")
  454. }
  455. attach, err := models.NewAttachment().Find(attachId)
  456. if err != nil {
  457. beego.Error(err)
  458. c.JsonResult(6002, "附件不存在")
  459. }
  460. document, err := models.NewDocument().Find(attach.DocumentId)
  461. if err != nil {
  462. beego.Error(err)
  463. c.JsonResult(6003, "文档不存在")
  464. }
  465. if c.Member.Role != conf.MemberSuperRole {
  466. rel, err := models.NewRelationship().FindByBookIdAndMemberId(document.BookId, c.Member.MemberId)
  467. if err != nil {
  468. beego.Error(err)
  469. c.JsonResult(6004, "权限不足")
  470. }
  471. if rel.RoleId == conf.BookObserver {
  472. c.JsonResult(6004, "权限不足")
  473. }
  474. }
  475. err = attach.Delete()
  476. if err != nil {
  477. beego.Error(err)
  478. c.JsonResult(6005, "删除失败")
  479. }
  480. os.Remove(filepath.Join(conf.WorkingDirectory, attach.FilePath))
  481. c.JsonResult(0, "ok", attach)
  482. }
  483. // 删除文档
  484. func (c *DocumentController) Delete() {
  485. c.Prepare()
  486. identify := c.GetString("identify")
  487. docId, err := c.GetInt("doc_id", 0)
  488. bookId := 0
  489. // 如果是超级管理员则忽略权限判断
  490. if c.Member.IsAdministrator() {
  491. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  492. if err != nil {
  493. beego.Error("FindByIdentify => ", err)
  494. c.JsonResult(6002, "项目不存在或权限不足")
  495. }
  496. bookId = book.BookId
  497. } else {
  498. bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  499. if err != nil || bookResult.RoleId == conf.BookObserver {
  500. beego.Error("FindByIdentify => ", err)
  501. c.JsonResult(6002, "项目不存在或权限不足")
  502. }
  503. bookId = bookResult.BookId
  504. }
  505. if docId <= 0 {
  506. c.JsonResult(6001, "参数错误")
  507. }
  508. doc, err := models.NewDocument().Find(docId)
  509. if err != nil {
  510. beego.Error("Delete => ", err)
  511. c.JsonResult(6003, "删除失败")
  512. }
  513. // 如果文档所属项目错误
  514. if doc.BookId != bookId {
  515. c.JsonResult(6004, "参数错误")
  516. }
  517. // 递归删除项目下的文档以及子文档
  518. err = doc.RecursiveDocument(doc.DocumentId)
  519. if err != nil {
  520. c.JsonResult(6005, "删除失败")
  521. }
  522. // 重置文档数量统计
  523. models.NewBook().ResetDocumentNumber(doc.BookId)
  524. c.JsonResult(0, "ok")
  525. }
  526. // 获取文档内容
  527. func (c *DocumentController) Content() {
  528. c.Prepare()
  529. identify := c.Ctx.Input.Param(":key")
  530. docId, err := c.GetInt("doc_id")
  531. if err != nil {
  532. docId, _ = strconv.Atoi(c.Ctx.Input.Param(":id"))
  533. }
  534. bookId := 0
  535. autoRelease := false
  536. // 如果是超级管理员,则忽略权限
  537. if c.Member.IsAdministrator() {
  538. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  539. if err != nil {
  540. c.JsonResult(6002, "项目不存在或权限不足")
  541. }
  542. bookId = book.BookId
  543. autoRelease = book.AutoRelease == 1
  544. } else {
  545. bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  546. if err != nil || bookResult.RoleId == conf.BookObserver {
  547. beego.Error("项目不存在或权限不足 -> ", err)
  548. c.JsonResult(6002, "项目不存在或权限不足")
  549. }
  550. bookId = bookResult.BookId
  551. autoRelease = bookResult.AutoRelease
  552. }
  553. if docId <= 0 {
  554. c.JsonResult(6001, "参数错误")
  555. }
  556. if c.Ctx.Input.IsPost() {
  557. markdown := strings.TrimSpace(c.GetString("markdown", ""))
  558. content := c.GetString("html")
  559. version, _ := c.GetInt64("version", 0)
  560. isCover := c.GetString("cover")
  561. doc, err := models.NewDocument().Find(docId)
  562. if err != nil {
  563. c.JsonResult(6003, "读取文档错误")
  564. }
  565. if doc.BookId != bookId {
  566. c.JsonResult(6004, "保存的文档不属于指定项目")
  567. }
  568. if doc.Version != version && !strings.EqualFold(isCover, "yes") {
  569. beego.Info("%d|", version, doc.Version)
  570. c.JsonResult(6005, "文档已被修改确定要覆盖吗?")
  571. }
  572. history := models.NewDocumentHistory()
  573. history.DocumentId = docId
  574. history.Content = doc.Content
  575. history.Markdown = doc.Markdown
  576. history.DocumentName = doc.DocumentName
  577. history.ModifyAt = c.Member.MemberId
  578. history.MemberId = doc.MemberId
  579. history.ParentId = doc.ParentId
  580. history.Version = time.Now().Unix()
  581. history.Action = "modify"
  582. history.ActionName = "修改文档"
  583. if markdown == "" && content != "" {
  584. doc.Markdown = content
  585. } else {
  586. doc.Markdown = markdown
  587. }
  588. doc.Version = time.Now().Unix()
  589. doc.Content = content
  590. if err := doc.InsertOrUpdate(); err != nil {
  591. beego.Error("InsertOrUpdate => ", err)
  592. c.JsonResult(6006, "保存失败")
  593. }
  594. // 如果启用了文档历史,则添加历史文档
  595. ///如果两次保存的MD5值不同则保存为历史,否则忽略
  596. go func(history *models.DocumentHistory) {
  597. if c.EnableDocumentHistory && cryptil.Md5Crypt(history.Markdown) != cryptil.Md5Crypt(doc.Markdown) {
  598. _, err = history.InsertOrUpdate()
  599. if err != nil {
  600. beego.Error("DocumentHistory InsertOrUpdate => ", err)
  601. }
  602. }
  603. }(history)
  604. //如果启用了自动发布
  605. if autoRelease {
  606. go func() {
  607. err := doc.ReleaseContent()
  608. if err == nil {
  609. logs.Informational("文档自动发布成功 -> document_id=%d;document_name=%s", doc.DocumentId, doc.DocumentName)
  610. }
  611. }()
  612. }
  613. c.JsonResult(0, "ok", doc)
  614. }
  615. doc, err := models.NewDocument().Find(docId)
  616. if err != nil {
  617. c.JsonResult(6003, "文档不存在")
  618. }
  619. attach, err := models.NewAttachment().FindListByDocumentId(doc.DocumentId)
  620. if err == nil {
  621. doc.AttachList = attach
  622. }
  623. c.JsonResult(0, "ok", doc)
  624. }
  625. //
  626. //func (c *DocumentController) GetDocumentById(id string) (doc *models.Document, err error) {
  627. // doc = models.NewDocument()
  628. // if doc_id, err := strconv.Atoi(id); err == nil {
  629. // doc, err = doc.Find(doc_id)
  630. // if err != nil {
  631. // return nil, err
  632. // }
  633. // } else {
  634. // doc, err = doc.FindByFieldFirst("identify", id)
  635. // if err != nil {
  636. // return nil, err
  637. // }
  638. // }
  639. //
  640. // return doc, nil
  641. //}
  642. // 导出
  643. func (c *DocumentController) Export() {
  644. c.Prepare()
  645. identify := c.Ctx.Input.Param(":key")
  646. if identify == "" {
  647. c.ShowErrorPage(500, "参数错误")
  648. }
  649. output := c.GetString("output")
  650. token := c.GetString("token")
  651. // 如果没有开启匿名访问则跳转到登录
  652. if !c.EnableAnonymous && !isUserLoggedIn(c) {
  653. promptUserToLogIn(c)
  654. return
  655. }
  656. if !conf.GetEnableExport() {
  657. c.ShowErrorPage(500, "系统没有开启导出功能")
  658. }
  659. bookResult := models.NewBookResult()
  660. if c.Member != nil && c.Member.IsAdministrator() {
  661. book, err := models.NewBook().FindByIdentify(identify)
  662. if err != nil {
  663. if err == orm.ErrNoRows {
  664. c.ShowErrorPage(404, "项目不存在")
  665. } else {
  666. beego.Error("查找项目时出错 ->", err)
  667. c.ShowErrorPage(500, "查找项目时出错")
  668. }
  669. }
  670. bookResult = models.NewBookResult().ToBookResult(*book)
  671. } else {
  672. bookResult = isReadable(identify, token, c)
  673. }
  674. if !bookResult.IsDownload {
  675. c.ShowErrorPage(200, "当前项目没有开启导出功能")
  676. }
  677. if !strings.HasPrefix(bookResult.Cover, "http:://") && !strings.HasPrefix(bookResult.Cover, "https:://") {
  678. bookResult.Cover = conf.URLForWithCdnImage(bookResult.Cover)
  679. }
  680. if output == "markdown" {
  681. if bookResult.Editor != "markdown" {
  682. c.ShowErrorPage(500, "当前项目不支持Markdown编辑器")
  683. }
  684. p, err := bookResult.ExportMarkdown(c.CruSession.SessionID())
  685. if err != nil {
  686. c.ShowErrorPage(500, "导出文档失败")
  687. }
  688. c.Ctx.Output.Download(p, bookResult.BookName+".zip")
  689. c.StopRun()
  690. return
  691. }
  692. outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(bookResult.BookId))
  693. pdfpath := filepath.Join(outputPath, "book.pdf")
  694. epubpath := filepath.Join(outputPath, "book.epub")
  695. mobipath := filepath.Join(outputPath, "book.mobi")
  696. docxpath := filepath.Join(outputPath, "book.docx")
  697. if output == "pdf" && filetil.FileExists(pdfpath) {
  698. c.Ctx.Output.Download(pdfpath, bookResult.BookName+".pdf")
  699. c.Abort("200")
  700. } else if output == "epub" && filetil.FileExists(epubpath) {
  701. c.Ctx.Output.Download(epubpath, bookResult.BookName+".epub")
  702. c.Abort("200")
  703. } else if output == "mobi" && filetil.FileExists(mobipath) {
  704. c.Ctx.Output.Download(mobipath, bookResult.BookName+".mobi")
  705. c.Abort("200")
  706. } else if output == "docx" && filetil.FileExists(docxpath) {
  707. c.Ctx.Output.Download(docxpath, bookResult.BookName+".docx")
  708. c.Abort("200")
  709. } else if output == "pdf" || output == "epub" || output == "docx" || output == "mobi" {
  710. if err := models.BackgroundConvert(c.CruSession.SessionID(), bookResult); err != nil && err != gopool.ErrHandlerIsExist {
  711. c.ShowErrorPage(500, "导出失败,请查看系统日志")
  712. }
  713. c.ShowErrorPage(200, "文档正在后台转换,请稍后再下载")
  714. } else {
  715. c.ShowErrorPage(200, "不支持的文件格式")
  716. }
  717. c.ShowErrorPage(404, "项目没有导出文件")
  718. }
  719. // 生成项目访问的二维码
  720. func (c *DocumentController) QrCode() {
  721. c.Prepare()
  722. identify := c.GetString(":key")
  723. book, err := models.NewBook().FindByIdentify(identify)
  724. if err != nil || book.BookId <= 0 {
  725. c.ShowErrorPage(404, "项目不存在")
  726. }
  727. uri := conf.URLFor("DocumentController.Index", ":key", identify)
  728. code, err := qr.Encode(uri, qr.L, qr.Unicode)
  729. if err != nil {
  730. beego.Error("生成二维码失败 ->", err)
  731. c.ShowErrorPage(500, "生成二维码失败")
  732. }
  733. code, err = barcode.Scale(code, 150, 150)
  734. if err != nil {
  735. beego.Error("生成二维码失败 ->", err)
  736. c.ShowErrorPage(500, "生成二维码失败")
  737. }
  738. c.Ctx.ResponseWriter.Header().Set("Content-Type", "image/png")
  739. // imgpath := filepath.Join("cache","qrcode",identify + ".png")
  740. err = png.Encode(c.Ctx.ResponseWriter, code)
  741. if err != nil {
  742. beego.Error("生成二维码失败 ->", err)
  743. c.ShowErrorPage(500, "生成二维码失败")
  744. }
  745. }
  746. // 项目内搜索
  747. func (c *DocumentController) Search() {
  748. c.Prepare()
  749. identify := c.Ctx.Input.Param(":key")
  750. token := c.GetString("token")
  751. keyword := strings.TrimSpace(c.GetString("keyword"))
  752. if identify == "" {
  753. c.JsonResult(6001, "参数错误")
  754. }
  755. if !c.EnableAnonymous && !isUserLoggedIn(c) {
  756. promptUserToLogIn(c)
  757. return
  758. }
  759. bookResult := isReadable(identify, token, c)
  760. docs, err := models.NewDocumentSearchResult().SearchDocument(keyword, bookResult.BookId)
  761. if err != nil {
  762. beego.Error(err)
  763. c.JsonResult(6002, "搜索结果错误")
  764. }
  765. if len(docs) < 0 {
  766. c.JsonResult(404, "没有数据库")
  767. }
  768. for _, doc := range docs {
  769. doc.BookId = bookResult.BookId
  770. doc.BookName = bookResult.BookName
  771. doc.Description = bookResult.Description
  772. doc.BookIdentify = bookResult.Identify
  773. }
  774. c.JsonResult(0, "ok", docs)
  775. }
  776. // 文档历史列表
  777. func (c *DocumentController) History() {
  778. c.Prepare()
  779. c.TplName = "document/history.tpl"
  780. identify := c.GetString("identify")
  781. docId, err := c.GetInt("doc_id", 0)
  782. pageIndex, _ := c.GetInt("page", 1)
  783. bookId := 0
  784. // 如果是超级管理员则忽略权限判断
  785. if c.Member.IsAdministrator() {
  786. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  787. if err != nil {
  788. beego.Error("查找项目失败 ->", err)
  789. c.Data["ErrorMessage"] = "项目不存在或权限不足"
  790. return
  791. }
  792. bookId = book.BookId
  793. c.Data["Model"] = book
  794. } else {
  795. bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  796. if err != nil || bookResult.RoleId == conf.BookObserver {
  797. beego.Error("查找项目失败 ->", err)
  798. c.Data["ErrorMessage"] = "项目不存在或权限不足"
  799. return
  800. }
  801. bookId = bookResult.BookId
  802. c.Data["Model"] = bookResult
  803. }
  804. if docId <= 0 {
  805. c.Data["ErrorMessage"] = "参数错误"
  806. return
  807. }
  808. doc, err := models.NewDocument().Find(docId)
  809. if err != nil {
  810. beego.Error("Delete => ", err)
  811. c.Data["ErrorMessage"] = "获取历史失败"
  812. return
  813. }
  814. // 如果文档所属项目错误
  815. if doc.BookId != bookId {
  816. c.Data["ErrorMessage"] = "参数错误"
  817. return
  818. }
  819. histories, totalCount, err := models.NewDocumentHistory().FindToPager(docId, pageIndex, conf.PageSize)
  820. if err != nil {
  821. beego.Error("分页查找文档历史失败 ->", err)
  822. c.Data["ErrorMessage"] = "获取历史失败"
  823. return
  824. }
  825. c.Data["List"] = histories
  826. c.Data["PageHtml"] = ""
  827. c.Data["Document"] = doc
  828. if totalCount > 0 {
  829. pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
  830. c.Data["PageHtml"] = pager.HtmlPages()
  831. }
  832. }
  833. func (c *DocumentController) DeleteHistory() {
  834. c.Prepare()
  835. c.TplName = "document/history.tpl"
  836. identify := c.GetString("identify")
  837. docId, err := c.GetInt("doc_id", 0)
  838. historyId, _ := c.GetInt("history_id", 0)
  839. if historyId <= 0 {
  840. c.JsonResult(6001, "参数错误")
  841. }
  842. bookId := 0
  843. // 如果是超级管理员则忽略权限判断
  844. if c.Member.IsAdministrator() {
  845. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  846. if err != nil {
  847. beego.Error("查找项目失败 ->", err)
  848. c.JsonResult(6002, "项目不存在或权限不足")
  849. }
  850. bookId = book.BookId
  851. } else {
  852. bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  853. if err != nil || bookResult.RoleId == conf.BookObserver {
  854. beego.Error("查找项目失败 ->", err)
  855. c.JsonResult(6002, "项目不存在或权限不足")
  856. }
  857. bookId = bookResult.BookId
  858. }
  859. if docId <= 0 {
  860. c.JsonResult(6001, "参数错误")
  861. }
  862. doc, err := models.NewDocument().Find(docId)
  863. if err != nil {
  864. beego.Error("Delete => ", err)
  865. c.JsonResult(6001, "获取历史失败")
  866. }
  867. // 如果文档所属项目错误
  868. if doc.BookId != bookId {
  869. c.JsonResult(6001, "参数错误")
  870. }
  871. err = models.NewDocumentHistory().Delete(historyId, docId)
  872. if err != nil {
  873. beego.Error(err)
  874. c.JsonResult(6002, "删除失败")
  875. }
  876. c.JsonResult(0, "ok")
  877. }
  878. //通过文档历史恢复文档
  879. func (c *DocumentController) RestoreHistory() {
  880. c.Prepare()
  881. c.TplName = "document/history.tpl"
  882. identify := c.GetString("identify")
  883. docId, err := c.GetInt("doc_id", 0)
  884. historyId, _ := c.GetInt("history_id", 0)
  885. if historyId <= 0 {
  886. c.JsonResult(6001, "参数错误")
  887. }
  888. bookId := 0
  889. // 如果是超级管理员则忽略权限判断
  890. if c.Member.IsAdministrator() {
  891. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  892. if err != nil {
  893. beego.Error("FindByIdentify => ", err)
  894. c.JsonResult(6002, "项目不存在或权限不足")
  895. }
  896. bookId = book.BookId
  897. } else {
  898. bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  899. if err != nil || bookResult.RoleId == conf.BookObserver {
  900. beego.Error("FindByIdentify => ", err)
  901. c.JsonResult(6002, "项目不存在或权限不足")
  902. }
  903. bookId = bookResult.BookId
  904. }
  905. if docId <= 0 {
  906. c.JsonResult(6001, "参数错误")
  907. }
  908. doc, err := models.NewDocument().Find(docId)
  909. if err != nil {
  910. beego.Error("Delete => ", err)
  911. c.JsonResult(6001, "获取历史失败")
  912. }
  913. // 如果文档所属项目错误
  914. if doc.BookId != bookId {
  915. c.JsonResult(6001, "参数错误")
  916. }
  917. err = models.NewDocumentHistory().Restore(historyId, docId, c.Member.MemberId)
  918. if err != nil {
  919. beego.Error(err)
  920. c.JsonResult(6002, "删除失败")
  921. }
  922. c.JsonResult(0, "ok", doc)
  923. }
  924. func (c *DocumentController) Compare() {
  925. c.Prepare()
  926. c.TplName = "document/compare.tpl"
  927. historyId, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
  928. identify := c.Ctx.Input.Param(":key")
  929. bookId := 0
  930. editor := "markdown"
  931. // 如果是超级管理员则忽略权限判断
  932. if c.Member.IsAdministrator() {
  933. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  934. if err != nil {
  935. beego.Error("DocumentController.Compare => ", err)
  936. c.ShowErrorPage(403, "权限不足")
  937. return
  938. }
  939. bookId = book.BookId
  940. c.Data["Model"] = book
  941. editor = book.Editor
  942. } else {
  943. bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
  944. if err != nil || bookResult.RoleId == conf.BookObserver {
  945. beego.Error("FindByIdentify => ", err)
  946. c.ShowErrorPage(403, "权限不足")
  947. return
  948. }
  949. bookId = bookResult.BookId
  950. c.Data["Model"] = bookResult
  951. editor = bookResult.Editor
  952. }
  953. if historyId <= 0 {
  954. c.ShowErrorPage(60002, "参数错误")
  955. }
  956. history, err := models.NewDocumentHistory().Find(historyId)
  957. if err != nil {
  958. beego.Error("DocumentController.Compare => ", err)
  959. c.ShowErrorPage(60003, err.Error())
  960. }
  961. doc, err := models.NewDocument().Find(history.DocumentId)
  962. if doc.BookId != bookId {
  963. c.ShowErrorPage(60002, "参数错误")
  964. }
  965. c.Data["HistoryId"] = historyId
  966. c.Data["DocumentId"] = doc.DocumentId
  967. if editor == "markdown" {
  968. c.Data["HistoryContent"] = history.Markdown
  969. c.Data["Content"] = doc.Markdown
  970. } else {
  971. c.Data["HistoryContent"] = template.HTML(history.Content)
  972. c.Data["Content"] = template.HTML(doc.Content)
  973. }
  974. }
  975. // 递归生成文档序列数组
  976. func RecursiveFun(parentId int, prefix, dpath string, c *DocumentController, book *models.BookResult, docs []*models.Document, paths *list.List) {
  977. for _, item := range docs {
  978. if item.ParentId == parentId {
  979. EachFun(prefix, dpath, c, book, item, paths)
  980. for _, sub := range docs {
  981. if sub.ParentId == item.DocumentId {
  982. prefix += strconv.Itoa(item.ParentId) + strconv.Itoa(item.OrderSort) + strconv.Itoa(item.DocumentId)
  983. RecursiveFun(item.DocumentId, prefix, dpath, c, book, docs, paths)
  984. break
  985. }
  986. }
  987. }
  988. }
  989. }
  990. func EachFun(prefix, dpath string, c *DocumentController, book *models.BookResult, item *models.Document, paths *list.List) {
  991. name := prefix + strconv.Itoa(item.ParentId) + strconv.Itoa(item.OrderSort) + strconv.Itoa(item.DocumentId)
  992. fpath := dpath + "/" + name + ".html"
  993. paths.PushBack(fpath)
  994. f, err := os.OpenFile(fpath, os.O_CREATE|os.O_RDWR, 0777)
  995. if err != nil {
  996. beego.Error(err)
  997. c.ShowErrorPage(500, "系统错误")
  998. }
  999. html, err := c.ExecuteViewPathTemplate("document/export.tpl", map[string]interface{}{"Model": book, "Lists": item, "BaseUrl": c.BaseUrl()})
  1000. if err != nil {
  1001. f.Close()
  1002. beego.Error(err)
  1003. c.ShowErrorPage(500, "系统错误")
  1004. }
  1005. buf := bytes.NewReader([]byte(html))
  1006. doc, err := goquery.NewDocumentFromReader(buf)
  1007. doc.Find("img").Each(func(i int, contentSelection *goquery.Selection) {
  1008. if src, ok := contentSelection.Attr("src"); ok && strings.HasPrefix(src, "/uploads/") {
  1009. contentSelection.SetAttr("src", c.BaseUrl()+src)
  1010. }
  1011. })
  1012. html, err = doc.Html()
  1013. if err != nil {
  1014. f.Close()
  1015. beego.Error(err)
  1016. c.ShowErrorPage(500, "系统错误")
  1017. }
  1018. // html = strings.Replace(html, "<img src=\"/uploads", "<img src=\"" + c.BaseUrl() + "/uploads", -1)
  1019. f.WriteString(html)
  1020. f.Close()
  1021. }
  1022. // 判断用户是否可以阅读文档
  1023. func isReadable(identify, token string, c *DocumentController) *models.BookResult {
  1024. book, err := models.NewBook().FindByFieldFirst("identify", identify)
  1025. if err != nil {
  1026. beego.Error(err)
  1027. c.ShowErrorPage(500, "项目不存在")
  1028. }
  1029. bookResult := models.NewBookResult().ToBookResult(*book)
  1030. isOk := false
  1031. if c.Member != nil {
  1032. roleId, err := models.NewBook().FindForRoleId(book.BookId, c.Member.MemberId)
  1033. if err == nil {
  1034. isOk = true
  1035. bookResult.MemberId = c.Member.MemberId
  1036. bookResult.RoleId = roleId
  1037. }
  1038. }
  1039. // 如果文档是私有的
  1040. if book.PrivatelyOwned == 1 && !c.Member.IsAdministrator() {
  1041. if book.PrivateToken != "" && !isOk {
  1042. // 如果有访问的 Token,并且该项目设置了访问 Token,并且和用户提供的相匹配,则记录到 Session 中。
  1043. // 如果用户未提供 Token 且用户登录了,则判断用户是否参与了该项目。
  1044. // 如果用户未登录,则从 Session 中读取 Token。
  1045. if token != "" && strings.EqualFold(token, book.PrivateToken) {
  1046. c.SetSession(identify, token)
  1047. } else if token, ok := c.GetSession(identify).(string); !ok || !strings.EqualFold(token, book.PrivateToken) {
  1048. c.ShowErrorPage(403, "权限不足")
  1049. }
  1050. } else if !isOk {
  1051. c.ShowErrorPage(403, "权限不足")
  1052. }
  1053. }
  1054. //// 判断是否需要显示评论框
  1055. //if bookResult.CommentStatus == "closed" {
  1056. // bookResult.IsDisplayComment = false
  1057. //} else if bookResult.CommentStatus == "open" {
  1058. // bookResult.IsDisplayComment = true
  1059. //} else if bookResult.CommentStatus == "group_only" {
  1060. // bookResult.IsDisplayComment = bookResult.RelationshipId > 0
  1061. //} else if bookResult.CommentStatus == "registered_only" {
  1062. // bookResult.IsDisplayComment = true
  1063. //}
  1064. return bookResult
  1065. }
  1066. func isUserLoggedIn(c *DocumentController) bool {
  1067. return c.Member != nil && c.Member.MemberId > 0
  1068. }
  1069. func promptUserToLogIn(c *DocumentController) {
  1070. beego.Info("Access " + c.Ctx.Request.URL.RequestURI() + " not permitted.")
  1071. beego.Info(" Access will be redirected to login page(SessionId: " + c.CruSession.SessionID() + ").")
  1072. if c.IsAjax() {
  1073. c.JsonResult(6000, "请重新登录。")
  1074. } else {
  1075. c.Redirect(conf.URLFor("AccountController.Login")+"?url="+url.PathEscape(conf.BaseUrl+c.Ctx.Request.URL.RequestURI()), 302)
  1076. }
  1077. }