2017-04-21 18:20:35 +08:00
|
|
|
// package conf 为配置相关.
|
|
|
|
package conf
|
|
|
|
|
2017-04-27 18:19:37 +08:00
|
|
|
import (
|
|
|
|
"strings"
|
2017-05-11 13:39:34 +08:00
|
|
|
|
|
|
|
"github.com/astaxie/beego"
|
2017-04-27 18:19:37 +08:00
|
|
|
)
|
2017-04-21 18:20:35 +08:00
|
|
|
|
|
|
|
// 登录用户的Session名
|
|
|
|
const LoginSessionName = "LoginSessionName"
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
const CaptchaSessionName = "__captcha__"
|
2017-05-01 12:15:55 +08:00
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
const RegexpEmail = `^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$`
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
|
|
const RegexpAccount = `^[a-zA-Z][a-zA-z0-9]{2,50}$`
|
|
|
|
|
2017-04-24 18:25:17 +08:00
|
|
|
// PageSize 默认分页条数.
|
2017-05-11 13:39:34 +08:00
|
|
|
const PageSize = 15
|
2017-04-24 18:25:17 +08:00
|
|
|
|
|
|
|
// 用户权限
|
|
|
|
const (
|
|
|
|
// 超级管理员.
|
|
|
|
MemberSuperRole = 0
|
|
|
|
//普通管理员.
|
|
|
|
MemberAdminRole = 1
|
|
|
|
//普通用户.
|
|
|
|
MemberGeneralRole = 2
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// 创始人.
|
|
|
|
BookFounder = 0
|
|
|
|
//管理者
|
|
|
|
BookAdmin = 1
|
|
|
|
//编辑者.
|
|
|
|
BookEditor = 2
|
|
|
|
//观察者
|
|
|
|
BookObserver = 3
|
|
|
|
)
|
|
|
|
|
2017-06-09 18:14:55 +08:00
|
|
|
const (
|
|
|
|
LoggerOperate = "operate"
|
|
|
|
LoggerSystem = "system"
|
|
|
|
LoggerException = "exception"
|
|
|
|
LoggerDocument = "document"
|
|
|
|
)
|
2017-05-26 14:19:27 +08:00
|
|
|
const (
|
|
|
|
//本地账户校验
|
|
|
|
AuthMethodLocal = "local"
|
|
|
|
//LDAP用户校验
|
|
|
|
AuthMethodLDAP = "ldap"
|
|
|
|
)
|
2017-05-05 15:04:31 +08:00
|
|
|
var (
|
2017-05-11 13:39:34 +08:00
|
|
|
VERSION string
|
|
|
|
BUILD_TIME string
|
|
|
|
GO_VERSION string
|
2017-05-05 15:04:31 +08:00
|
|
|
)
|
|
|
|
|
2017-04-21 18:20:35 +08:00
|
|
|
// app_key
|
2017-05-11 13:39:34 +08:00
|
|
|
func GetAppKey() string {
|
|
|
|
return beego.AppConfig.DefaultString("app_key", "godoc")
|
2017-04-21 18:20:35 +08:00
|
|
|
}
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
func GetDatabasePrefix() string {
|
|
|
|
return beego.AppConfig.DefaultString("db_prefix", "md_")
|
2017-04-23 12:48:46 +08:00
|
|
|
}
|
2017-05-05 15:04:31 +08:00
|
|
|
|
2017-04-23 12:48:46 +08:00
|
|
|
//获取默认头像
|
|
|
|
func GetDefaultAvatar() string {
|
2017-05-11 13:39:34 +08:00
|
|
|
return beego.AppConfig.DefaultString("avatar", "/static/images/headimgurl.jpg")
|
2017-04-25 20:05:59 +08:00
|
|
|
}
|
|
|
|
|
2017-05-03 14:22:05 +08:00
|
|
|
//获取阅读令牌长度.
|
2017-04-25 20:05:59 +08:00
|
|
|
func GetTokenSize() int {
|
2017-05-11 13:39:34 +08:00
|
|
|
return beego.AppConfig.DefaultInt("token_size", 12)
|
2017-04-25 20:05:59 +08:00
|
|
|
}
|
|
|
|
|
2017-05-03 14:22:05 +08:00
|
|
|
//获取默认文档封面.
|
2017-04-25 20:05:59 +08:00
|
|
|
func GetDefaultCover() string {
|
2017-05-11 13:39:34 +08:00
|
|
|
return beego.AppConfig.DefaultString("cover", "/static/images/book.jpg")
|
2017-04-27 18:19:37 +08:00
|
|
|
}
|
|
|
|
|
2017-05-03 14:22:05 +08:00
|
|
|
//获取允许的商城文件的类型.
|
2017-05-11 13:39:34 +08:00
|
|
|
func GetUploadFileExt() []string {
|
|
|
|
ext := beego.AppConfig.DefaultString("upload_file_ext", "png|jpg|jpeg|gif|txt|doc|docx|pdf")
|
|
|
|
|
|
|
|
temp := strings.Split(ext, "|")
|
|
|
|
|
|
|
|
exts := make([]string, len(temp))
|
|
|
|
|
2017-04-27 18:19:37 +08:00
|
|
|
i := 0
|
2017-05-11 13:39:34 +08:00
|
|
|
for _, item := range temp {
|
2017-04-27 18:19:37 +08:00
|
|
|
if item != "" {
|
|
|
|
exts[i] = item
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exts
|
|
|
|
}
|
2017-05-05 15:04:31 +08:00
|
|
|
|
2017-05-03 14:22:05 +08:00
|
|
|
//判断是否是允许商城的文件类型.
|
2017-05-11 13:39:34 +08:00
|
|
|
func IsAllowUploadFileExt(ext string) bool {
|
2017-04-27 18:19:37 +08:00
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
if strings.HasPrefix(ext, ".") {
|
2017-04-27 18:19:37 +08:00
|
|
|
ext = string(ext[1:])
|
|
|
|
}
|
|
|
|
exts := GetUploadFileExt()
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
for _, item := range exts {
|
|
|
|
if strings.EqualFold(item, ext) {
|
|
|
|
return true
|
2017-04-27 18:19:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2017-05-03 14:22:05 +08:00
|
|
|
}
|