mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
merge from mindoc-org/mindoc and resolved conflict
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"time"
|
||||
|
||||
"os"
|
||||
|
||||
"strings"
|
||||
|
||||
"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/utils/filetil"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/astaxie/beego"
|
||||
"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/mindoc-org/mindoc/cache"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
@@ -110,7 +111,7 @@ func (b *Blog) FindFromCache(blogId int) (blog *Blog, err error) {
|
||||
if err == nil {
|
||||
b = &temp
|
||||
b.Link()
|
||||
beego.Debug("从缓存读取文章成功 ->", key)
|
||||
logs.Debug("从缓存读取文章成功 ->", key)
|
||||
return b, nil
|
||||
} else {
|
||||
logs.Error("读取缓存失败 ->", err)
|
||||
@@ -273,7 +274,7 @@ func (b *Blog) Processor() *Blog {
|
||||
}
|
||||
})
|
||||
//设置图片为CDN地址
|
||||
if cdnimg := beego.AppConfig.String("cdnimg"); cdnimg != "" {
|
||||
if cdnimg, _ := web.AppConfig.String("cdnimg"); cdnimg != "" {
|
||||
content.Find("img").Each(func(i int, contentSelection *goquery.Selection) {
|
||||
if src, ok := contentSelection.Attr("src"); ok && strings.HasPrefix(src, "/uploads/") {
|
||||
contentSelection.SetAttr("src", utils.JoinURI(cdnimg, src))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -16,8 +17,8 @@ import (
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"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/utils"
|
||||
@@ -25,7 +26,7 @@ import (
|
||||
"github.com/mindoc-org/mindoc/utils/filetil"
|
||||
"github.com/mindoc-org/mindoc/utils/requests"
|
||||
"github.com/mindoc-org/mindoc/utils/ziptil"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
var releaseQueue = make(chan int, 500)
|
||||
@@ -197,7 +198,7 @@ func (book *Book) Copy(identify string) error {
|
||||
logs.Error("查询项目时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
if err := o.Begin(); err != nil {
|
||||
if _, err := o.Begin(); err != nil {
|
||||
logs.Error("开启事物时出错 -> ", err)
|
||||
return err
|
||||
}
|
||||
@@ -210,49 +211,87 @@ func (book *Book) Copy(identify string) error {
|
||||
book.CommentCount = 0
|
||||
book.HistoryCount = 0
|
||||
|
||||
if _, err := o.Insert(book); err != nil {
|
||||
logs.Error("复制项目时出错 -> ", err)
|
||||
o.Rollback()
|
||||
/* v2 version of beego remove the o.Rollback api for transaction operation.
|
||||
* typically, in v1, you can write code like this:
|
||||
*
|
||||
* o := orm.NewOrm()
|
||||
* if err := o.Operateion(); err != nil {
|
||||
* o.Rollback()
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* however, in v2, this is not available. beego will handles the transaction in new way using
|
||||
* cluster. the new code is like below:
|
||||
*
|
||||
* o := orm.NewOrm()
|
||||
* if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error{
|
||||
* err := o.Operations()
|
||||
* if err != nil {
|
||||
* return err
|
||||
* }
|
||||
* ...
|
||||
* }); err != nil {
|
||||
* ...
|
||||
* }
|
||||
*
|
||||
* when operation failed, it will automatically calls o.Rollback() for TxOrmer.
|
||||
* more details see https://beego.me/docs/mvc/model/transaction.md
|
||||
*/
|
||||
if err := o.DoTx(func(ctx context.Context, txo orm.TxOrmer) error {
|
||||
_, err := txo.Insert(book)
|
||||
return err
|
||||
|
||||
}); err != nil {
|
||||
logs.Error("复制项目时出错: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
var rels []*Relationship
|
||||
|
||||
if _, err := o.QueryTable(NewRelationship().TableNameWithPrefix()).Filter("book_id", bookId).All(&rels); err != nil {
|
||||
if err := o.DoTx(func(ctx context.Context, txo orm.TxOrmer) error {
|
||||
_, err := txo.QueryTable(NewRelationship().TableNameWithPrefix()).Filter("book_id", bookId).All(&rels)
|
||||
return err
|
||||
}); err != nil {
|
||||
logs.Error("复制项目关系时出错 -> ", err)
|
||||
o.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range rels {
|
||||
rel.BookId = book.BookId
|
||||
rel.RelationshipId = 0
|
||||
if _, err := o.Insert(rel); err != nil {
|
||||
if err := o.DoTx(func(ctx context.Context, txo orm.TxOrmer) error {
|
||||
_, err := txo.Insert(rel)
|
||||
return err
|
||||
}); err != nil {
|
||||
logs.Error("复制项目关系时出错 -> ", err)
|
||||
o.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var docs []*Document
|
||||
|
||||
if _, err := o.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).Filter("parent_id", 0).All(&docs); err != nil && err != orm.ErrNoRows {
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err := txOrm.QueryTable(NewDocument().TableNameWithPrefix()).Filter("book_id", bookId).Filter("parent_id", 0).All(&docs)
|
||||
return err
|
||||
}); err != nil && err != orm.ErrNoRows {
|
||||
logs.Error("读取项目文档时出错 -> ", err)
|
||||
o.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
if len(docs) > 0 {
|
||||
if err := recursiveInsertDocument(docs, o, book.BookId, 0); err != nil {
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
return recursiveInsertDocument(docs, txOrm, book.BookId, 0)
|
||||
}); err != nil {
|
||||
logs.Error("复制项目时出错 -> ", err)
|
||||
o.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return o.Commit()
|
||||
return nil
|
||||
}
|
||||
|
||||
//递归的复制文档
|
||||
func recursiveInsertDocument(docs []*Document, o orm.Ormer, bookId int, parentId int) error {
|
||||
func recursiveInsertDocument(docs []*Document, o orm.TxOrmer, bookId int, parentId int) error {
|
||||
for _, doc := range docs {
|
||||
|
||||
docId := doc.DocumentId
|
||||
@@ -419,42 +458,49 @@ func (book *Book) ThoroughDeleteBook(id int) error {
|
||||
o.Begin()
|
||||
|
||||
//删除附件,这里没有删除实际物理文件
|
||||
_, err = o.Raw("DELETE FROM "+NewAttachment().TableNameWithPrefix()+" WHERE book_id=?", book.BookId).Exec()
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+NewAttachment().TableNameWithPrefix()+" WHERE book_id=?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//删除文档
|
||||
_, err = o.Raw("DELETE FROM "+NewDocument().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+NewDocument().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
//删除项目
|
||||
_, err = o.Raw("DELETE FROM "+book.TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+book.TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//删除关系
|
||||
_, err = o.Raw("DELETE FROM "+NewRelationship().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+NewRelationship().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = o.Raw(fmt.Sprintf("DELETE FROM %s WHERE book_id=?", NewTeamRelationship().TableNameWithPrefix()), book.BookId).Exec()
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw(fmt.Sprintf("DELETE FROM %s WHERE book_id=?", NewTeamRelationship().TableNameWithPrefix()), book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
//删除模板
|
||||
_, err = o.Raw("DELETE FROM "+NewTemplate().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
if err != nil {
|
||||
o.Rollback()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
_, err = txOrm.Raw("DELETE FROM "+NewTemplate().TableNameWithPrefix()+" WHERE book_id = ?", book.BookId).Exec()
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -471,7 +517,7 @@ func (book *Book) ThoroughDeleteBook(id int) error {
|
||||
logs.Error("删除项目附件和图片失败 ->", err)
|
||||
}
|
||||
|
||||
return o.Commit()
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"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/converter"
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"github.com/mindoc-org/mindoc/utils/gopool"
|
||||
"github.com/mindoc-org/mindoc/utils/requests"
|
||||
"github.com/mindoc-org/mindoc/utils/ziptil"
|
||||
"gopkg.in/russross/blackfriday.v2"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -269,7 +269,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
convertBookResult := ConvertBookResult{}
|
||||
|
||||
outputPath := filepath.Join(conf.GetExportOutputPath(), strconv.Itoa(m.BookId))
|
||||
viewPath := beego.BConfig.WebConfig.ViewsPath
|
||||
viewPath := web.BConfig.WebConfig.ViewsPath
|
||||
|
||||
pdfpath := filepath.Join(outputPath, "book.pdf")
|
||||
epubpath := filepath.Join(outputPath, "book.epub")
|
||||
@@ -380,7 +380,7 @@ func (m *BookResult) Converter(sessionId string) (ConvertBookResult, error) {
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := beego.ExecuteViewPathTemplate(&buf, "document/export.tpl", viewPath, map[string]interface{}{"Model": m, "Lists": item, "BaseUrl": conf.BaseUrl}); err != nil {
|
||||
if err := web.ExecuteViewPathTemplate(&buf, "document/export.tpl", viewPath, map[string]interface{}{"Model": m, "Lists": item, "BaseUrl": conf.BaseUrl}); err != nil {
|
||||
return convertBookResult, err
|
||||
}
|
||||
html := buf.String()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
import "github.com/astaxie/beego/orm"
|
||||
import "github.com/beego/beego/v2/client/orm"
|
||||
|
||||
type Dashboard struct {
|
||||
BookNumber int64 `json:"book_number"`
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
|
||||
@@ -15,8 +15,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/astaxie/beego"
|
||||
"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/mindoc-org/mindoc/cache"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
"github.com/mindoc-org/mindoc/utils"
|
||||
@@ -44,6 +45,7 @@ type Document struct {
|
||||
Version int64 `orm:"column(version);type(bigint);" json:"version"`
|
||||
//是否展开子目录:0 否/1 是 /2 空间节点,单击时展开下一级
|
||||
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
||||
ViewCount int `orm:"column(view_count);type(int)" json:"view_count"`
|
||||
AttachList []*Attachment `orm:"-" json:"attach"`
|
||||
//i18n
|
||||
Lang string `orm:"-"`
|
||||
@@ -338,7 +340,7 @@ func (item *Document) Processor() *Document {
|
||||
selector.First().AppendHtml(release)
|
||||
}
|
||||
}
|
||||
cdnimg := beego.AppConfig.String("cdnimg")
|
||||
cdnimg,_ := web.AppConfig.String("cdnimg")
|
||||
|
||||
docQuery.Find("img").Each(func(i int, selection *goquery.Selection) {
|
||||
|
||||
@@ -389,3 +391,11 @@ func (item *Document) Processor() *Document {
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
// 增加阅读次数
|
||||
func (item *Document) IncrViewCount(id int) {
|
||||
o := orm.NewOrm()
|
||||
o.QueryTable(item.TableNameWithPrefix()).Filter("document_id", id).Update(orm.Params{
|
||||
"view_count": orm.ColValue(orm.ColAdd, 1),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
)
|
||||
|
||||
type DocumentSearchResult struct {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"html/template"
|
||||
"math"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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/utils"
|
||||
"github.com/mindoc-org/mindoc/utils/cryptil"
|
||||
@@ -112,8 +112,9 @@ func (item *Itemsets) Delete(itemId int) (err error) {
|
||||
if !item.Exist(itemId) {
|
||||
return errors.New("项目空间不存在")
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
if err := o.Begin(); err != nil {
|
||||
ormer := orm.NewOrm()
|
||||
o, err := ormer.Begin()
|
||||
if err != nil {
|
||||
logs.Error("开启事物失败 ->", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/logs"
|
||||
"strings"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ import (
|
||||
|
||||
"math"
|
||||
|
||||
"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/utils"
|
||||
@@ -77,14 +77,14 @@ func (m *Member) Login(account string, password string) (*Member, error) {
|
||||
err := o.Raw("select * from md_members where (account = ? or email = ?) and status = 0 limit 1;", account, account).QueryRow(member)
|
||||
|
||||
if err != nil {
|
||||
if beego.AppConfig.DefaultBool("ldap_enable", false) == true {
|
||||
if web.AppConfig.DefaultBool("ldap_enable", false) {
|
||||
logs.Info("转入LDAP登陆 ->", account)
|
||||
return member.ldapLogin(account, password)
|
||||
} else if beego.AppConfig.String("http_login_url") != "" {
|
||||
} else if url, err := web.AppConfig.String("http_login_url"); url != "" {
|
||||
logs.Info("转入 HTTP 接口登陆 ->", account)
|
||||
return member.httpLogin(account, password)
|
||||
} else {
|
||||
logs.Error("用户登录 ->", err)
|
||||
logs.Error("user login for `%s`: %s", account, err)
|
||||
return member, ErrMemberNoExist
|
||||
}
|
||||
}
|
||||
@@ -121,26 +121,32 @@ func (m *Member) TmpLogin(account string) (*Member, error) {
|
||||
|
||||
//ldapLogin 通过LDAP登陆
|
||||
func (m *Member) ldapLogin(account string, password string) (*Member, error) {
|
||||
if beego.AppConfig.DefaultBool("ldap_enable", false) == false {
|
||||
if !web.AppConfig.DefaultBool("ldap_enable", false) {
|
||||
return m, ErrMemberAuthMethodInvalid
|
||||
}
|
||||
var err error
|
||||
lc, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", beego.AppConfig.String("ldap_host"), beego.AppConfig.DefaultInt("ldap_port", 3268)))
|
||||
ldaphost, _ := web.AppConfig.String("ldap_host")
|
||||
lc, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", ldaphost, web.AppConfig.DefaultInt("ldap_port", 3268)))
|
||||
if err != nil {
|
||||
logs.Error("绑定 LDAP 用户失败 ->", err)
|
||||
return m, ErrLDAPConnect
|
||||
}
|
||||
defer lc.Close()
|
||||
err = lc.Bind(beego.AppConfig.String("ldap_user"), beego.AppConfig.String("ldap_password"))
|
||||
ldapuser, _ := web.AppConfig.String("ldap_user")
|
||||
ldappass, _ := web.AppConfig.String("ldap_password")
|
||||
err = lc.Bind(ldapuser, ldappass)
|
||||
if err != nil {
|
||||
logs.Error("绑定 LDAP 用户失败 ->", err)
|
||||
return m, ErrLDAPFirstBind
|
||||
}
|
||||
ldapbase, _ := web.AppConfig.String("ldap_base")
|
||||
ldapfilter, _ := web.AppConfig.String("ldap_filter")
|
||||
ldapattr, _ := web.AppConfig.String("ldap_attribute")
|
||||
searchRequest := ldap.NewSearchRequest(
|
||||
beego.AppConfig.String("ldap_base"),
|
||||
ldapbase,
|
||||
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
|
||||
//修改objectClass通过配置文件获取值
|
||||
fmt.Sprintf("(&(%s)(%s=%s))", beego.AppConfig.String("ldap_filter"), beego.AppConfig.String("ldap_attribute"), account),
|
||||
fmt.Sprintf("(&(%s)(%s=%s))", ldapfilter, ldapattr, account),
|
||||
[]string{"dn", "mail"},
|
||||
nil,
|
||||
)
|
||||
@@ -163,7 +169,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
|
||||
m.Email = searchResult.Entries[0].GetAttributeValue("mail")
|
||||
m.AuthMethod = "ldap"
|
||||
m.Avatar = "/static/images/headimgurl.jpg"
|
||||
m.Role = conf.SystemRole(beego.AppConfig.DefaultInt("ldap_user_role", 2))
|
||||
m.Role = conf.SystemRole(web.AppConfig.DefaultInt("ldap_user_role", 2))
|
||||
m.CreateTime = time.Now()
|
||||
|
||||
err = m.Add()
|
||||
@@ -177,7 +183,7 @@ func (m *Member) ldapLogin(account string, password string) (*Member, error) {
|
||||
}
|
||||
|
||||
func (m *Member) httpLogin(account, password string) (*Member, error) {
|
||||
urlStr := beego.AppConfig.String("http_login_url")
|
||||
urlStr, _ := web.AppConfig.String("http_login_url")
|
||||
if urlStr == "" {
|
||||
return nil, ErrMemberAuthMethodInvalid
|
||||
}
|
||||
@@ -188,7 +194,7 @@ func (m *Member) httpLogin(account, password string) (*Member, error) {
|
||||
"time": []string{strconv.FormatInt(time.Now().Unix(), 10)},
|
||||
}
|
||||
h := md5.New()
|
||||
h.Write([]byte(val.Encode() + beego.AppConfig.DefaultString("http_login_secret", "")))
|
||||
h.Write([]byte(val.Encode() + web.AppConfig.DefaultString("http_login_secret", "")))
|
||||
|
||||
val.Add("sn", hex.EncodeToString(h.Sum(nil)))
|
||||
|
||||
@@ -240,7 +246,7 @@ func (m *Member) httpLogin(account, password string) (*Member, error) {
|
||||
member.Account = account
|
||||
member.Password = password
|
||||
member.AuthMethod = "http"
|
||||
member.Role = conf.SystemRole(beego.AppConfig.DefaultInt("ldap_user_role", 2))
|
||||
member.Role = conf.SystemRole(web.AppConfig.DefaultInt("ldap_user_role", 2))
|
||||
member.CreateTime = time.Now()
|
||||
if err := member.Add(); err != nil {
|
||||
logs.Error("自动注册用户错误", err)
|
||||
@@ -459,9 +465,9 @@ func (m *Member) Valid(is_hash_password bool) error {
|
||||
|
||||
//删除一个用户.
|
||||
func (m *Member) Delete(oldId int, newId int) error {
|
||||
o := orm.NewOrm()
|
||||
ormer := orm.NewOrm()
|
||||
|
||||
err := o.Begin()
|
||||
o, err := ormer.Begin()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package models
|
||||
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/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ func (m *Relationship) TableUnique() [][]string {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Relationship) QueryTable() orm.QuerySeter {
|
||||
func (m *Relationship) QueryTable() orm.QuerySeter {
|
||||
return orm.NewOrm().QueryTable(m.TableNameWithPrefix())
|
||||
}
|
||||
func NewRelationship() *Relationship {
|
||||
@@ -122,11 +122,11 @@ func (m *Relationship) Insert() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Relationship) Update() error {
|
||||
o := orm.NewOrm()
|
||||
|
||||
_, err := o.Update(m)
|
||||
|
||||
func (m *Relationship) Update(txOrm orm.TxOrmer) error {
|
||||
_, err := txOrm.Update(m)
|
||||
if err != nil {
|
||||
txOrm.Rollback()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -152,11 +152,11 @@ func (m *Relationship) DeleteByBookIdAndMemberId(book_id, member_id int) error {
|
||||
}
|
||||
|
||||
func (m *Relationship) Transfer(book_id, founder_id, receive_id int) error {
|
||||
o := orm.NewOrm()
|
||||
ormer := orm.NewOrm()
|
||||
|
||||
founder := NewRelationship()
|
||||
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id", book_id).Filter("member_id", founder_id).One(founder)
|
||||
err := ormer.QueryTable(m.TableNameWithPrefix()).Filter("book_id", book_id).Filter("member_id", founder_id).One(founder)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -166,12 +166,12 @@ func (m *Relationship) Transfer(book_id, founder_id, receive_id int) error {
|
||||
}
|
||||
receive := NewRelationship()
|
||||
|
||||
err = o.QueryTable(m.TableNameWithPrefix()).Filter("book_id", book_id).Filter("member_id", receive_id).One(receive)
|
||||
err = ormer.QueryTable(m.TableNameWithPrefix()).Filter("book_id", book_id).Filter("member_id", receive_id).One(receive)
|
||||
|
||||
if err != orm.ErrNoRows && err != nil {
|
||||
return err
|
||||
}
|
||||
o.Begin()
|
||||
o, _ := ormer.Begin()
|
||||
|
||||
founder.RoleId = conf.BookAdmin
|
||||
|
||||
@@ -179,8 +179,7 @@ func (m *Relationship) Transfer(book_id, founder_id, receive_id int) error {
|
||||
receive.RoleId = conf.BookFounder
|
||||
receive.BookId = book_id
|
||||
|
||||
if err := founder.Update(); err != nil {
|
||||
o.Rollback()
|
||||
if err := founder.Update(o); err != nil {
|
||||
return err
|
||||
}
|
||||
if receive.RelationshipId > 0 {
|
||||
|
||||
@@ -2,10 +2,10 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -59,9 +59,9 @@ func (t *Team) Delete(id int) (err error) {
|
||||
if id <= 0 {
|
||||
return ErrInvalidParameter
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
ormer := orm.NewOrm()
|
||||
|
||||
err = o.Begin()
|
||||
o, err := ormer.Begin()
|
||||
|
||||
if err != nil {
|
||||
logs.Error("开启事物时出错 ->", err)
|
||||
|
||||
@@ -3,10 +3,9 @@ package models
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/i18n"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
import "github.com/astaxie/beego/orm"
|
||||
import "github.com/beego/beego/v2/client/orm"
|
||||
|
||||
type CommentResult struct {
|
||||
Comment
|
||||
|
||||
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user