Esempio n. 1
0
func Test_GetUserEmailByUID(t *testing.T) {
	a := assert.New(t)
	info := &dropbox.AccountInfo{
		Email:       "*****@*****.**",
		Uid:         1234,
		DisplayName: "pippo",
	}
	token := dropbox.AccessToken{Key: "a", Secret: "b"}
	datastore.SaveUserData(info, token)

	email, _ := datastore.GetUserEmailByUID(1234)
	a.Equal(email, "*****@*****.**")

	_, err := datastore.GetUserEmailByUID(1)
	a.NotEqual(err, nil)
}
Esempio n. 2
0
// 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)
	})
}
Esempio n. 3
0
func Test_SaveUserData(t *testing.T) {
	a := assert.New(t)
	info := &dropbox.AccountInfo{
		Email:       "*****@*****.**",
		Uid:         1234,
		DisplayName: "pippo",
	}
	token := dropbox.AccessToken{Key: "a", Secret: "b"}
	datastore.SaveUserData(info, token)

	at, _ := datastore.LoadUserToken("*****@*****.**")
	a.Equal(at, token)

	at, _ = datastore.LoadUserTokenByUID(1234)
	a.Equal(at, token)

	userData, _ := datastore.LoadUserData("*****@*****.**")
	a.Equal(userData, info)
}
Esempio n. 4
0
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)
	}

}