diff options
Diffstat (limited to 'modules/base')
-rw-r--r-- | modules/base/conf.go | 37 | ||||
-rw-r--r-- | modules/base/markdown.go | 4 | ||||
-rw-r--r-- | modules/base/template.go | 22 |
3 files changed, 35 insertions, 28 deletions
diff --git a/modules/base/conf.go b/modules/base/conf.go index d1564aa1..957ec57b 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -29,13 +29,17 @@ type Mailer struct { User, Passwd string } +type OauthInfo struct { + ClientId, ClientSecret string + Scopes string + AuthUrl, TokenUrl string +} + // Oauther represents oauth service. type Oauther struct { - GitHub struct { - Enabled bool - ClientId, ClientSecret string - Scopes string - } + GitHub, Google, Tencent bool + Twitter, Weibo bool + OauthInfos map[string]*OauthInfo } var ( @@ -252,26 +256,6 @@ 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") - OauthService.GitHub.Scopes = Cfg.MustValue("oauth.github", "SCOPES") - oauths = append(oauths, "GitHub") - } - - log.Info("Oauth Service Enabled %s", oauths) -} - func NewConfigContext() { //var err error workDir, err := ExecDir() @@ -328,7 +312,7 @@ func NewConfigContext() { } } -func NewServices() { +func NewBaseServices() { newService() newLogService() newCacheService() @@ -336,5 +320,4 @@ func NewServices() { newMailService() newRegisterMailService() newNotifyMailService() - newOauthService() } diff --git a/modules/base/markdown.go b/modules/base/markdown.go index cc180775..95b4b212 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -166,3 +166,7 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { // fmt.Println(string(body)) return body } + +func RenderMarkdownString(raw, urlPrefix string) string { + return string(RenderMarkdown([]byte(raw), urlPrefix)) +} diff --git a/modules/base/template.go b/modules/base/template.go index 62414979..79aeeb9d 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -92,6 +92,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "DiffTypeToStr": DiffTypeToStr, "DiffLineTypeToStr": DiffLineTypeToStr, "ShortSha": ShortSha, + "Oauth2Icon": Oauth2Icon, } type Actioner interface { @@ -109,7 +110,7 @@ func ActionIcon(opType int) string { switch opType { case 1: // Create repository. return "plus-circle" - case 5: // Commit repository. + case 5, 9: // Commit repository. return "arrow-circle-o-right" case 6: // Create issue. return "exclamation-circle" @@ -127,6 +128,7 @@ const ( TPL_CREATE_ISSUE = `<a href="/user/%s">%s</a> opened issue <a href="/%s/issues/%s">%s#%s</a> <div><img src="%s?s=16" alt="user-avatar"/> %s</div>` TPL_TRANSFER_REPO = `<a href="/user/%s">%s</a> transfered repository <code>%s</code> to <a href="/%s">%s</a>` + TPL_PUSH_TAG = `<a href="/user/%s">%s</a> pushed tag <a href="/%s/src/%s">%s</a> at <a href="/%s">%s</a>` ) type PushCommit struct { @@ -174,6 +176,8 @@ func ActionDesc(act Actioner) string { case 8: // Transfer repository. newRepoLink := content + "/" + repoName return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink) + case 9: // Push tag. + return fmt.Sprintf(TPL_PUSH_TAG, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink) default: return "invalid type" } @@ -197,3 +201,19 @@ func DiffLineTypeToStr(diffType int) string { } return "same" } + +func Oauth2Icon(t int) string { + switch t { + case 1: + return "fa-github-square" + case 2: + return "fa-google-plus-square" + case 3: + return "fa-twitter-square" + case 4: + return "fa-linux" + case 5: + return "fa-weibo" + } + return "" +} |