Exemple #1
0
//PostOnFacebook creates new post on facebook page wall
func PostOnFacebook(link, message string) error {
	//see http://stackoverflow.com/questions/17197970/facebook-permanent-page-access-token
	//for info on obtaining upexpirable page access token
	//also https://developers.facebook.com/docs/graph-api/reference/v2.5/page/feed for api description

	token := &oauth2.Token{
		AccessToken: shared.GetConfig().Oauth.Facebook.Token, //page access token
	}
	client := fbConfig().Client(oauth2.NoContext, token)
	response, err := client.Post(
		fmt.Sprintf(
			"https://graph.facebook.com/v2.5/%s/feed?access_token=%s&link=%s&message=%s",
			shared.GetConfig().Oauth.Facebook.Page,
			token.AccessToken,
			url.QueryEscape(link),
			url.QueryEscape(message),
		),
		"application/json",
		nil,
	)
	if err != nil {
		return err
	}
	body, _ := ioutil.ReadAll(response.Body)
	response.Body.Close()
	if response.StatusCode != 200 {
		err := fmt.Errorf("ERROR: while posting on facebook: %s\n", body)
		return err
	}
	return nil
}
Exemple #2
0
func vkConfig() *oauth2.Config {
	return &oauth2.Config{
		ClientID:     shared.GetConfig().Oauth.Vk.ClientID,
		ClientSecret: shared.GetConfig().Oauth.Vk.ClientSecret,
		RedirectURL:  shared.GetConfig().Oauth.Vk.RedirectURL,
		Scopes:       []string{"email"},
		Endpoint:     vk.Endpoint,
	}
}
Exemple #3
0
//google config
func goConfig() *oauth2.Config {
	return &oauth2.Config{
		ClientID:     shared.GetConfig().Oauth.Google.ClientID,
		ClientSecret: shared.GetConfig().Oauth.Google.ClientSecret,
		RedirectURL:  shared.GetConfig().Oauth.Google.RedirectURL,
		Scopes:       []string{goauth2.PlusLoginScope, goauth2.PlusMeScope, goauth2.UserinfoEmailScope, goauth2.UserinfoProfileScope},
		Endpoint:     google.Endpoint,
	}
}
Exemple #4
0
//facebook config
func fbConfig() *oauth2.Config {
	return &oauth2.Config{
		ClientID:     shared.GetConfig().Oauth.Facebook.ClientID,
		ClientSecret: shared.GetConfig().Oauth.Facebook.ClientSecret,
		RedirectURL:  shared.GetConfig().Oauth.Facebook.RedirectURL,
		Scopes:       []string{"email", "user_about_me"},
		Endpoint:     facebook.Endpoint,
	}
}
Exemple #5
0
func inConfig() *oauth2.Config {
	return &oauth2.Config{
		ClientID:     shared.GetConfig().Oauth.Linkedin.ClientID,
		ClientSecret: shared.GetConfig().Oauth.Linkedin.ClientSecret,
		RedirectURL:  shared.GetConfig().Oauth.Linkedin.RedirectURL,
		Scopes:       []string{"r_basicprofile", "r_emailaddress"},
		Endpoint:     linkedin.Endpoint,
	}
}
Exemple #6
0
//RssXML handles GET /rss route
func RssXML(w http.ResponseWriter, r *http.Request) {
	tmpl := shared.Template(r)
	if r.Method == "GET" {

		now := time.Now()
		domain := shared.GetConfig().Domain
		feed := &feeds.Feed{
			Title:       "Blog boilerplate",
			Link:        &feeds.Link{Href: domain},
			Description: "Basic blog boilerplate in Go",
			Author:      &feeds.Author{Name: "Blog Author"},
			Created:     now,
			Copyright:   fmt.Sprintf("© %s", "Blog"),
		}

		feed.Items = make([]*feeds.Item, 0)
		posts, err := models.GetPublishedPosts()
		if err != nil {
			log.Printf("ERROR: %s\n", err)
			w.WriteHeader(500)
			tmpl.Lookup("errors/500").Execute(w, shared.ErrorData(err))
			return
		}
		for i := range posts {
			feed.Items = append(feed.Items, &feeds.Item{
				Id:          fmt.Sprintf("%s/posts/%d", domain, posts[i].ID),
				Title:       posts[i].Name,
				Link:        &feeds.Link{Href: fmt.Sprintf("%s/posts/%d", domain, posts[i].ID)},
				Description: string(posts[i].Excerpt()),
				Author:      &feeds.Author{Name: posts[i].Author.Name},
				Created:     now,
			})
		}

		rss, err := feed.ToRss()
		if err != nil {
			log.Printf("ERROR: %s\n", err)
			w.WriteHeader(500)
			tmpl.Lookup("errors/500").Execute(w, shared.ErrorData(err))
			return
		}
		fmt.Fprintln(w, rss)

	} else {
		err := fmt.Errorf("Method %q not allowed", r.Method)
		log.Printf("ERROR: %s\n", err)
		w.WriteHeader(405)
		tmpl.Lookup("errors/405").Execute(w, shared.ErrorData(err))
	}
}
Exemple #7
0
func Init() {
	shared.InitCsrf()

	http.Handle("/", shared.Default(controllers.Home))

	if shared.GetConfig().SignupEnabled {
		http.Handle("/signup", shared.Default(controllers.SignUp))
	}
	http.Handle("/signin", shared.Default(controllers.SignIn))
	http.Handle("/logout", shared.Default(controllers.Logout))

	http.Handle("/pages/", shared.Default(controllers.PageShow))
	http.Handle("/posts/", shared.Default(controllers.PostShow))
	http.Handle("/tags/", shared.Default(controllers.TagShow))
	http.Handle("/archives/", shared.Default(controllers.ArchiveShow))
	http.Handle("/rss", shared.Default(controllers.RssXML))
	http.Handle("/search", shared.Default(controllers.Search))
	http.Handle("/new_comment", shared.Default(controllers.CommentCreate))

	//comment oauth login
	http.Handle("/facebook_login", shared.Default(oauth.FacebookLogin))
	http.Handle("/facebook_callback", shared.Default(oauth.FacebookCallback))
	http.Handle("/google_login", shared.Default(oauth.GoogleLogin))
	http.Handle("/google_callback", shared.Default(oauth.GoogleCallback))
	http.Handle("/linkedin_login", shared.Default(oauth.LinkedinLogin))
	http.Handle("/linkedin_callback", shared.Default(oauth.LinkedinCallback))
	http.Handle("/vk_login", shared.Default(oauth.VkLogin))
	http.Handle("/vk_callback", shared.Default(oauth.VkCallback))

	{
		http.Handle("/admin", shared.Restricted(controllers.Dashboard))

		http.Handle("/admin/users", shared.Restricted(controllers.UserIndex))
		http.Handle("/admin/new_user", shared.Restricted(controllers.UserCreate))
		http.Handle("/admin/edit_user/", shared.Restricted(controllers.UserUpdate))
		http.Handle("/admin/delete_user", shared.Restricted(controllers.UserDelete))

		http.Handle("/admin/pages", shared.Restricted(controllers.PageIndex))
		http.Handle("/admin/new_page", shared.Restricted(controllers.PageCreate))
		http.Handle("/admin/edit_page/", shared.Restricted(controllers.PageUpdate))
		http.Handle("/admin/delete_page", shared.Restricted(controllers.PageDelete))

		http.Handle("/admin/posts", shared.Restricted(controllers.PostIndex))
		http.Handle("/admin/new_post", shared.Restricted(controllers.PostCreate))
		http.Handle("/admin/edit_post/", shared.Restricted(controllers.PostUpdate))
		http.Handle("/admin/delete_post", shared.Restricted(controllers.PostDelete))
		http.Handle("/admin/post_on_facebook", shared.RestrictedWithoutCSRF(controllers.PostOnFacebook))

		http.Handle("/admin/tags", shared.Restricted(controllers.TagIndex))
		http.Handle("/admin/new_tag", shared.Restricted(controllers.TagCreate))
		http.Handle("/admin/delete_tag", shared.Restricted(controllers.TagDelete))

		http.Handle("/admin/comments", shared.Restricted(controllers.CommentIndex))
		http.Handle("/admin/new_comment", shared.Restricted(controllers.CommentReply))
		http.Handle("/admin/edit_comment/", shared.Restricted(controllers.CommentUpdate))
		http.Handle("/admin/delete_comment", shared.Restricted(controllers.CommentDelete))

		//markdown editor does not support csrf when uploading images, so I have to apply CSRF middleware manually per route, sigh :/
		http.Handle("/admin/upload", shared.RestrictedWithoutCSRF(controllers.Upload))
	}

	http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("static/public")))) //styles, js, images
}