// saves the user id in session, save used data and access token in // db, creates the default folders func callback(w http.ResponseWriter, r *http.Request) { withSession(w, r, func(session *sessions.Session) { RequestToken := session.Values["RequestToken"].(dropbox.RequestToken) AccessToken, _ := dropbox.FinishAuth(config.AppToken, RequestToken) dbc := dropbox.NewClient(AccessToken, config.AppToken) info, err := dbc.GetAccountInfo() if err != nil { log.Println(err) } datastore.SaveUserData(info, AccessToken) session.Values["email"] = info.Email session.Save(r, w) dbc.CreateDir("drafts") dbc.CreateDir("published") http.Redirect(w, r, "/", 302) }) }
func handleCommands() { refresh := flag.Bool("refresh", false, "refresh articles for the provided email if present, otherwise refresh the default email") oauth := flag.Bool("oauth", false, "authorize oauth app from command line") flag.Parse() if *refresh { if len(flag.Args()) > 0 { refreshArticles(flag.Args()[0]) } else { refreshArticles(config.DefaultUserEmail) } os.Exit(1) } if *oauth { requestToken, _ := dropbox.StartAuth(config.AppToken) url, _ := url.Parse("") fmt.Println("open in a web browser the following url and authorize boxed app:") fmt.Println(dropbox.GetAuthorizeURL(requestToken, url)) fmt.Println("\n\npress enter when ready") reader := bufio.NewReader(os.Stdin) reader.ReadString('\n') accessToken, _ := dropbox.FinishAuth(config.AppToken, requestToken) dbc := dropbox.NewClient(accessToken, config.AppToken) info, err := dbc.GetAccountInfo() if err != nil { fmt.Println(err) } else { fmt.Printf("authorized: %s %s\n", info.DisplayName, info.Email) datastore.SaveUserData(info, accessToken) dbc.CreateDir("drafts") dbc.CreateDir("published") dbc.CreateDir("images") } os.Exit(1) } }