Fixed #209
This commit is contained in:
parent
87854c95a9
commit
688ec6ecbd
37 changed files with 693 additions and 482 deletions
|
@ -13,6 +13,8 @@ import (
|
|||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
func Str2html(raw string) template.HTML {
|
||||
|
@ -52,16 +54,16 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
|
|||
return runtime.Version()
|
||||
},
|
||||
"AppName": func() string {
|
||||
return AppName
|
||||
return setting.AppName
|
||||
},
|
||||
"AppVer": func() string {
|
||||
return AppVer
|
||||
return setting.AppVer
|
||||
},
|
||||
"AppDomain": func() string {
|
||||
return Domain
|
||||
return setting.Domain
|
||||
},
|
||||
"CdnMode": func() bool {
|
||||
return ProdMode && !OfflineMode
|
||||
return setting.ProdMode && !setting.OfflineMode
|
||||
},
|
||||
"LoadTimes": func(startTime time.Time) string {
|
||||
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
|
||||
|
|
|
@ -16,6 +16,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
// Encode string to md5 hex value
|
||||
|
@ -131,7 +133,7 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
|
|||
|
||||
// create sha1 encode string
|
||||
sh := sha1.New()
|
||||
sh.Write([]byte(data + SecretKey + startStr + endStr + ToStr(minutes)))
|
||||
sh.Write([]byte(data + setting.SecretKey + startStr + endStr + ToStr(minutes)))
|
||||
encoded := hex.EncodeToString(sh.Sum(nil))
|
||||
|
||||
code := fmt.Sprintf("%s%06d%s", startStr, minutes, encoded)
|
||||
|
@ -140,9 +142,9 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
|
|||
|
||||
// AvatarLink returns avatar link by given e-mail.
|
||||
func AvatarLink(email string) string {
|
||||
if DisableGravatar {
|
||||
if setting.DisableGravatar {
|
||||
return "/img/avatar_default.jpg"
|
||||
} else if Service.EnableCacheAvatar {
|
||||
} else if setting.Service.EnableCacheAvatar {
|
||||
return "/avatar/" + EncodeMd5(email)
|
||||
}
|
||||
return "//1.gravatar.com/avatar/" + EncodeMd5(email)
|
||||
|
|
220
modules/bin/conf.go
Normal file
220
modules/bin/conf.go
Normal file
|
@ -0,0 +1,220 @@
|
|||
package bin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// bindata_read reads the given file from disk. It returns an error on failure.
|
||||
func bindata_read(path, name string) ([]byte, error) {
|
||||
buf, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error reading asset %s at %s: %v", name, path, err)
|
||||
}
|
||||
return buf, err
|
||||
}
|
||||
|
||||
// conf_app_ini reads file data from disk. It returns an error on failure.
|
||||
func conf_app_ini() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/app.ini",
|
||||
"conf/app.ini",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_content_git_bare_zip reads file data from disk. It returns an error on failure.
|
||||
func conf_content_git_bare_zip() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/content/git-bare.zip",
|
||||
"conf/content/git-bare.zip",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_etc_supervisord_conf reads file data from disk. It returns an error on failure.
|
||||
func conf_etc_supervisord_conf() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/etc/supervisord.conf",
|
||||
"conf/etc/supervisord.conf",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_android reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_android() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/Android",
|
||||
"conf/gitignore/Android",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_c reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_c() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/C",
|
||||
"conf/gitignore/C",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_c_sharp reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_c_sharp() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/C Sharp",
|
||||
"conf/gitignore/C Sharp",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_c_ reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_c_() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/C++",
|
||||
"conf/gitignore/C++",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_google_go reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_google_go() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/Google Go",
|
||||
"conf/gitignore/Google Go",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_java reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_java() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/Java",
|
||||
"conf/gitignore/Java",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_objective_c reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_objective_c() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/Objective-C",
|
||||
"conf/gitignore/Objective-C",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_python reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_python() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/Python",
|
||||
"conf/gitignore/Python",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_gitignore_ruby reads file data from disk. It returns an error on failure.
|
||||
func conf_gitignore_ruby() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/gitignore/Ruby",
|
||||
"conf/gitignore/Ruby",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_license_affero_gpl reads file data from disk. It returns an error on failure.
|
||||
func conf_license_affero_gpl() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/license/Affero GPL",
|
||||
"conf/license/Affero GPL",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_license_apache_v2_license reads file data from disk. It returns an error on failure.
|
||||
func conf_license_apache_v2_license() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/license/Apache v2 License",
|
||||
"conf/license/Apache v2 License",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_license_artistic_license_2_0 reads file data from disk. It returns an error on failure.
|
||||
func conf_license_artistic_license_2_0() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/license/Artistic License 2.0",
|
||||
"conf/license/Artistic License 2.0",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_license_bsd_3_clause_license reads file data from disk. It returns an error on failure.
|
||||
func conf_license_bsd_3_clause_license() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/license/BSD (3-Clause) License",
|
||||
"conf/license/BSD (3-Clause) License",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_license_gpl_v2 reads file data from disk. It returns an error on failure.
|
||||
func conf_license_gpl_v2() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/license/GPL v2",
|
||||
"conf/license/GPL v2",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_license_mit_license reads file data from disk. It returns an error on failure.
|
||||
func conf_license_mit_license() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/license/MIT License",
|
||||
"conf/license/MIT License",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_mysql_sql reads file data from disk. It returns an error on failure.
|
||||
func conf_mysql_sql() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/mysql.sql",
|
||||
"conf/mysql.sql",
|
||||
)
|
||||
}
|
||||
|
||||
// conf_supervisor_ini reads file data from disk. It returns an error on failure.
|
||||
func conf_supervisor_ini() ([]byte, error) {
|
||||
return bindata_read(
|
||||
"/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/conf/supervisor.ini",
|
||||
"conf/supervisor.ini",
|
||||
)
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
|
||||
// AssetNames returns the names of the assets.
|
||||
func AssetNames() []string {
|
||||
names := make([]string, 0, len(_bindata))
|
||||
for name := range _bindata {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() ([]byte, error){
|
||||
"conf/app.ini": conf_app_ini,
|
||||
"conf/content/git-bare.zip": conf_content_git_bare_zip,
|
||||
"conf/etc/supervisord.conf": conf_etc_supervisord_conf,
|
||||
"conf/gitignore/Android": conf_gitignore_android,
|
||||
"conf/gitignore/C": conf_gitignore_c,
|
||||
"conf/gitignore/C Sharp": conf_gitignore_c_sharp,
|
||||
"conf/gitignore/C++": conf_gitignore_c_,
|
||||
"conf/gitignore/Google Go": conf_gitignore_google_go,
|
||||
"conf/gitignore/Java": conf_gitignore_java,
|
||||
"conf/gitignore/Objective-C": conf_gitignore_objective_c,
|
||||
"conf/gitignore/Python": conf_gitignore_python,
|
||||
"conf/gitignore/Ruby": conf_gitignore_ruby,
|
||||
"conf/license/Affero GPL": conf_license_affero_gpl,
|
||||
"conf/license/Apache v2 License": conf_license_apache_v2_license,
|
||||
"conf/license/Artistic License 2.0": conf_license_artistic_license_2_0,
|
||||
"conf/license/BSD (3-Clause) License": conf_license_bsd_3_clause_license,
|
||||
"conf/license/GPL v2": conf_license_gpl_v2,
|
||||
"conf/license/MIT License": conf_license_mit_license,
|
||||
"conf/mysql.sql": conf_mysql_sql,
|
||||
"conf/supervisor.ini": conf_supervisor_ini,
|
||||
}
|
|
@ -6,6 +6,8 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/gogits/logs"
|
||||
)
|
||||
|
||||
|
@ -69,3 +71,11 @@ func Critical(format string, v ...interface{}) {
|
|||
logger.Critical(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func Fatal(format string, v ...interface{}) {
|
||||
Error(format, v...)
|
||||
for _, l := range loggers {
|
||||
l.Close()
|
||||
}
|
||||
os.Exit(2)
|
||||
}
|
||||
|
|
|
@ -14,28 +14,29 @@ import (
|
|||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
// Create New mail message use MailFrom and MailUser
|
||||
func NewMailMessageFrom(To []string, from, subject, body string) Message {
|
||||
msg := NewHtmlMessage(To, from, subject, body)
|
||||
msg.User = base.MailService.User
|
||||
msg.User = setting.MailService.User
|
||||
return msg
|
||||
}
|
||||
|
||||
// Create New mail message use MailFrom and MailUser
|
||||
func NewMailMessage(To []string, subject, body string) Message {
|
||||
return NewMailMessageFrom(To, base.MailService.User, subject, body)
|
||||
return NewMailMessageFrom(To, setting.MailService.User, subject, body)
|
||||
}
|
||||
|
||||
func GetMailTmplData(user *models.User) map[interface{}]interface{} {
|
||||
data := make(map[interface{}]interface{}, 10)
|
||||
data["AppName"] = base.AppName
|
||||
data["AppVer"] = base.AppVer
|
||||
data["AppUrl"] = base.AppUrl
|
||||
data["AppLogo"] = base.AppLogo
|
||||
data["ActiveCodeLives"] = base.Service.ActiveCodeLives / 60
|
||||
data["ResetPwdCodeLives"] = base.Service.ResetPwdCodeLives / 60
|
||||
data["AppName"] = setting.AppName
|
||||
data["AppVer"] = setting.AppVer
|
||||
data["AppUrl"] = setting.AppUrl
|
||||
data["AppLogo"] = setting.AppLogo
|
||||
data["ActiveCodeLives"] = setting.Service.ActiveCodeLives / 60
|
||||
data["ResetPwdCodeLives"] = setting.Service.ResetPwdCodeLives / 60
|
||||
if user != nil {
|
||||
data["User"] = user
|
||||
}
|
||||
|
@ -44,7 +45,7 @@ func GetMailTmplData(user *models.User) map[interface{}]interface{} {
|
|||
|
||||
// create a time limit code for user active
|
||||
func CreateUserActiveCode(user *models.User, startInf interface{}) string {
|
||||
minutes := base.Service.ActiveCodeLives
|
||||
minutes := setting.Service.ActiveCodeLives
|
||||
data := base.ToStr(user.Id) + user.Email + user.LowerName + user.Passwd + user.Rands
|
||||
code := base.CreateTimeLimitCode(data, minutes, startInf)
|
||||
|
||||
|
@ -139,7 +140,7 @@ func SendIssueNotifyMail(user, owner *models.User, repo *models.Repository, issu
|
|||
subject := fmt.Sprintf("[%s] %s(#%d)", repo.Name, issue.Name, issue.Index)
|
||||
content := fmt.Sprintf("%s<br>-<br> <a href=\"%s%s/%s/issues/%d\">View it on Gogs</a>.",
|
||||
base.RenderSpecialLink([]byte(issue.Content), owner.Name+"/"+repo.Name),
|
||||
base.AppUrl, owner.Name, repo.Name, issue.Index)
|
||||
setting.AppUrl, owner.Name, repo.Name, issue.Index)
|
||||
msg := NewMailMessageFrom(tos, user.Email, subject, content)
|
||||
msg.Info = fmt.Sprintf("Subject: %s, send issue notify emails", subject)
|
||||
SendAsync(&msg)
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"net/smtp"
|
||||
"strings"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
|
@ -41,7 +41,7 @@ func (m Message) Content() string {
|
|||
var mailQueue chan *Message
|
||||
|
||||
func NewMailerContext() {
|
||||
mailQueue = make(chan *Message, base.Cfg.MustInt("mailer", "SEND_BUFFER_LEN", 10))
|
||||
mailQueue = make(chan *Message, setting.Cfg.MustInt("mailer", "SEND_BUFFER_LEN", 10))
|
||||
go processMailQueue()
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ func processMailQueue() {
|
|||
// Direct Send mail message
|
||||
func Send(msg *Message) (int, error) {
|
||||
log.Trace("Sending mails to: %s", strings.Join(msg.To, "; "))
|
||||
host := strings.Split(base.MailService.Host, ":")
|
||||
host := strings.Split(setting.MailService.Host, ":")
|
||||
|
||||
// get message body
|
||||
content := msg.Content()
|
||||
|
@ -78,14 +78,14 @@ func Send(msg *Message) (int, error) {
|
|||
return 0, fmt.Errorf("empty email body")
|
||||
}
|
||||
|
||||
auth := smtp.PlainAuth("", base.MailService.User, base.MailService.Passwd, host[0])
|
||||
auth := smtp.PlainAuth("", setting.MailService.User, setting.MailService.Passwd, host[0])
|
||||
|
||||
if msg.Massive {
|
||||
// send mail to multiple emails one by one
|
||||
num := 0
|
||||
for _, to := range msg.To {
|
||||
body := []byte("To: " + to + "\r\n" + content)
|
||||
err := smtp.SendMail(base.MailService.Host, auth, msg.From, []string{to}, body)
|
||||
err := smtp.SendMail(setting.MailService.Host, auth, msg.From, []string{to}, body)
|
||||
if err != nil {
|
||||
return num, err
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ func Send(msg *Message) (int, error) {
|
|||
body := []byte("To: " + strings.Join(msg.To, ";") + "\r\n" + content)
|
||||
|
||||
// send to multiple emails in one message
|
||||
err := smtp.SendMail(base.MailService.Host, auth, msg.From, msg.To, body)
|
||||
err := smtp.SendMail(setting.MailService.Host, auth, msg.From, msg.To, body)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
type ToggleOptions struct {
|
||||
|
@ -23,7 +23,7 @@ type ToggleOptions struct {
|
|||
func Toggle(options *ToggleOptions) martini.Handler {
|
||||
return func(ctx *Context) {
|
||||
// Cannot view any page before installation.
|
||||
if !base.InstallLock {
|
||||
if !setting.InstallLock {
|
||||
ctx.Redirect("/install")
|
||||
return
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func Toggle(options *ToggleOptions) martini.Handler {
|
|||
ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI))
|
||||
ctx.Redirect("/user/login")
|
||||
return
|
||||
} else if !ctx.User.IsActive && base.Service.RegisterEmailConfirm {
|
||||
} else if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
||||
ctx.Data["Title"] = "Activate Your Account"
|
||||
ctx.HTML(200, "user/activate")
|
||||
return
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/auth"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
// Context represents context of a request.
|
||||
|
@ -325,14 +326,14 @@ func InitContext() martini.Handler {
|
|||
// p: p,
|
||||
Req: r,
|
||||
Res: res,
|
||||
Cache: base.Cache,
|
||||
Cache: setting.Cache,
|
||||
Render: rd,
|
||||
}
|
||||
|
||||
ctx.Data["PageStartTime"] = time.Now()
|
||||
|
||||
// start session
|
||||
ctx.Session = base.SessionManager.SessionStart(res, r)
|
||||
ctx.Session = setting.SessionManager.SessionStart(res, r)
|
||||
|
||||
// Get flash.
|
||||
values, err := url.ParseQuery(ctx.GetCookie("gogs_flash"))
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
var isWindows bool
|
||||
|
@ -24,7 +24,7 @@ func init() {
|
|||
|
||||
func Logger() martini.Handler {
|
||||
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) {
|
||||
if base.DisableRouterLog {
|
||||
if setting.DisableRouterLog {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -38,26 +38,18 @@ var helperFuncs = template.FuncMap{
|
|||
}
|
||||
|
||||
type Delims struct {
|
||||
Left string
|
||||
|
||||
Left string
|
||||
Right string
|
||||
}
|
||||
|
||||
type RenderOptions struct {
|
||||
Directory string
|
||||
|
||||
Layout string
|
||||
|
||||
Extensions []string
|
||||
|
||||
Funcs []template.FuncMap
|
||||
|
||||
Delims Delims
|
||||
|
||||
Charset string
|
||||
|
||||
IndentJSON bool
|
||||
|
||||
Directory string
|
||||
Layout string
|
||||
Extensions []string
|
||||
Funcs []template.FuncMap
|
||||
Delims Delims
|
||||
Charset string
|
||||
IndentJSON bool
|
||||
HTMLContentType string
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ import (
|
|||
"github.com/gogits/git"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
func RepoAssignment(redirect bool, args ...bool) martini.Handler {
|
||||
|
@ -159,17 +159,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
|
|||
ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner
|
||||
ctx.Data["BranchName"] = ""
|
||||
|
||||
if base.SshPort != 22 {
|
||||
ctx.Repo.CloneLink.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName)
|
||||
if setting.SshPort != 22 {
|
||||
ctx.Repo.CloneLink.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", setting.RunUser, setting.Domain, user.LowerName, repo.LowerName)
|
||||
} else {
|
||||
ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName)
|
||||
ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.Domain, user.LowerName, repo.LowerName)
|
||||
}
|
||||
ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", base.AppUrl, user.LowerName, repo.LowerName)
|
||||
ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s%s/%s.git", setting.AppUrl, user.LowerName, repo.LowerName)
|
||||
ctx.Data["CloneLink"] = ctx.Repo.CloneLink
|
||||
|
||||
if ctx.Repo.Repository.IsGoget {
|
||||
ctx.Data["GoGetLink"] = fmt.Sprintf("%s%s/%s", base.AppUrl, user.LowerName, repo.LowerName)
|
||||
ctx.Data["GoGetImport"] = fmt.Sprintf("%s/%s/%s", base.Domain, user.LowerName, repo.LowerName)
|
||||
ctx.Data["GoGetLink"] = fmt.Sprintf("%s%s/%s", setting.AppUrl, user.LowerName, repo.LowerName)
|
||||
ctx.Data["GoGetImport"] = fmt.Sprintf("%s/%s/%s", setting.Domain, user.LowerName, repo.LowerName)
|
||||
}
|
||||
|
||||
// when repo is bare, not valid branch
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package base
|
||||
package setting
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -14,78 +14,171 @@ import (
|
|||
|
||||
"github.com/Unknwon/com"
|
||||
"github.com/Unknwon/goconfig"
|
||||
qlog "github.com/qiniu/log"
|
||||
|
||||
"github.com/gogits/cache"
|
||||
"github.com/gogits/session"
|
||||
|
||||
"github.com/gogits/gogs/modules/bin"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
)
|
||||
|
||||
// Mailer represents mail service.
|
||||
type Mailer struct {
|
||||
Name string
|
||||
Host string
|
||||
User, Passwd string
|
||||
}
|
||||
type Scheme string
|
||||
|
||||
type OauthInfo struct {
|
||||
ClientId, ClientSecret string
|
||||
Scopes string
|
||||
AuthUrl, TokenUrl string
|
||||
}
|
||||
|
||||
// Oauther represents oauth service.
|
||||
type Oauther struct {
|
||||
GitHub, Google, Tencent,
|
||||
Twitter, Weibo bool
|
||||
OauthInfos map[string]*OauthInfo
|
||||
}
|
||||
const (
|
||||
HTTP Scheme = "http"
|
||||
HTTPS Scheme = "https"
|
||||
)
|
||||
|
||||
var (
|
||||
AppVer string
|
||||
AppName string
|
||||
AppLogo string
|
||||
AppUrl string
|
||||
SshPort int
|
||||
OfflineMode bool
|
||||
DisableRouterLog bool
|
||||
ProdMode bool
|
||||
Domain string
|
||||
SecretKey string
|
||||
RunUser string
|
||||
// App settings.
|
||||
AppVer string
|
||||
AppName string
|
||||
AppLogo string
|
||||
AppUrl string
|
||||
|
||||
RepoRootPath string
|
||||
ScriptType string
|
||||
|
||||
InstallLock bool
|
||||
// Server settings.
|
||||
Protocol Scheme
|
||||
Domain string
|
||||
HttpAddr, HttpPort string
|
||||
SshPort int
|
||||
OfflineMode bool
|
||||
DisableRouterLog bool
|
||||
CertFile, KeyFile string
|
||||
StaticRootPath string
|
||||
|
||||
// Security settings.
|
||||
InstallLock bool
|
||||
SecretKey string
|
||||
LogInRememberDays int
|
||||
CookieUserName string
|
||||
CookieRememberName string
|
||||
|
||||
Cfg *goconfig.ConfigFile
|
||||
MailService *Mailer
|
||||
OauthService *Oauther
|
||||
// Repository settings.
|
||||
RepoRootPath string
|
||||
ScriptType string
|
||||
|
||||
// Picture settings.
|
||||
PictureService string
|
||||
DisableGravatar bool
|
||||
|
||||
// Log settings.
|
||||
LogModes []string
|
||||
LogConfigs []string
|
||||
|
||||
// Cache settings.
|
||||
Cache cache.Cache
|
||||
CacheAdapter string
|
||||
CacheConfig string
|
||||
|
||||
EnableRedis bool
|
||||
EnableMemcache bool
|
||||
|
||||
// Session settings.
|
||||
SessionProvider string
|
||||
SessionConfig *session.Config
|
||||
SessionManager *session.Manager
|
||||
|
||||
PictureService string
|
||||
DisableGravatar bool
|
||||
|
||||
EnableRedis bool
|
||||
EnableMemcache bool
|
||||
// Global setting objects.
|
||||
Cfg *goconfig.ConfigFile
|
||||
CustomPath string // Custom directory path.
|
||||
ProdMode bool
|
||||
RunUser string
|
||||
)
|
||||
|
||||
// WorkDir returns absolute path of work directory.
|
||||
func WorkDir() (string, error) {
|
||||
file, err := exec.LookPath(os.Args[0])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
p, err := filepath.Abs(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path.Dir(strings.Replace(p, "\\", "/", -1)), nil
|
||||
}
|
||||
|
||||
// NewConfigContext initializes configuration context.
|
||||
func NewConfigContext() {
|
||||
workDir, err := WorkDir()
|
||||
if err != nil {
|
||||
log.Fatal("Fail to get work directory: %v", err)
|
||||
}
|
||||
|
||||
data, err := bin.Asset("conf/app.ini")
|
||||
if err != nil {
|
||||
log.Fatal("Fail to read 'conf/app.ini': %v", err)
|
||||
}
|
||||
Cfg, err = goconfig.LoadFromData(data)
|
||||
if err != nil {
|
||||
log.Fatal("Fail to parse 'conf/app.ini': %v", err)
|
||||
}
|
||||
|
||||
CustomPath = os.Getenv("GOGS_CUSTOM")
|
||||
if len(CustomPath) == 0 {
|
||||
CustomPath = path.Join(workDir, "custom")
|
||||
}
|
||||
log.Trace("Custom path: %s", CustomPath)
|
||||
|
||||
cfgPath := path.Join(CustomPath, "conf/app.ini")
|
||||
if com.IsFile(cfgPath) {
|
||||
if err = Cfg.AppendFiles(cfgPath); err != nil {
|
||||
log.Fatal("Fail to load custom 'conf/app.ini': %v", err)
|
||||
}
|
||||
} else {
|
||||
log.Warn("No custom 'conf/app.ini' found")
|
||||
}
|
||||
|
||||
AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
|
||||
AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
|
||||
AppUrl = Cfg.MustValue("server", "ROOT_URL", "http://localhost:3000")
|
||||
|
||||
Protocol = HTTP
|
||||
if Cfg.MustValue("server", "PROTOCOL") == "https" {
|
||||
Protocol = HTTPS
|
||||
CertFile = Cfg.MustValue("server", "CERT_FILE")
|
||||
KeyFile = Cfg.MustValue("server", "KEY_FILE")
|
||||
}
|
||||
Domain = Cfg.MustValue("server", "DOMAIN", "localhost")
|
||||
HttpAddr = Cfg.MustValue("server", "HTTP_ADDR", "0.0.0.0")
|
||||
HttpPort = Cfg.MustValue("server", "HTTP_PORT", "3000")
|
||||
SshPort = Cfg.MustInt("server", "SSH_PORT", 22)
|
||||
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE")
|
||||
DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG")
|
||||
StaticRootPath = Cfg.MustValue("server", "STATIC_ROOT_PATH")
|
||||
|
||||
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK")
|
||||
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
|
||||
LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
|
||||
CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
|
||||
CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")
|
||||
|
||||
RunUser = Cfg.MustValue("", "RUN_USER")
|
||||
curUser := os.Getenv("USER")
|
||||
if len(curUser) == 0 {
|
||||
curUser = os.Getenv("USERNAME")
|
||||
}
|
||||
// Does not check run user when the install lock is off.
|
||||
if InstallLock && RunUser != curUser {
|
||||
log.Fatal("Expect user(%s) but current user is: %s", RunUser, curUser)
|
||||
}
|
||||
|
||||
// Determine and create root git reposiroty path.
|
||||
homeDir, err := com.HomeDir()
|
||||
if err != nil {
|
||||
log.Fatal("Fail to get home directory: %v", err)
|
||||
}
|
||||
RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
|
||||
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
|
||||
log.Fatal("Fail to create repository root path(%s): %v", RepoRootPath, err)
|
||||
}
|
||||
ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
|
||||
|
||||
PictureService = Cfg.MustValueRange("picture", "SERVICE", "server",
|
||||
[]string{"server"})
|
||||
DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR")
|
||||
}
|
||||
|
||||
var Service struct {
|
||||
RegisterEmailConfirm bool
|
||||
DisableRegistration bool
|
||||
|
@ -97,17 +190,12 @@ var Service struct {
|
|||
LdapAuth bool
|
||||
}
|
||||
|
||||
// ExecDir returns absolute path execution(binary) path.
|
||||
func ExecDir() (string, error) {
|
||||
file, err := exec.LookPath(os.Args[0])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
p, err := filepath.Abs(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path.Dir(strings.Replace(p, "\\", "/", -1)), nil
|
||||
func newService() {
|
||||
Service.ActiveCodeLives = Cfg.MustInt("service", "ACTIVE_CODE_LIVE_MINUTES", 180)
|
||||
Service.ResetPwdCodeLives = Cfg.MustInt("service", "RESET_PASSWD_CODE_LIVE_MINUTES", 180)
|
||||
Service.DisableRegistration = Cfg.MustBool("service", "DISABLE_REGISTRATION")
|
||||
Service.RequireSignInView = Cfg.MustBool("service", "REQUIRE_SIGNIN_VIEW")
|
||||
Service.EnableCacheAvatar = Cfg.MustBool("service", "ENABLE_CACHE_AVATAR")
|
||||
}
|
||||
|
||||
var logLevels = map[string]string{
|
||||
|
@ -119,14 +207,6 @@ var logLevels = map[string]string{
|
|||
"Critical": "5",
|
||||
}
|
||||
|
||||
func newService() {
|
||||
Service.ActiveCodeLives = Cfg.MustInt("service", "ACTIVE_CODE_LIVE_MINUTES", 180)
|
||||
Service.ResetPwdCodeLives = Cfg.MustInt("service", "RESET_PASSWD_CODE_LIVE_MINUTES", 180)
|
||||
Service.DisableRegistration = Cfg.MustBool("service", "DISABLE_REGISTRATION", false)
|
||||
Service.RequireSignInView = Cfg.MustBool("service", "REQUIRE_SIGNIN_VIEW", false)
|
||||
Service.EnableCacheAvatar = Cfg.MustBool("service", "ENABLE_CACHE_AVATAR", false)
|
||||
}
|
||||
|
||||
func newLogService() {
|
||||
log.Info("%s %s", AppName, AppVer)
|
||||
|
||||
|
@ -137,7 +217,7 @@ func newLogService() {
|
|||
mode = strings.TrimSpace(mode)
|
||||
modeSec := "log." + mode
|
||||
if _, err := Cfg.GetSection(modeSec); err != nil {
|
||||
qlog.Fatalf("Unknown log mode: %s\n", mode)
|
||||
log.Fatal("Unknown log mode: %s", mode)
|
||||
}
|
||||
|
||||
// Log level.
|
||||
|
@ -145,7 +225,7 @@ func newLogService() {
|
|||
[]string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"})
|
||||
level, ok := logLevels[levelName]
|
||||
if !ok {
|
||||
qlog.Fatalf("Unknown log level: %s\n", levelName)
|
||||
log.Fatal("Unknown log level: %s", levelName)
|
||||
}
|
||||
|
||||
// Generate log configuration.
|
||||
|
@ -165,8 +245,8 @@ func newLogService() {
|
|||
Cfg.MustInt(modeSec, "MAX_DAYS", 7))
|
||||
case "conn":
|
||||
LogConfigs[i] = fmt.Sprintf(`{"level":"%s","reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level,
|
||||
Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false),
|
||||
Cfg.MustBool(modeSec, "RECONNECT", false),
|
||||
Cfg.MustBool(modeSec, "RECONNECT_ON_MSG"),
|
||||
Cfg.MustBool(modeSec, "RECONNECT"),
|
||||
Cfg.MustValueRange(modeSec, "PROTOCOL", "tcp", []string{"tcp", "unix", "udp"}),
|
||||
Cfg.MustValue(modeSec, "ADDR", ":7020"))
|
||||
case "smtp":
|
||||
|
@ -202,13 +282,13 @@ func newCacheService() {
|
|||
case "redis", "memcache":
|
||||
CacheConfig = fmt.Sprintf(`{"conn":"%s"}`, Cfg.MustValue("cache", "HOST"))
|
||||
default:
|
||||
qlog.Fatalf("Unknown cache adapter: %s\n", CacheAdapter)
|
||||
log.Fatal("Unknown cache adapter: %s", CacheAdapter)
|
||||
}
|
||||
|
||||
var err error
|
||||
Cache, err = cache.NewCache(CacheAdapter, CacheConfig)
|
||||
if err != nil {
|
||||
qlog.Fatalf("Init cache system failed, adapter: %s, config: %s, %v\n",
|
||||
log.Fatal("Init cache system failed, adapter: %s, config: %s, %v\n",
|
||||
CacheAdapter, CacheConfig, err)
|
||||
}
|
||||
|
||||
|
@ -237,13 +317,38 @@ func newSessionService() {
|
|||
var err error
|
||||
SessionManager, err = session.NewManager(SessionProvider, *SessionConfig)
|
||||
if err != nil {
|
||||
qlog.Fatalf("Init session system failed, provider: %s, %v\n",
|
||||
log.Fatal("Init session system failed, provider: %s, %v",
|
||||
SessionProvider, err)
|
||||
}
|
||||
|
||||
log.Info("Session Service Enabled")
|
||||
}
|
||||
|
||||
// Mailer represents mail service.
|
||||
type Mailer struct {
|
||||
Name string
|
||||
Host string
|
||||
User, Passwd string
|
||||
}
|
||||
|
||||
type OauthInfo struct {
|
||||
ClientId, ClientSecret string
|
||||
Scopes string
|
||||
AuthUrl, TokenUrl string
|
||||
}
|
||||
|
||||
// Oauther represents oauth service.
|
||||
type Oauther struct {
|
||||
GitHub, Google, Tencent,
|
||||
Twitter, Weibo bool
|
||||
OauthInfos map[string]*OauthInfo
|
||||
}
|
||||
|
||||
var (
|
||||
MailService *Mailer
|
||||
OauthService *Oauther
|
||||
)
|
||||
|
||||
func newMailService() {
|
||||
// Check mailer setting.
|
||||
if !Cfg.MustBool("mailer", "ENABLED") {
|
||||
|
@ -281,69 +386,7 @@ func newNotifyMailService() {
|
|||
log.Info("Notify Mail Service Enabled")
|
||||
}
|
||||
|
||||
func NewConfigContext() {
|
||||
workDir, err := ExecDir()
|
||||
if err != nil {
|
||||
qlog.Fatalf("Fail to get work directory: %s\n", err)
|
||||
}
|
||||
|
||||
cfgPath := filepath.Join(workDir, "conf/app.ini")
|
||||
Cfg, err = goconfig.LoadConfigFile(cfgPath)
|
||||
if err != nil {
|
||||
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||
}
|
||||
Cfg.BlockMode = false
|
||||
|
||||
cfgPaths := []string{os.Getenv("GOGS_CONFIG"), filepath.Join(workDir, "custom/conf/app.ini")}
|
||||
for _, cfgPath := range cfgPaths {
|
||||
if com.IsFile(cfgPath) {
|
||||
if err = Cfg.AppendFiles(cfgPath); err != nil {
|
||||
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
|
||||
AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
|
||||
AppUrl = Cfg.MustValue("server", "ROOT_URL")
|
||||
Domain = Cfg.MustValue("server", "DOMAIN")
|
||||
SshPort = Cfg.MustInt("server", "SSH_PORT", 22)
|
||||
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
|
||||
DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG", false)
|
||||
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
|
||||
|
||||
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
|
||||
|
||||
RunUser = Cfg.MustValue("", "RUN_USER")
|
||||
curUser := os.Getenv("USER")
|
||||
if len(curUser) == 0 {
|
||||
curUser = os.Getenv("USERNAME")
|
||||
}
|
||||
// Does not check run user when the install lock is off.
|
||||
if InstallLock && RunUser != curUser {
|
||||
qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
|
||||
}
|
||||
|
||||
LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
|
||||
CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
|
||||
CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")
|
||||
|
||||
PictureService = Cfg.MustValue("picture", "SERVICE")
|
||||
DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR", false)
|
||||
|
||||
// Determine and create root git reposiroty path.
|
||||
homeDir, err := com.HomeDir()
|
||||
if err != nil {
|
||||
qlog.Fatalf("Fail to get home directory): %v\n", err)
|
||||
}
|
||||
RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
|
||||
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
|
||||
qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
|
||||
}
|
||||
ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
|
||||
}
|
||||
|
||||
func NewBaseServices() {
|
||||
func NewServices() {
|
||||
newService()
|
||||
newLogService()
|
||||
newCacheService()
|
|
@ -15,8 +15,8 @@ import (
|
|||
oauth "github.com/gogits/oauth2"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
type BasicUserInfo struct {
|
||||
|
@ -40,67 +40,67 @@ var (
|
|||
)
|
||||
|
||||
func NewOauthService() {
|
||||
if !base.Cfg.MustBool("oauth", "ENABLED") {
|
||||
if !setting.Cfg.MustBool("oauth", "ENABLED") {
|
||||
return
|
||||
}
|
||||
|
||||
base.OauthService = &base.Oauther{}
|
||||
base.OauthService.OauthInfos = make(map[string]*base.OauthInfo)
|
||||
setting.OauthService = &setting.Oauther{}
|
||||
setting.OauthService.OauthInfos = make(map[string]*setting.OauthInfo)
|
||||
|
||||
socialConfigs := make(map[string]*oauth.Config)
|
||||
allOauthes := []string{"github", "google", "qq", "twitter", "weibo"}
|
||||
// Load all OAuth config data.
|
||||
for _, name := range allOauthes {
|
||||
base.OauthService.OauthInfos[name] = &base.OauthInfo{
|
||||
ClientId: base.Cfg.MustValue("oauth."+name, "CLIENT_ID"),
|
||||
ClientSecret: base.Cfg.MustValue("oauth."+name, "CLIENT_SECRET"),
|
||||
Scopes: base.Cfg.MustValue("oauth."+name, "SCOPES"),
|
||||
AuthUrl: base.Cfg.MustValue("oauth."+name, "AUTH_URL"),
|
||||
TokenUrl: base.Cfg.MustValue("oauth."+name, "TOKEN_URL"),
|
||||
setting.OauthService.OauthInfos[name] = &setting.OauthInfo{
|
||||
ClientId: setting.Cfg.MustValue("oauth."+name, "CLIENT_ID"),
|
||||
ClientSecret: setting.Cfg.MustValue("oauth."+name, "CLIENT_SECRET"),
|
||||
Scopes: setting.Cfg.MustValue("oauth."+name, "SCOPES"),
|
||||
AuthUrl: setting.Cfg.MustValue("oauth."+name, "AUTH_URL"),
|
||||
TokenUrl: setting.Cfg.MustValue("oauth."+name, "TOKEN_URL"),
|
||||
}
|
||||
socialConfigs[name] = &oauth.Config{
|
||||
ClientId: base.OauthService.OauthInfos[name].ClientId,
|
||||
ClientSecret: base.OauthService.OauthInfos[name].ClientSecret,
|
||||
RedirectURL: strings.TrimSuffix(base.AppUrl, "/") + SocialBaseUrl + name,
|
||||
Scope: base.OauthService.OauthInfos[name].Scopes,
|
||||
AuthURL: base.OauthService.OauthInfos[name].AuthUrl,
|
||||
TokenURL: base.OauthService.OauthInfos[name].TokenUrl,
|
||||
ClientId: setting.OauthService.OauthInfos[name].ClientId,
|
||||
ClientSecret: setting.OauthService.OauthInfos[name].ClientSecret,
|
||||
RedirectURL: strings.TrimSuffix(setting.AppUrl, "/") + SocialBaseUrl + name,
|
||||
Scope: setting.OauthService.OauthInfos[name].Scopes,
|
||||
AuthURL: setting.OauthService.OauthInfos[name].AuthUrl,
|
||||
TokenURL: setting.OauthService.OauthInfos[name].TokenUrl,
|
||||
}
|
||||
}
|
||||
|
||||
enabledOauths := make([]string, 0, 10)
|
||||
|
||||
// GitHub.
|
||||
if base.Cfg.MustBool("oauth.github", "ENABLED") {
|
||||
base.OauthService.GitHub = true
|
||||
if setting.Cfg.MustBool("oauth.github", "ENABLED") {
|
||||
setting.OauthService.GitHub = true
|
||||
newGitHubOauth(socialConfigs["github"])
|
||||
enabledOauths = append(enabledOauths, "GitHub")
|
||||
}
|
||||
|
||||
// Google.
|
||||
if base.Cfg.MustBool("oauth.google", "ENABLED") {
|
||||
base.OauthService.Google = true
|
||||
if setting.Cfg.MustBool("oauth.google", "ENABLED") {
|
||||
setting.OauthService.Google = true
|
||||
newGoogleOauth(socialConfigs["google"])
|
||||
enabledOauths = append(enabledOauths, "Google")
|
||||
}
|
||||
|
||||
// QQ.
|
||||
if base.Cfg.MustBool("oauth.qq", "ENABLED") {
|
||||
base.OauthService.Tencent = true
|
||||
if setting.Cfg.MustBool("oauth.qq", "ENABLED") {
|
||||
setting.OauthService.Tencent = true
|
||||
newTencentOauth(socialConfigs["qq"])
|
||||
enabledOauths = append(enabledOauths, "QQ")
|
||||
}
|
||||
|
||||
// Twitter.
|
||||
if base.Cfg.MustBool("oauth.twitter", "ENABLED") {
|
||||
base.OauthService.Twitter = true
|
||||
if setting.Cfg.MustBool("oauth.twitter", "ENABLED") {
|
||||
setting.OauthService.Twitter = true
|
||||
newTwitterOauth(socialConfigs["twitter"])
|
||||
enabledOauths = append(enabledOauths, "Twitter")
|
||||
}
|
||||
|
||||
// Weibo.
|
||||
if base.Cfg.MustBool("oauth.weibo", "ENABLED") {
|
||||
base.OauthService.Weibo = true
|
||||
if setting.Cfg.MustBool("oauth.weibo", "ENABLED") {
|
||||
setting.OauthService.Weibo = true
|
||||
newWeiboOauth(socialConfigs["weibo"])
|
||||
enabledOauths = append(enabledOauths, "Weibo")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue