Browse Source

refactor: minor refactoring of PR #10560

Torkel Ödegaard 8 years ago
parent
commit
dbfaf5dac8
2 changed files with 5 additions and 6 deletions
  1. 4 5
      pkg/api/login_oauth.go
  2. 1 1
      pkg/social/social.go

+ 4 - 5
pkg/api/login_oauth.go

@@ -29,7 +29,7 @@ var (
 	ErrSignUpNotAllowed      = errors.New("Signup is not allowed for this adapter")
 	ErrSignUpNotAllowed      = errors.New("Signup is not allowed for this adapter")
 	ErrUsersQuotaReached     = errors.New("Users quota reached")
 	ErrUsersQuotaReached     = errors.New("Users quota reached")
 	ErrNoEmail               = errors.New("Login provider didn't return an email address")
 	ErrNoEmail               = errors.New("Login provider didn't return an email address")
-	oauthLogger              = log.New("oauth.login")
+	oauthLogger              = log.New("oauth")
 )
 )
 
 
 func GenStateString() string {
 func GenStateString() string {
@@ -96,7 +96,7 @@ func OAuthLogin(ctx *middleware.Context) {
 	if setting.OAuthService.OAuthInfos[name].TlsClientCert != "" || setting.OAuthService.OAuthInfos[name].TlsClientKey != "" {
 	if setting.OAuthService.OAuthInfos[name].TlsClientCert != "" || setting.OAuthService.OAuthInfos[name].TlsClientKey != "" {
 		cert, err := tls.LoadX509KeyPair(setting.OAuthService.OAuthInfos[name].TlsClientCert, setting.OAuthService.OAuthInfos[name].TlsClientKey)
 		cert, err := tls.LoadX509KeyPair(setting.OAuthService.OAuthInfos[name].TlsClientCert, setting.OAuthService.OAuthInfos[name].TlsClientKey)
 		if err != nil {
 		if err != nil {
-			oauthLogger.Error("Failed to setup TlsClientCert", "oauth provider", name, "error", err)
+			ctx.Logger.Error("Failed to setup TlsClientCert", "oauth", name, "error", err)
 			ctx.Handle(500, "login.OAuthLogin(Failed to setup TlsClientCert)", nil)
 			ctx.Handle(500, "login.OAuthLogin(Failed to setup TlsClientCert)", nil)
 			return
 			return
 		}
 		}
@@ -107,7 +107,7 @@ func OAuthLogin(ctx *middleware.Context) {
 	if setting.OAuthService.OAuthInfos[name].TlsClientCa != "" {
 	if setting.OAuthService.OAuthInfos[name].TlsClientCa != "" {
 		caCert, err := ioutil.ReadFile(setting.OAuthService.OAuthInfos[name].TlsClientCa)
 		caCert, err := ioutil.ReadFile(setting.OAuthService.OAuthInfos[name].TlsClientCa)
 		if err != nil {
 		if err != nil {
-			oauthLogger.Error("Failed to setup TlsClientCa", "oauth provider", name, "error", err)
+			ctx.Logger.Error("Failed to setup TlsClientCa", "oauth", name, "error", err)
 			ctx.Handle(500, "login.OAuthLogin(Failed to setup TlsClientCa)", nil)
 			ctx.Handle(500, "login.OAuthLogin(Failed to setup TlsClientCa)", nil)
 			return
 			return
 		}
 		}
@@ -209,8 +209,7 @@ func OAuthLogin(ctx *middleware.Context) {
 }
 }
 
 
 func redirectWithError(ctx *middleware.Context, err error, v ...interface{}) {
 func redirectWithError(ctx *middleware.Context, err error, v ...interface{}) {
-	oauthLogger.Info(err.Error(), v...)
-	// TODO: we can use the flash storage here once it's implemented
+	ctx.Logger.Error(err.Error(), v...)
 	ctx.Session.Set("loginError", err.Error())
 	ctx.Session.Set("loginError", err.Error())
 	ctx.Redirect(setting.AppSubUrl + "/login")
 	ctx.Redirect(setting.AppSubUrl + "/login")
 }
 }

+ 1 - 1
pkg/social/social.go

@@ -97,7 +97,7 @@ func NewOAuthService() {
 			Scopes:      info.Scopes,
 			Scopes:      info.Scopes,
 		}
 		}
 
 
-		logger := log.New("oauth.login." + name)
+		logger := log.New("oauth." + name)
 
 
 		// GitHub.
 		// GitHub.
 		if name == "github" {
 		if name == "github" {