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