//检查申请资源是否被授权,如有有未授权的资源,则返回授权页 func checkAuthorize(oauth *OAuth, w http.ResponseWriter, r *http.Request, acname string) bool { sliceRes := []Res{} strRes := "" queryForm := common.GetUrlParam(r) arrScope := strings.Split(queryForm["scope"][0], ",") clientId := queryForm["client_id"][0] if acname == "" { acname = GetCookieName(r) } openId := GetOpenIdByacName(acname, clientId) for i := 0; i < len(arrScope); i++ { resId := GetResId(arrScope[i]) if resId > 0 { if !IsPersonConfered(clientId, openId, resId) { resCname := GetResCname(arrScope[i]) res := Res{Resname: arrScope[i], Rescname: resCname} sliceRes = append(sliceRes, res) } else { if strRes == "" { strRes += arrScope[i] } else { strRes += "," + arrScope[i] } } } } if len(sliceRes) > 0 { requestURI := "/oauth2/authorize?response_type=" + queryForm["response_type"][0] + "&client_id=" + queryForm["client_id"][0] + "&redirect_uri=" + queryForm["redirect_uri"][0] + "&state=" + queryForm["state"][0] common.ForwardPage(w, "./static/public/oauth2/oauth.html", map[string]interface{}{"RequestURI": requestURI, "sliceRes": sliceRes, "strRes": strRes}) return false } return true }
//检查是否登录,未登录,则返回登录页 func checkLogin(oauth *OAuth, w http.ResponseWriter, r *http.Request) bool { fmt.Println("checkLogin\r\n") acname := GetCookieName(r) fmt.Println("checkLogin acname", acname) if acname == "" { common.ForwardPage(w, "./static/public/oauth2/login.html", map[string]string{"RequestURI": "/oauth2/login?" + r.URL.RawQuery}) return false } return true }