mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 12:22:11 +00:00
Fix issue with log in with GitHub but need more error handle after
This commit is contained in:
parent
05fb34eacd
commit
9ea9818d32
13 changed files with 167 additions and 60 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue