示例#1
0
func (gh *GitHub) GetUser() *user.User {
	client := gh.Config.Client(oauth2.NoContext, gh.Token)
	test, _ := client.Get("https://api.github.com/user")
	u := new(user.User)
	json.NewDecoder(test.Body).Decode(u)
	u.Type = "github"
	return u

}
示例#2
0
// Validate admin has admin role.
func validateAdmin(w *wrapper.Wrapper) bool {
	user := new(user.User)
	err := user.Get(w)
	loginurls := make(map[string]string)
	w.SiteConfig.RawConfig.MarshalKey("LoginURLs", &loginurls)
	if err != nil {
		services.Redirect(loginurls["login"], w)
		w.Serve()
		return false
	}
	if user.Roles != nil {
		for _, r := range user.Roles {
			if r == "admin" {
				return true
			}
		}
	}
	services.Redirect(loginurls["access_denied"], w)
	w.Serve()
	return false
}