Selaa lähdekoodia

Update oauth2.go

AY 4 vuotta sitten
vanhempi
commit
53fc5d9649
1 muutettua tiedostoa jossa 6 lisäystä ja 3 poistoa
  1. 6 3
      mod/auth/oauth2/oauth2.go

+ 6 - 3
mod/auth/oauth2/oauth2.go

@@ -63,12 +63,12 @@ func NewOauthHandler(authAgent *auth.AuthAgent, register *reg.RegisterHandler, c
 //HandleOauthLogin xxx
 func (oh *OauthHandler) HandleLogin(w http.ResponseWriter, r *http.Request) {
 	//add cookies
-	redirect, err := r.URL.Query()["redirect"]
+	redirect, err := mv(r, "redirect", false)
 	uuid := ""
-	if !err || len(redirect[0]) < 1 {
+	if err != nil {
 		uuid = oh.syncDb.Store("/")
 	} else {
-		uuid = oh.syncDb.Store(redirect[0])
+		uuid = oh.syncDb.Store(redirect)
 	}
 	oh.addCookie(w, "uuid_login", uuid, 30*time.Minute)
 	//handle redirect
@@ -109,6 +109,7 @@ func (oh *OauthHandler) HandleAuthorize(w http.ResponseWriter, r *http.Request)
 
 	username, err := getUserInfo(token.AccessToken, oh.coredb)
 	if err != nil {
+		oh.ag.Logger.LogAuth(r, false)
 		sendTextResponse(w, "Failed to obtain user info.")
 		return
 	}
@@ -119,11 +120,13 @@ func (oh *OauthHandler) HandleAuthorize(w http.ResponseWriter, r *http.Request)
 		if oh.reg.AllowRegistry {
 			http.Redirect(w, r, "/public/register/register.system?user="+username, 302)
 		} else {
+			oh.ag.Logger.LogAuth(r, false)
 			sendHTMLResponse(w, "You are not allowed to register in this system.&nbsp;<a href=\"/\">Back</a>")
 		}
 	} else {
 		log.Println(username + " logged in via OAuth.")
 		oh.ag.LoginUserByRequest(w, r, username, true)
+		oh.ag.Logger.LogAuth(r, true)
 		//clear the cooke
 		oh.addCookie(w, "uuid_login", "-invaild-", -1)
 		//read the value from db and delete it from db