summaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-04-07 12:56:40 -0400
committerUnknown <joe2010xtmf@163.com>2014-04-07 12:56:40 -0400
commit9ea9818d3255e5b08293205e278240dece36687d (patch)
tree51c6a65586843082f451ee1e93082fec5784ccd2 /modules/base
parent05fb34eacdbec59fb8bcdf96c82c0855e6ec78d2 (diff)
downloadgitea-9ea9818d3255e5b08293205e278240dece36687d.tar.gz
gitea-9ea9818d3255e5b08293205e278240dece36687d.zip
Fix issue with log in with GitHub but need more error handle after
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/conf.go53
-rw-r--r--modules/base/markdown.go13
2 files changed, 48 insertions, 18 deletions
diff --git a/modules/base/conf.go b/modules/base/conf.go
index 0a618ab1d2..ba9c320d77 100644
--- a/modules/base/conf.go
+++ b/modules/base/conf.go
@@ -22,13 +22,21 @@ import (
"github.com/gogits/gogs/modules/log"
)
-// Mailer represents a mail service.
+// Mailer represents mail service.
type Mailer struct {
Name string
Host string
User, Passwd string
}
+// Oauther represents oauth service.
+type Oauther struct {
+ GitHub struct {
+ Enabled bool
+ ClientId, ClientSecret string
+ }
+}
+
var (
AppVer string
AppName string
@@ -45,8 +53,9 @@ var (
CookieUserName string
CookieRememberName string
- Cfg *goconfig.ConfigFile
- MailService *Mailer
+ Cfg *goconfig.ConfigFile
+ MailService *Mailer
+ OauthService *Oauther
LogMode string
LogConfig string
@@ -206,15 +215,17 @@ func newSessionService() {
func newMailService() {
// Check mailer setting.
- if Cfg.MustBool("mailer", "ENABLED") {
- MailService = &Mailer{
- Name: Cfg.MustValue("mailer", "NAME", AppName),
- Host: Cfg.MustValue("mailer", "HOST"),
- User: Cfg.MustValue("mailer", "USER"),
- Passwd: Cfg.MustValue("mailer", "PASSWD"),
- }
- log.Info("Mail Service Enabled")
+ if !Cfg.MustBool("mailer", "ENABLED") {
+ return
+ }
+
+ MailService = &Mailer{
+ Name: Cfg.MustValue("mailer", "NAME", AppName),
+ Host: Cfg.MustValue("mailer", "HOST"),
+ User: Cfg.MustValue("mailer", "USER"),
+ Passwd: Cfg.MustValue("mailer", "PASSWD"),
}
+ log.Info("Mail Service Enabled")
}
func newRegisterMailService() {
@@ -239,6 +250,25 @@ func newNotifyMailService() {
log.Info("Notify Mail Service Enabled")
}
+func newOauthService() {
+ if !Cfg.MustBool("oauth", "ENABLED") {
+ return
+ }
+
+ OauthService = &Oauther{}
+ oauths := make([]string, 0, 10)
+
+ // GitHub.
+ if Cfg.MustBool("oauth.github", "ENABLED") {
+ OauthService.GitHub.Enabled = true
+ OauthService.GitHub.ClientId = Cfg.MustValue("oauth.github", "CLIENT_ID")
+ OauthService.GitHub.ClientSecret = Cfg.MustValue("oauth.github", "CLIENT_SECRET")
+ oauths = append(oauths, "GitHub")
+ }
+
+ log.Info("Oauth Service Enabled %s", oauths)
+}
+
func NewConfigContext() {
//var err error
workDir, err := ExecDir()
@@ -303,4 +333,5 @@ func NewServices() {
newMailService()
newRegisterMailService()
newNotifyMailService()
+ newOauthService()
}
diff --git a/modules/base/markdown.go b/modules/base/markdown.go
index f0992d04df..ce1e2f5bec 100644
--- a/modules/base/markdown.go
+++ b/modules/base/markdown.go
@@ -90,21 +90,21 @@ func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte,
}
var (
- mentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`)
+ MentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`)
commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`)
issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`)
- issueIndexPattern = regexp.MustCompile(`(\s|^)#[0-9]+`)
+ issueIndexPattern = regexp.MustCompile(`#[0-9]+`)
)
func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte {
- ms := mentionPattern.FindAll(rawBytes, -1)
+ ms := MentionPattern.FindAll(rawBytes, -1)
for _, m := range ms {
rawBytes = bytes.Replace(rawBytes, m,
[]byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1)
}
ms = commitPattern.FindAll(rawBytes, -1)
for _, m := range ms {
- m = bytes.TrimPrefix(m, []byte(" "))
+ m = bytes.TrimSpace(m)
i := strings.Index(string(m), "commit/")
j := strings.Index(string(m), "#")
if j == -1 {
@@ -115,7 +115,7 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte {
}
ms = issueFullPattern.FindAll(rawBytes, -1)
for _, m := range ms {
- m = bytes.TrimPrefix(m, []byte(" "))
+ m = bytes.TrimSpace(m)
i := strings.Index(string(m), "issues/")
j := strings.Index(string(m), "#")
if j == -1 {
@@ -126,9 +126,8 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte {
}
ms = issueIndexPattern.FindAll(rawBytes, -1)
for _, m := range ms {
- m = bytes.TrimPrefix(m, []byte(" "))
rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
- ` <a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)), -1)
+ `<a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)), -1)
}
return rawBytes
}