Exemple #1
0
// Performs validation and combines errors from validation
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(obj reflect.Value, context martini.Context, errors *base.BindingErrors, ifacePtr ...interface{}) {
	context.Invoke(Validate(obj.Interface()))
	errors.Combine(getErrors(context))
	context.Map(*errors)
	context.Map(obj.Elem().Interface())
	if len(ifacePtr) > 0 {
		context.MapTo(obj.Elem().Interface(), ifacePtr[0])
	}
}
Exemple #2
0
// Performs validation and combines errors from validation
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(obj reflect.Value, context martini.Context, errors Errors, ifacePtr ...interface{}) {
	context.Invoke(Validate(obj.Interface()))
	errors = append(errors, getErrors(context)...)
	context.Map(errors)
	context.Map(obj.Elem().Interface())
	if len(ifacePtr) > 0 {
		context.MapTo(obj.Elem().Interface(), ifacePtr[0])
	}
}
Exemple #3
0
func logoutHandle(f *Config, c martini.Context, s sessions.Session, w http.ResponseWriter, r *http.Request) {
	s.Delete(keyToken)
	path := fmt.Sprintf("%s?client_id=%s&client_secret=%s", f.Endpoint.LogoutURL, f.ClientID, f.ClientSecret)
	utils.HttpGetString(path)
	//	fmt.Println("oauth logout result:",string(str))
	f.ClientID = ""
	f.ClientSecret = ""
	c.Invoke(Logout)
	http.Redirect(w, r, "/", 302)
}
Exemple #4
0
func callNormalizeBinding(val reflect.Value, context martini.Context) (interface{}, error) {
	obj := val.Interface()
	if m := val.MethodByName("NormalizeBinding"); m.IsValid() {
		results, err := context.Invoke(m.Interface())
		if err != nil {
			return nil, err
		}
		if len(results) > 0 {
			obj = results[0].Interface()
		}
	}
	return obj, nil
}
Exemple #5
0
// Performs validation and combines errors from validation
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(val reflect.Value, context martini.Context, errors *Errors, ifacePtr ...interface{}) {
	context.Invoke(Validate(val.Interface()))
	context.Map(errors)
	target, _ := normalize(val, context)
	if target == nil {
		panic("binding: wrong return nil value")
	}
	context.Map(target)
	if len(ifacePtr) > 0 {
		for index, _ := range ifacePtr {
			context.MapTo(target, ifacePtr[index])
		}
	}
}
Exemple #6
0
func callbackhandle(f *Config, c martini.Context, s sessions.Session, w http.ResponseWriter, r *http.Request) {
	rurl, _ := s.Get("_RedirectURL").(string)
	rurl = extractPath(rurl)
	if len(r.URL.Query().Get("code")) > 0 {
		//获取token
		tk, error := f.authTokenURL(r.URL.Query().Get("code"))

		if error == nil && tk.Valid() {
			val, _ := json.Marshal(tk)
			s.Set(keyToken, val)
			fmt.Println("登陆成功")
			s.AddFlash("登陆成功")
			c.Invoke(oAuthUserLoginCallback)
			if len(rurl) == 0 {
				rurl = "/"
			}
			fmt.Println("rul:", rurl)
			http.Redirect(w, r, rurl, 302)
			return
		} else {
			s.AddFlash("登陆失败")
			http.Redirect(w, r, PathError, 302)
			return
		}
	}
	if len(r.URL.Query().Get("client_id")) > 0 {
		f.ClientID = r.URL.Query().Get("client_id")
		f.ClientSecret = r.URL.Query().Get("client_secret")
		http.Redirect(w, r, f.authCodeURL(), 302)
		return
	}

	//	fmt.Println("call:",r)
	//	if (len(r.URL.Query().Get("code"))>0) {
	//		fmt.Println("callFUN:q token")
	//		rurl,_:=  s.Get("_RedirectURL").(string)
	//		//获取token
	//		tk, error := f.authTokenURL(r.URL.Query().Get("code"))
	//		if error==nil && tk.Valid() {
	//			val, _ := json.Marshal(tk)
	//			s.Set(keyToken, val)
	//			s.AddFlash("success","登陆成功")
	//			c.Invoke(oAuthUserLogin)
	//
	//
	//			 http.RedirectHandler(rurl, 302)
	//		 	 return
	//		}else{
	//			s.AddFlash("warning","登陆失败")
	//			http.Redirect(w, r, PathError, 302)
	//			return
	//		}
	//	}else{
	//		fmt.Println("callFUN:1111")
	//		//获取code
	//		if len(r.URL.Query().Get("client_id"))>0 {
	//			fmt.Println("callFUN:q code")
	//			f.ClientID = r.URL.Query().Get("client_id")
	//			f.ClientSecret = r.URL.Query().Get("client_secret")
	//			http.Redirect(w, r, f.authCodeURL(), 302)
	//			return
	//		}
	//		http.Redirect(w, r, "/", 302)
	//	}
	//	fmt.Println("callFUN:sppp")
}