mirror of https://github.com/mindoc-org/mindoc.git
parent
45ef30c4d9
commit
ca2e0478ca
10
.travis.yml
10
.travis.yml
|
@ -18,9 +18,9 @@ script:
|
|||
|
||||
before_deploy:
|
||||
- sudo apt-get -qq update
|
||||
- GOARCH=amd64 GOOS=linux go build -o godoc_linux_amd64 -ldflags="-w -X main.VERSION=$TAG -X 'main.BUILD_TIME=`date`' -X 'main.GO_VERSION=`go version`'"
|
||||
- GOARCH=amd64 GOOS=darwin go build -o godoc_darwin_amd64 -ldflags="-w -X main.VERSION=$TAG -X 'main.BUILD_TIME=`date`' -X 'main.GO_VERSION=`go version`'"
|
||||
- GOARCH=amd64 GOOS=windows go build -o godoc_windows_amd64.exe -ldflags="-w -X main.VERSION=$TAG -X 'main.BUILD_TIME=`date`' -X 'main.GO_VERSION=`go version`'"
|
||||
- GOARCH=amd64 GOOS=linux go build -o godoc_linux_amd64 -ldflags="-w -X github.com/lifei6671/godoc/conf.VERSION=$TRAVIS_TAG -X 'github.com/lifei6671/godoc/conf.BUILD_TIME=`date`' -X 'conf.GO_VERSION=`github.com/lifei6671/godoc/go version`'"
|
||||
- GOARCH=amd64 GOOS=darwin go build -o godoc_darwin_amd64 -ldflags="-w -X github.com/lifei6671/godoc/conf.VERSION=$TRAVIS_TAG -X 'github.com/lifei6671/godoc/conf.BUILD_TIME=`date`' -X 'conf.GO_VERSION=`github.com/lifei6671/godoc/go version`'"
|
||||
- GOARCH=amd64 GOOS=windows go build -o godoc_windows_amd64.exe -ldflags="-w -X github.com/lifei6671/godoc/conf.VERSION=$TRAVIS_TAG -X 'github.com/lifei6671/godoc/conf.BUILD_TIME=`date`' -X 'conf.GO_VERSION=`github.com/lifei6671/godoc/go version`'"
|
||||
- rm -rf commands controllers models modules data routers tasks vendor docs search utils graphics .git Godeps uploads/* .gitignore .travis.yml Dockerfile gide.yaml LICENSE main.go README.md conf/enumerate.go conf/mail.go install.lock *.md
|
||||
- cp conf/app.conf.example conf/app.conf
|
||||
- zip -r godoc_linux_amd64.zip conf logs static uploads views lib godoc_linux_amd64
|
||||
|
@ -40,7 +40,3 @@ deploy:
|
|||
tags: true
|
||||
all_branches: true
|
||||
go: 1.8
|
||||
|
||||
env:
|
||||
global:
|
||||
- TAG: 0.1.3
|
|
@ -1,19 +1,18 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
"os"
|
||||
"encoding/gob"
|
||||
"time"
|
||||
|
||||
"github.com/lifei6671/godoc/models"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/gocaptcha"
|
||||
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
"github.com/lifei6671/godoc/models"
|
||||
)
|
||||
|
||||
// RegisterDataBase 注册数据库
|
||||
|
@ -28,10 +27,9 @@ func RegisterDataBase() {
|
|||
|
||||
dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true&loc=%s", username, password, host, port, database, url.QueryEscape(timezone))
|
||||
|
||||
|
||||
orm.RegisterDataBase("default", "mysql", dataSource)
|
||||
|
||||
location , err := time.LoadLocation(timezone);
|
||||
location, err := time.LoadLocation(timezone)
|
||||
if err == nil {
|
||||
orm.DefaultTimeLoc = location
|
||||
} else {
|
||||
|
@ -57,74 +55,6 @@ func RegisterModel() {
|
|||
|
||||
}
|
||||
|
||||
//初始化数据
|
||||
func Initialization() {
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
||||
_,err := o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用注册','ENABLED_REGISTER','false' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLED_REGISTER');`).Exec()
|
||||
|
||||
if err != nil {
|
||||
panic("ENABLED_REGISTER => " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
_,err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用验证码','ENABLED_CAPTCHA','false' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLED_CAPTCHA');`).Exec()
|
||||
|
||||
if err != nil {
|
||||
panic("ENABLED_CAPTCHA => " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
_,err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '启用匿名访问','ENABLE_ANONYMOUS','true' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLE_ANONYMOUS');`).Exec()
|
||||
|
||||
if err != nil {
|
||||
panic("ENABLE_ANONYMOUS => " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
_,err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '站点名称','SITE_NAME','MinDoc' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'SITE_NAME');`).Exec()
|
||||
|
||||
if err != nil {
|
||||
panic("SITE_NAME => " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
member,err := models.NewMember().FindByFieldFirst("account","admin")
|
||||
if err == orm.ErrNoRows {
|
||||
|
||||
member.Account = "admin"
|
||||
member.Avatar = "/static/images/headimgurl.jpg"
|
||||
member.Password = "123456"
|
||||
member.Role = 0
|
||||
member.Email = "admin@iminho.me"
|
||||
|
||||
if err := member.Add(); err != nil {
|
||||
panic("Member.Add => " + err.Error())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
book := models.NewBook()
|
||||
|
||||
book.MemberId = member.MemberId
|
||||
book.BookName = "MinDoc演示项目"
|
||||
book.Status = 0
|
||||
book.Description = "这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。"
|
||||
book.CommentCount = 0
|
||||
book.PrivatelyOwned = 0
|
||||
book.CommentStatus = "closed"
|
||||
book.Identify = "mindoc"
|
||||
book.DocCount = 0
|
||||
book.CommentCount = 0
|
||||
book.Version = time.Now().Unix()
|
||||
book.Cover = conf.GetDefaultCover()
|
||||
book.Editor = "markdown"
|
||||
book.Theme = "default"
|
||||
|
||||
if err := book.Insert(); err != nil {
|
||||
panic("Book.Insert => " + err.Error())
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterLogger 注册日志
|
||||
func RegisterLogger() {
|
||||
|
||||
|
@ -149,18 +79,8 @@ func RegisterLogger() {
|
|||
// RunCommand 注册orm命令行工具
|
||||
func RegisterCommand() {
|
||||
|
||||
if _,err := os.Stat("install.lock"); os.IsNotExist(err){
|
||||
err = orm.RunSyncdb("default",false,true)
|
||||
if err == nil {
|
||||
Initialization()
|
||||
f, _ := os.Create("install.lock")
|
||||
defer f.Close()
|
||||
}else{
|
||||
panic(err.Error())
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
Install()
|
||||
Update()
|
||||
CheckUpdate()
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
"github.com/lifei6671/godoc/models"
|
||||
)
|
||||
|
||||
//系统安装.
|
||||
func Install() {
|
||||
if len(os.Args) >= 2 && os.Args[1] == "install" {
|
||||
fmt.Println("Initializing...")
|
||||
|
||||
err := orm.RunSyncdb("default", false, true)
|
||||
if err == nil {
|
||||
initialization()
|
||||
} else {
|
||||
panic(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println("Install Successfully!")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
//初始化数据
|
||||
func initialization() {
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
||||
_, err := o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用注册','ENABLED_REGISTER','false' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLED_REGISTER');`).Exec()
|
||||
|
||||
if err != nil {
|
||||
panic("ENABLED_REGISTER => " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
_, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '是否启用验证码','ENABLED_CAPTCHA','false' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLED_CAPTCHA');`).Exec()
|
||||
|
||||
if err != nil {
|
||||
panic("ENABLED_CAPTCHA => " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
_, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '启用匿名访问','ENABLE_ANONYMOUS','true' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'ENABLE_ANONYMOUS');`).Exec()
|
||||
|
||||
if err != nil {
|
||||
panic("ENABLE_ANONYMOUS => " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
_, err = o.Raw(`INSERT INTO md_options (option_title, option_name, option_value) SELECT '站点名称','SITE_NAME','MinDoc' FROM dual WHERE NOT exists(SELECT * FROM md_options WHERE option_name = 'SITE_NAME');`).Exec()
|
||||
|
||||
if err != nil {
|
||||
panic("SITE_NAME => " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
member, err := models.NewMember().FindByFieldFirst("account", "admin")
|
||||
if err == orm.ErrNoRows {
|
||||
|
||||
member.Account = "admin"
|
||||
member.Avatar = "/static/images/headimgurl.jpg"
|
||||
member.Password = "123456"
|
||||
member.Role = 0
|
||||
member.Email = "admin@iminho.me"
|
||||
|
||||
if err := member.Add(); err != nil {
|
||||
panic("Member.Add => " + err.Error())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
book := models.NewBook()
|
||||
|
||||
book.MemberId = member.MemberId
|
||||
book.BookName = "MinDoc演示项目"
|
||||
book.Status = 0
|
||||
book.Description = "这是一个MinDoc演示项目,该项目是由系统初始化时自动创建。"
|
||||
book.CommentCount = 0
|
||||
book.PrivatelyOwned = 0
|
||||
book.CommentStatus = "closed"
|
||||
book.Identify = "mindoc"
|
||||
book.DocCount = 0
|
||||
book.CommentCount = 0
|
||||
book.Version = time.Now().Unix()
|
||||
book.Cover = conf.GetDefaultCover()
|
||||
book.Editor = "markdown"
|
||||
book.Theme = "default"
|
||||
|
||||
if err := book.Insert(); err != nil {
|
||||
panic("Book.Insert => " + err.Error())
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +1,21 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"os"
|
||||
"net/http"
|
||||
"github.com/astaxie/beego"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
)
|
||||
|
||||
//系统升级.
|
||||
func Update() {
|
||||
if len(os.Args) > 2 && os.Args[1] == "update" {
|
||||
if len(os.Args) >= 2 && os.Args[1] == "update" {
|
||||
|
||||
fmt.Println("update successed.")
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
@ -45,7 +50,7 @@ func CheckUpdate() {
|
|||
beego.Error("CheckUpdate => ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println("MinDoc current version => ", conf.VERSION)
|
||||
fmt.Println("MinDoc last version => ", result[0].Name)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
package conf
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego"
|
||||
"strings"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
// 登录用户的Session名
|
||||
|
@ -41,10 +42,12 @@ const (
|
|||
|
||||
var (
|
||||
VERSION string
|
||||
BUILD_TIME string
|
||||
GO_VERSION string
|
||||
)
|
||||
|
||||
// app_key
|
||||
func GetAppKey() (string) {
|
||||
func GetAppKey() string {
|
||||
return beego.AppConfig.DefaultString("app_key", "godoc")
|
||||
}
|
||||
|
||||
|
@ -100,9 +103,3 @@ func IsAllowUploadFileExt(ext string) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//获取当前版本.
|
||||
func Version() string {
|
||||
|
||||
return VERSION
|
||||
}
|
|
@ -161,6 +161,7 @@ func (c *BookController) SaveBook() {
|
|||
c.JsonResult(0,"ok",bookResult)
|
||||
}
|
||||
|
||||
//设置项目私有状态.
|
||||
func (c *BookController) PrivatelyOwned() {
|
||||
|
||||
status := c.GetString("status")
|
||||
|
@ -184,7 +185,6 @@ func (c *BookController) PrivatelyOwned() {
|
|||
if bookResult.RoleId != conf.BookFounder {
|
||||
c.JsonResult(6002,"权限不足")
|
||||
}
|
||||
fmt.Printf("%+v",bookResult)
|
||||
|
||||
book,err := models.NewBook().Find(bookResult.BookId)
|
||||
|
||||
|
@ -193,8 +193,6 @@ func (c *BookController) PrivatelyOwned() {
|
|||
}
|
||||
book.PrivatelyOwned = state
|
||||
|
||||
logs.Info("",state,status)
|
||||
|
||||
err = book.Update()
|
||||
|
||||
if err != nil {
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"strings"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/lifei6671/godoc/utils"
|
||||
"github.com/lifei6671/godoc/models"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
"github.com/lifei6671/godoc/models"
|
||||
"github.com/lifei6671/godoc/utils"
|
||||
)
|
||||
|
||||
type ManagerController struct {
|
||||
|
@ -63,7 +62,7 @@ func (c *ManagerController) Users() {
|
|||
}
|
||||
}
|
||||
|
||||
// 添加用户
|
||||
// 添加用户.
|
||||
func (c *ManagerController) CreateMember() {
|
||||
c.Prepare()
|
||||
if !c.Member.IsAdministrator() {
|
||||
|
@ -90,7 +89,7 @@ func (c *ManagerController) CreateMember() {
|
|||
if ok, err := regexp.MatchString(conf.RegexpEmail, email); !ok || err != nil || email == "" {
|
||||
c.JsonResult(6004, "邮箱格式不正确")
|
||||
}
|
||||
if role != 0 && role != 1 {
|
||||
if role != 0 && role != 1 && role != 2 {
|
||||
role = 1
|
||||
}
|
||||
if status != 0 && status != 1 {
|
||||
|
@ -151,6 +150,7 @@ func (c *ManagerController) UpdateMemberStatus() {
|
|||
c.JsonResult(0, "ok", member)
|
||||
}
|
||||
|
||||
//变更用户权限.
|
||||
func (c *ManagerController) ChangeMemberRole() {
|
||||
c.Prepare()
|
||||
|
||||
|
@ -237,7 +237,6 @@ func (c *ManagerController) EditBook() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
book.BookName = book_name
|
||||
book.Description = description
|
||||
book.CommentStatus = comment_status
|
||||
|
@ -288,7 +287,7 @@ func (c *ManagerController) CreateToken() {
|
|||
|
||||
identify := c.GetString("identify")
|
||||
|
||||
book,err := models.NewBook().FindByFieldFirst("identify",identify);
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
|
||||
if err != nil {
|
||||
c.JsonResult(6001, "项目不存在")
|
||||
|
@ -315,6 +314,7 @@ func (c *ManagerController) CreateToken() {
|
|||
}
|
||||
}
|
||||
|
||||
//项目设置.
|
||||
func (c *ManagerController) Setting() {
|
||||
c.Prepare()
|
||||
c.TplName = "manager/setting.tpl"
|
||||
|
@ -342,7 +342,53 @@ func (c *ManagerController) Setting() {
|
|||
c.Data[item.OptionName] = item
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Transfer 转让项目.
|
||||
func (c *ManagerController) Transfer() {
|
||||
c.Prepare()
|
||||
account := c.GetString("account")
|
||||
|
||||
if account == "" {
|
||||
c.JsonResult(6004, "接受者账号不能为空")
|
||||
}
|
||||
member, err := models.NewMember().FindByAccount(account)
|
||||
|
||||
if err != nil {
|
||||
logs.Error("FindByAccount => ", err)
|
||||
c.JsonResult(6005, "接受用户不存在")
|
||||
}
|
||||
if member.Status != 0 {
|
||||
c.JsonResult(6006, "接受用户已被禁用")
|
||||
}
|
||||
|
||||
if !c.Member.IsAdministrator() {
|
||||
c.Abort("403")
|
||||
}
|
||||
|
||||
identify := c.GetString("identify")
|
||||
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
c.JsonResult(6001, err.Error())
|
||||
}
|
||||
rel, err := models.NewRelationship().FindFounder(book.BookId)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("FindFounder => ", err)
|
||||
c.JsonResult(6009, "查询项目创始人失败")
|
||||
}
|
||||
if member.MemberId == rel.MemberId {
|
||||
c.JsonResult(6007, "不能转让给自己")
|
||||
}
|
||||
|
||||
err = models.NewRelationship().Transfer(book.BookId, rel.MemberId, member.MemberId)
|
||||
|
||||
if err != nil {
|
||||
logs.Error("Transfer => ", err)
|
||||
c.JsonResult(6008, err.Error())
|
||||
}
|
||||
c.JsonResult(0, "ok")
|
||||
}
|
||||
|
||||
func (c *ManagerController) Comments() {
|
||||
|
@ -380,24 +426,40 @@ func (c *ManagerController) DeleteComment() {
|
|||
c.JsonResult(0, "ok", comment)
|
||||
}
|
||||
|
||||
//设置项目私有状态.
|
||||
func (c *ManagerController) PrivatelyOwned() {
|
||||
|
||||
status := c.GetString("status")
|
||||
identify := c.GetString("identify")
|
||||
|
||||
if status != "open" && status != "close" {
|
||||
c.JsonResult(6003, "参数错误")
|
||||
}
|
||||
state := 0
|
||||
if status == "open" {
|
||||
state = 0
|
||||
} else {
|
||||
state = 1
|
||||
}
|
||||
|
||||
if !c.Member.IsAdministrator() {
|
||||
c.Abort("403")
|
||||
}
|
||||
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
c.JsonResult(6001, err.Error())
|
||||
}
|
||||
|
||||
book.PrivatelyOwned = state
|
||||
|
||||
logs.Info("", state, status)
|
||||
|
||||
err = book.Update()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if err != nil {
|
||||
logs.Error("PrivatelyOwned => ", err)
|
||||
c.JsonResult(6004, "保存失败")
|
||||
}
|
||||
c.JsonResult(0, "ok")
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ func (c *SettingController) Index() {
|
|||
if err := member.Update(); err != nil {
|
||||
c.JsonResult(602, err.Error())
|
||||
}
|
||||
c.SetMember(*member)
|
||||
c.JsonResult(0, "ok")
|
||||
}
|
||||
}
|
||||
|
|
22
main.go
22
main.go
|
@ -3,27 +3,20 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/lifei6671/godoc/routers"
|
||||
_ "github.com/astaxie/beego/session/redis"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
_ "github.com/astaxie/beego/session/memcache"
|
||||
_ "github.com/astaxie/beego/session/mysql"
|
||||
"github.com/astaxie/beego"
|
||||
_ "github.com/astaxie/beego/session/redis"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/lifei6671/godoc/commands"
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
"github.com/lifei6671/godoc/controllers"
|
||||
_ "github.com/lifei6671/godoc/routers"
|
||||
)
|
||||
|
||||
var (
|
||||
VERSION string
|
||||
BUILD_TIME string
|
||||
GO_VERSION string
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Printf("MinDoc version => %s\nbuild time => %s\nstart directory => %s\n%s\n", VERSION, BUILD_TIME, os.Args[0],GO_VERSION)
|
||||
|
||||
commands.RegisterDataBase()
|
||||
commands.RegisterModel()
|
||||
commands.RegisterLogger()
|
||||
|
@ -34,6 +27,7 @@ func main() {
|
|||
|
||||
beego.ErrorController(&controllers.ErrorController{})
|
||||
|
||||
fmt.Printf("MinDoc version => %s\nbuild time => %s\nstart directory => %s\n%s\n", conf.VERSION, conf.BUILD_TIME, os.Args[0], conf.GO_VERSION)
|
||||
|
||||
beego.Run()
|
||||
}
|
||||
|
||||
|
|
|
@ -160,9 +160,9 @@ func (m *Book) FindToPager(pageIndex, pageSize ,memberId int) (books []*BookResu
|
|||
|
||||
qb2.Select("book.*,rel.member_id","rel.role_id","m.account as create_name").
|
||||
From(m.TableNameWithPrefix() + " AS book").
|
||||
LeftJoin(relationship.TableNameWithPrefix() + " AS rel").
|
||||
On("book.book_id=rel.book_id").
|
||||
LeftJoin(NewMember().TableNameWithPrefix() + " AS m").On("rel.member_id=m.member_id AND rel.role_id=0").
|
||||
LeftJoin(relationship.TableNameWithPrefix() + " AS rel").On("book.book_id=rel.book_id").
|
||||
LeftJoin(relationship.TableNameWithPrefix() + " AS rel1").On("book.book_id=rel1.book_id AND rel.role_id=0").
|
||||
LeftJoin(NewMember().TableNameWithPrefix() + " AS m").On("rel1.member_id=m.member_id").
|
||||
Where("rel.member_id=?").
|
||||
OrderBy("book.order_index DESC ","book.book_id").Desc().
|
||||
Limit(pageSize).
|
||||
|
|
|
@ -47,6 +47,15 @@ func (m *Relationship) Find(id int) (*Relationship,error) {
|
|||
return m,err
|
||||
}
|
||||
|
||||
//查询指定项目的创始人.
|
||||
func (m *Relationship) FindFounder(book_id int) (*Relationship,error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
err := o.QueryTable(m.TableNameWithPrefix()).Filter("book_id",book_id).Filter("role_id",0).One(m)
|
||||
|
||||
return m,err
|
||||
}
|
||||
|
||||
func (m *Relationship) UpdateRoleId(book_id,member_id, role_id int) (*Relationship,error) {
|
||||
o := orm.NewOrm()
|
||||
book := NewBook()
|
||||
|
|
|
@ -24,7 +24,7 @@ func init() {
|
|||
beego.InsertFilter("/api/*",beego.BeforeRouter,FilterUser)
|
||||
|
||||
var FinishRouter = func(ctx *context.Context) {
|
||||
ctx.ResponseWriter.Header().Add("MinDoc-Version",conf.Version())
|
||||
ctx.ResponseWriter.Header().Add("MinDoc-Version",conf.VERSION)
|
||||
ctx.ResponseWriter.Header().Add("MinDoc-Site","http://www.iminho.me")
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ func init() {
|
|||
beego.Router("/manager/comments", &controllers.ManagerController{},"*:Comments")
|
||||
beego.Router("/manager/books/token", &controllers.ManagerController{},"post:CreateToken")
|
||||
beego.Router("/manager/setting",&controllers.ManagerController{},"*:Setting")
|
||||
beego.Router("/manager/books/transfer", &controllers.ManagerController{},"post:Transfer")
|
||||
beego.Router("/manager/books/open", &controllers.ManagerController{},"post:PrivatelyOwned")
|
||||
|
||||
beego.Router("/setting", &controllers.SettingController{},"*:Index")
|
||||
beego.Router("/setting/password", &controllers.SettingController{},"*:Password")
|
||||
|
|
|
@ -38,6 +38,12 @@
|
|||
<div class="m-box">
|
||||
<div class="box-head">
|
||||
<strong class="box-title"> 项目设置</strong>
|
||||
<button type="button" class="btn btn-success btn-sm pull-right" data-toggle="modal" data-target="#transferBookModal">转让项目</button>
|
||||
{{if eq .Model.PrivatelyOwned 1}}
|
||||
<button type="button" class="btn btn-success btn-sm pull-right" data-toggle="modal" data-target="#changePrivatelyOwnedModal" style="margin-right: 5px;">转为公有</button>
|
||||
{{else}}
|
||||
<button type="button" class="btn btn-danger btn-sm pull-right" data-toggle="modal" data-target="#changePrivatelyOwnedModal" style="margin-right: 5px;">转为私有</button>
|
||||
{{end}}
|
||||
<button type="button" class="btn btn-danger btn-sm pull-right" style="margin-right: 5px;" data-toggle="modal" data-target="#deleteBookModal">删除项目</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -119,6 +125,43 @@
|
|||
</div>
|
||||
{{template "widgets/footer.tpl" .}}
|
||||
</div>
|
||||
<div class="modal fade" id="changePrivatelyOwnedModal" tabindex="-1" role="dialog" aria-labelledby="changePrivatelyOwnedModalLabel">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form method="post" action="{{urlfor "ManagerController.PrivatelyOwned" }}" id="changePrivatelyOwnedForm">
|
||||
<input type="hidden" name="identify" value="{{.Model.Identify}}">
|
||||
<input type="hidden" name="status" value="{{if eq .Model.PrivatelyOwned 0}}close{{else}}open{{end}}">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">
|
||||
{{if eq .Model.PrivatelyOwned 0}}
|
||||
转为私有
|
||||
{{else}}
|
||||
转为共有
|
||||
{{end}}
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{{if eq .Model.PrivatelyOwned 0}}
|
||||
<span style="font-size: 14px;font-weight: 400;">确定将项目转为私有吗?</span>
|
||||
<p></p>
|
||||
<p class="text error-message">转为私有后需要通过阅读令牌才能访问该项目。</p>
|
||||
{{else}}
|
||||
<span style="font-size: 14px;font-weight: 400;"> 确定将项目转为公有吗?</span>
|
||||
<p></p>
|
||||
<p class="text error-message">转为公有后所有人都可以访问该项目。</p>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<span class="error-message" id="form-error-message1"></span>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||
<button type="submit" class="btn btn-primary" data-loading-text="变更中..." id="btnChangePrivatelyOwned">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Book Modal -->
|
||||
<div class="modal fade" id="deleteBookModal" tabindex="-1" role="dialog" aria-labelledby="deleteBookModalLabel">
|
||||
<div class="modal-dialog" role="document">
|
||||
|
@ -143,7 +186,33 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="transferBookModal" tabindex="-1" role="dialog" aria-labelledby="transferBookModalLabel">
|
||||
<div class="modal-dialog" role="document">
|
||||
<form action="{{urlfor "ManagerController.Transfer"}}" method="post" id="transferBookForm">
|
||||
<input type="hidden" name="identify" value="{{.Model.Identify}}">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title" id="myModalLabel">项目转让</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">接收账号</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="account" class="form-control" placeholder="接收者账号" id="receiveAccount" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<span id="form-error-message3" class="error-message"></span>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||
<button type="submit" id="btnTransferBook" class="btn btn-primary">确定转让</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/jquery/1.12.4/jquery.min.js" type="text/javascript"></script>
|
||||
<script src="/static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
||||
<script src="/static/webuploader/webuploader.min.js" type="text/javascript"></script>
|
||||
|
@ -213,7 +282,46 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
$("#transferBookForm").ajaxForm({
|
||||
beforeSubmit : function () {
|
||||
var account = $.trim($("#receiveAccount").val());
|
||||
if (account === ""){
|
||||
return showError("接受者账号不能为空","#form-error-message3")
|
||||
}
|
||||
$("#btnTransferBook").button("loading");
|
||||
},
|
||||
success : function (res) {
|
||||
if(res.errcode === 0){
|
||||
window.location = window.location.href;
|
||||
}else{
|
||||
showError(res.message,"#form-error-message3");
|
||||
}
|
||||
$("#btnTransferBook").button("reset");
|
||||
},
|
||||
error : function () {
|
||||
$("#btnTransferBook").button("reset");
|
||||
}
|
||||
});
|
||||
$("#changePrivatelyOwnedForm").ajaxForm({
|
||||
beforeSubmit :function () {
|
||||
$("#btnChangePrivatelyOwned").button("loading");
|
||||
},
|
||||
success :function (res) {
|
||||
if(res.errcode === 0){
|
||||
window.location = window.location.href;
|
||||
return;
|
||||
}else{
|
||||
showError(res.message,"#form-error-message1");
|
||||
}
|
||||
$("#btnChangePrivatelyOwned").button("reset");
|
||||
},
|
||||
error :function () {
|
||||
showError("服务器异常","#form-error-message1");
|
||||
$("#btnChangePrivatelyOwned").button("reset");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -170,7 +170,7 @@
|
|||
<div class="modal-footer">
|
||||
<span id="form-error-message"></span>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
|
||||
<button type="submit" class="btn btn-success">保存</button>
|
||||
<button type="submit" class="btn btn-success" data-loading-text="保存中..." id="btnAddMember">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -207,6 +207,7 @@
|
|||
if (email === "") {
|
||||
return showError("邮箱不能为空");
|
||||
}
|
||||
$("#btnAddMember").button("loading");
|
||||
return true;
|
||||
},
|
||||
success : function (res) {
|
||||
|
@ -216,6 +217,11 @@
|
|||
}else{
|
||||
showError(res.message);
|
||||
}
|
||||
$("#btnAddMember").button("reset");
|
||||
},
|
||||
error : function () {
|
||||
showError("服务器异常");
|
||||
$("#btnAddMember").button("reset");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue