mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-18 09:44:26 +08:00
merge from mindoc-org/mindoc and resolved conflict
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/beego/i18n"
|
||||
"net/url"
|
||||
"regexp"
|
||||
@@ -10,7 +9,8 @@ import (
|
||||
|
||||
"html/template"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/lifei6671/gocaptcha"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/mail"
|
||||
@@ -34,12 +34,14 @@ func (c *AccountController) referer() string {
|
||||
|
||||
func (c *AccountController) Prepare() {
|
||||
c.BaseController.Prepare()
|
||||
c.EnableXSRF = beego.AppConfig.DefaultBool("enablexsrf", true)
|
||||
c.EnableXSRF = web.AppConfig.DefaultBool("enablexsrf", true)
|
||||
|
||||
c.Data["xsrfdata"] = template.HTML(c.XSRFFormHTML())
|
||||
c.Data["corpID"] = beego.AppConfig.String("dingtalk_corpid")
|
||||
c.Data["ENABLE_QR_DINGTALK"] = (beego.AppConfig.String("dingtalk_corpid") != "")
|
||||
c.Data["dingtalk_qr_key"] = beego.AppConfig.String("dingtalk_qr_key")
|
||||
c.Data["corpID"], _ = web.AppConfig.String("dingtalk_corpid")
|
||||
if dtcorpid, _ := web.AppConfig.String("dingtalk_corpid"); dtcorpid != "" {
|
||||
c.Data["ENABLE_QR_DINGTALK"] = true
|
||||
}
|
||||
c.Data["dingtalk_qr_key"], _ = web.AppConfig.String("dingtalk_qr_key")
|
||||
|
||||
if !c.EnableXSRF {
|
||||
return
|
||||
@@ -152,9 +154,9 @@ func (c *AccountController) DingTalkLogin() {
|
||||
c.JsonResult(500, i18n.Tr(c.Lang, "message.failed_obtain_user_info"), nil)
|
||||
}
|
||||
|
||||
appKey := beego.AppConfig.String("dingtalk_app_key")
|
||||
appSecret := beego.AppConfig.String("dingtalk_app_secret")
|
||||
tmpReader := beego.AppConfig.String("dingtalk_tmp_reader")
|
||||
appKey, _ := web.AppConfig.String("dingtalk_app_key")
|
||||
appSecret, _ := web.AppConfig.String("dingtalk_app_secret")
|
||||
tmpReader, _ := web.AppConfig.String("dingtalk_tmp_reader")
|
||||
|
||||
if appKey == "" || appSecret == "" || tmpReader == "" {
|
||||
c.JsonResult(500, i18n.Tr(c.Lang, "message.dingtalk_auto_login_not_enable"), nil)
|
||||
@@ -212,8 +214,8 @@ func (c *AccountController) QRLogin() {
|
||||
c.Redirect(conf.URLFor("AccountController.Login"), 302)
|
||||
c.StopRun()
|
||||
}
|
||||
appKey := beego.AppConfig.String("dingtalk_qr_key")
|
||||
appSecret := beego.AppConfig.String("dingtalk_qr_secret")
|
||||
appKey, _ := web.AppConfig.String("dingtalk_qr_key")
|
||||
appSecret, _ := web.AppConfig.String("dingtalk_qr_secret")
|
||||
|
||||
qrDingtalk := dingtalk.NewDingtalkQRLogin(appSecret, appKey)
|
||||
unionID, err := qrDingtalk.GetUnionIDByCode(code)
|
||||
@@ -223,9 +225,9 @@ func (c *AccountController) QRLogin() {
|
||||
c.StopRun()
|
||||
}
|
||||
|
||||
appKey = beego.AppConfig.String("dingtalk_app_key")
|
||||
appSecret = beego.AppConfig.String("dingtalk_app_secret")
|
||||
tmpReader := beego.AppConfig.String("dingtalk_tmp_reader")
|
||||
appKey, _ = web.AppConfig.String("dingtalk_app_key")
|
||||
appSecret, _ = web.AppConfig.String("dingtalk_app_secret")
|
||||
tmpReader, _ := web.AppConfig.String("dingtalk_tmp_reader")
|
||||
|
||||
dingtalkAgent := dingtalk.NewDingTalkAgent(appSecret, appKey)
|
||||
err = dingtalkAgent.GetAccesstoken()
|
||||
@@ -478,7 +480,7 @@ func (c *AccountController) FindPassword() {
|
||||
c.TplName = "errors/error.tpl"
|
||||
return
|
||||
}
|
||||
subTime := memberToken.SendTime.Sub(time.Now())
|
||||
subTime := time.Until(memberToken.SendTime)
|
||||
|
||||
if !strings.EqualFold(memberToken.Email, email) || subTime.Minutes() > float64(mailConf.MailExpired) || !memberToken.ValidTime.IsZero() {
|
||||
c.Data["ErrorMessage"] = i18n.Tr(c.Lang, "message.captcha_expired")
|
||||
@@ -527,7 +529,7 @@ func (c *AccountController) ValidEmail() {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6007, i18n.Tr(c.Lang, "message.mail_expired"))
|
||||
}
|
||||
subTime := memberToken.SendTime.Sub(time.Now())
|
||||
subTime := time.Until(memberToken.SendTime)
|
||||
|
||||
if !strings.EqualFold(memberToken.Email, email) || subTime.Minutes() > float64(mailConf.MailExpired) || !memberToken.ValidTime.IsZero() {
|
||||
|
||||
|
@@ -14,14 +14,15 @@ import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
)
|
||||
|
||||
type BaseController struct {
|
||||
beego.Controller
|
||||
web.Controller
|
||||
Member *models.Member
|
||||
Option map[string]string
|
||||
EnableAnonymous bool
|
||||
@@ -75,9 +76,9 @@ func (c *BaseController) Prepare() {
|
||||
c.EnableAnonymous = strings.EqualFold(c.Option["ENABLE_ANONYMOUS"], "true")
|
||||
c.EnableDocumentHistory = strings.EqualFold(c.Option["ENABLE_DOCUMENT_HISTORY"], "true")
|
||||
}
|
||||
c.Data["HighlightStyle"] = beego.AppConfig.DefaultString("highlight_style", "github")
|
||||
c.Data["HighlightStyle"] = web.AppConfig.DefaultString("highlight_style", "github")
|
||||
|
||||
if b, err := ioutil.ReadFile(filepath.Join(beego.BConfig.WebConfig.ViewsPath, "widgets", "scripts.tpl")); err == nil {
|
||||
if b, err := ioutil.ReadFile(filepath.Join(web.BConfig.WebConfig.ViewsPath, "widgets", "scripts.tpl")); err == nil {
|
||||
c.Data["Scripts"] = template.HTML(string(b))
|
||||
}
|
||||
|
||||
@@ -161,18 +162,18 @@ func (c *BaseController) ExecuteViewPathTemplate(tplName string, data interface{
|
||||
viewPath := c.ViewPath
|
||||
|
||||
if c.ViewPath == "" {
|
||||
viewPath = beego.BConfig.WebConfig.ViewsPath
|
||||
viewPath = web.BConfig.WebConfig.ViewsPath
|
||||
|
||||
}
|
||||
|
||||
if err := beego.ExecuteViewPathTemplate(&buf, tplName, viewPath, data); err != nil {
|
||||
if err := web.ExecuteViewPathTemplate(&buf, tplName, viewPath, data); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func (c *BaseController) BaseUrl() string {
|
||||
baseUrl := beego.AppConfig.DefaultString("baseurl", "")
|
||||
baseUrl := web.AppConfig.DefaultString("baseurl", "")
|
||||
if baseUrl != "" {
|
||||
if strings.HasSuffix(baseUrl, "/") {
|
||||
baseUrl = strings.TrimSuffix(baseUrl, "/")
|
||||
@@ -192,7 +193,7 @@ func (c *BaseController) ShowErrorPage(errCode int, errMsg string) {
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := beego.ExecuteViewPathTemplate(&buf, "errors/error.tpl", beego.BConfig.WebConfig.ViewsPath, map[string]interface{}{"ErrorMessage": errMsg, "ErrorCode": errCode, "BaseUrl": conf.BaseUrl}); err != nil {
|
||||
if err := web.ExecuteViewPathTemplate(&buf, "errors/error.tpl", web.BConfig.WebConfig.ViewsPath, map[string]interface{}{"ErrorMessage": errMsg, "ErrorCode": errCode, "BaseUrl": conf.BaseUrl}); err != nil {
|
||||
c.Abort("500")
|
||||
}
|
||||
if errCode >= 200 && errCode <= 510 {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
@@ -12,11 +13,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/i18n"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
@@ -57,11 +57,11 @@ func (c *BlogController) Index() {
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.blog_pwd_incorrect"))
|
||||
} else if blog.BlogStatus == "password" && password == blog.Password {
|
||||
//如果密码输入正确,则存入session中
|
||||
_ = c.CruSession.Set(blogReadSession, blogId)
|
||||
_ = c.CruSession.Set(context.TODO(), blogReadSession, blogId)
|
||||
c.JsonResult(0, "OK")
|
||||
}
|
||||
c.JsonResult(0, "OK")
|
||||
} else if blog.BlogStatus == "password" && (c.CruSession.Get(blogReadSession) == nil || (c.Member != nil && blog.MemberId != c.Member.MemberId && !c.Member.IsAdministrator())) {
|
||||
} else if blog.BlogStatus == "password" && (c.CruSession.Get(context.TODO(), blogReadSession) == nil || (c.Member != nil && blog.MemberId != c.Member.MemberId && !c.Member.IsAdministrator())) {
|
||||
//如果不存在已输入密码的标记
|
||||
c.TplName = "blog/index_password.tpl"
|
||||
}
|
||||
@@ -469,7 +469,7 @@ func (c *BlogController) Upload() {
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.upload_file_type_error"))
|
||||
}
|
||||
//如果文件类型设置为 * 标识不限制文件类型
|
||||
if beego.AppConfig.DefaultString("upload_file_ext", "") != "*" {
|
||||
if web.AppConfig.DefaultString("upload_file_ext", "") != "*" {
|
||||
if !conf.IsAllowUploadFileExt(ext) {
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.upload_file_type_error"))
|
||||
}
|
||||
@@ -631,7 +631,7 @@ func (c *BlogController) Download() {
|
||||
}
|
||||
blogReadSession := fmt.Sprintf("blog:read:%d", blogId)
|
||||
//如果没有启动匿名访问,或者设置了访问密码
|
||||
if (c.Member == nil && !c.EnableAnonymous) || (blog.BlogStatus == "password" && password != blog.Password && c.CruSession.Get(blogReadSession) == nil) {
|
||||
if (c.Member == nil && !c.EnableAnonymous) || (blog.BlogStatus == "password" && password != blog.Password && c.CruSession.Get(context.TODO(), blogReadSession) == nil) {
|
||||
c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -17,14 +18,14 @@ import (
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/graphics"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
"github.com/mindoc-org/mindoc/utils/pagination"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
type BookController struct {
|
||||
@@ -614,7 +615,7 @@ func (c *BookController) Import() {
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.project_id_existed"))
|
||||
}
|
||||
|
||||
tempPath := filepath.Join(os.TempDir(), c.CruSession.SessionID())
|
||||
tempPath := filepath.Join(os.TempDir(), c.CruSession.SessionID(context.TODO()))
|
||||
|
||||
os.MkdirAll(tempPath, 0766)
|
||||
|
||||
|
@@ -3,8 +3,8 @@ package controllers
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
@@ -14,9 +15,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/qr"
|
||||
@@ -27,7 +28,7 @@ import (
|
||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||
"github.com/mindoc-org/mindoc/utils/gopool"
|
||||
"github.com/mindoc-org/mindoc/utils/pagination"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
// DocumentController struct
|
||||
@@ -143,17 +144,22 @@ func (c *DocumentController) Read() {
|
||||
doc.AttachList = attach
|
||||
}
|
||||
|
||||
doc.IncrViewCount(doc.DocumentId)
|
||||
c.Data["ViewCount"] = doc.ViewCount + 1
|
||||
|
||||
if c.IsAjax() {
|
||||
var data struct {
|
||||
DocTitle string `json:"doc_title"`
|
||||
Body string `json:"body"`
|
||||
Title string `json:"title"`
|
||||
Version int64 `json:"version"`
|
||||
DocTitle string `json:"doc_title"`
|
||||
Body string `json:"body"`
|
||||
Title string `json:"title"`
|
||||
Version int64 `json:"version"`
|
||||
ViewCount int `json:"view_count"`
|
||||
}
|
||||
data.DocTitle = doc.DocumentName
|
||||
data.Body = doc.Release
|
||||
data.Title = doc.DocumentName + " - Powered by MinDoc"
|
||||
data.Version = doc.Version
|
||||
data.ViewCount = doc.ViewCount + 1
|
||||
|
||||
c.JsonResult(0, "ok", data)
|
||||
}
|
||||
@@ -242,7 +248,7 @@ func (c *DocumentController) Edit() {
|
||||
}
|
||||
}
|
||||
|
||||
c.Data["BaiDuMapKey"] = beego.AppConfig.DefaultString("baidumapkey", "")
|
||||
c.Data["BaiDuMapKey"] = web.AppConfig.DefaultString("baidumapkey", "")
|
||||
|
||||
if conf.GetUploadFileSize() > 0 {
|
||||
c.Data["UploadFileSize"] = conf.GetUploadFileSize()
|
||||
@@ -839,7 +845,7 @@ func (c *DocumentController) Export() {
|
||||
if bookResult.Editor != "markdown" {
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.cur_project_not_support_md"))
|
||||
}
|
||||
p, err := bookResult.ExportMarkdown(c.CruSession.SessionID())
|
||||
p, err := bookResult.ExportMarkdown(c.CruSession.SessionID(context.TODO()))
|
||||
|
||||
if err != nil {
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.failed"))
|
||||
@@ -874,7 +880,7 @@ func (c *DocumentController) Export() {
|
||||
c.Abort("200")
|
||||
|
||||
} else if output == "pdf" || output == "epub" || output == "docx" || output == "mobi" {
|
||||
if err := models.BackgroundConvert(c.CruSession.SessionID(), bookResult); err != nil && err != gopool.ErrHandlerIsExist {
|
||||
if err := models.BackgroundConvert(c.CruSession.SessionID(context.TODO()), bookResult); err != nil && err != gopool.ErrHandlerIsExist {
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.export_failed"))
|
||||
}
|
||||
|
||||
@@ -1277,7 +1283,7 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
|
||||
|
||||
func promptUserToLogIn(c *DocumentController) {
|
||||
logs.Info("Access " + c.Ctx.Request.URL.RequestURI() + " not permitted.")
|
||||
logs.Info(" Access will be redirected to login page(SessionId: " + c.CruSession.SessionID() + ").")
|
||||
logs.Info(" Access will be redirected to login page(SessionId: " + c.CruSession.SessionID(context.TODO()) + ").")
|
||||
|
||||
if c.IsAjax() {
|
||||
c.JsonResult(6000, i18n.Tr(c.Lang, "message.need_relogin"))
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"math"
|
||||
"net/url"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
"github.com/mindoc-org/mindoc/utils/pagination"
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
"github.com/mindoc-org/mindoc/utils/pagination"
|
||||
|
@@ -1,10 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"math"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
"github.com/mindoc-org/mindoc/utils/pagination"
|
||||
|
@@ -13,16 +13,16 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||
"github.com/mindoc-org/mindoc/utils/pagination"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
type ManagerController struct {
|
||||
@@ -748,7 +748,7 @@ func (c *ManagerController) Config() {
|
||||
|
||||
tf.WriteString(content)
|
||||
|
||||
err = beego.LoadAppConfig("ini", tf.Name())
|
||||
err = web.LoadAppConfig("ini", tf.Name())
|
||||
|
||||
if err != nil {
|
||||
logs.Error("加载配置文件失败 ->", err)
|
||||
|
@@ -4,9 +4,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/i18n"
|
||||
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/graphics"
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/models"
|
||||
|
Reference in New Issue
Block a user