README.md in dailycred-0.1.2 vs README.md in dailycred-0.1.4
- old
+ new
@@ -1,76 +1,202 @@
# Dailycred
-## Installation
+## Introduction
-Add this line to your application's Gemfile:
+The Dailycred ruby gem is everything you need to get off the ground running with robust authentication. It includes an [omniauth](https://github.com/intridea/omniauth) provider and a generator to create necessary models and controllers. The generated authentication structure is inspired by [nifty-generators](https://github.com/ryanb/nifty-generators). To get started using Dailycred with Ruby on Rails, the first thing you need to do is add the dailycred gem to your gemfile:
-And then execute:
+ gem 'dailycred'
- $ bundle
+Make sure you've signed up for Dailycred, and head over to your [settings](https://www.dailycred.com/admin/settings) page to get your API keys. Once you've done that, head back to the command line and run:
-Or install it yourself as:
+ bundle
+ rails g dailycred
+ rake db:migrate
- $ gem install omniauth-dailycred
+Thats it! You've successfully added authentication to your app, and you can start signing up users. Run `rails s` to start your
+ server, and point your browser to [http://localhost:3000/auth](http://localhost:3000/auth) and you'll see a pre-built page with links to sign up.
-## Usage
+Here's what the dailycred gem generates for you:
-bash
+* A few helper methods to `/app/controllers/application_controller.rb`.
+* An initializer file at `/config/initializers/omniauth.rb` which configures your dailycred API keys.
+* `/app/models/user.rb`, the User model.
+* A migration file to create the user table in your database.
+
+
+While this is enough to get off the ground running with user authentication, this setup is meant to be lightweight and flexible, so feel free to tinker with
+ any of the generated code to better match your needs.
+
+## Authenticating
+
+#### login_path
+
+A helper for linking to the authentication url.
+
+ <%= link_to 'sign up', login_path %>
+ # => <a href="/auth/dailycred">sign up</a>
+
+#### logout_path
+
+To logout a user, simply send them to `/auth/logout`.
+
+ <%= link_to 'logout', logout_path %>
+ # => <a href="/auth/logout">logout</a>
- rails g dailycred YOUR_CLIENT_ID YOUR_SECRET_KEY
- rake db:migrate
+#### authenticate
-This will generate everything you need to get going with authentication, including a user model, session controller, omniauth initializer, javascript tracking code, and many helper variables. You will You can locate your API keys at [dailycred](https://www.dailycred.com/admin/settings/keys)
+To protect a controller method from unauthorized users, use the 'authorize' helper method as a `before_filter`.
-##### Authentication
+ #before_filter :authenticate, :except => [:index] #don't authenticate some
+ #before_filter :authenticate, :only => [:create, :new] #only authenticate some
+ before_filter :authenticate #all methods
-Use the `:authenticate` helper to require a user to be signed in:
+## Social Connect
- before_filter :authenticate
+To use a social sign-in service instead of email, and password, use `connect_path.`
-The current user object can be located with `current_user`:
+ <%= link_to 'sign in with facebook', connect_path(:identity_provider => :facebook) %>
- # in posts_controller
+The `identity_provider` can be one of `facebook`, `google`, or `twitter.`
- @posts = currrent_user.posts.all
+After a user has social connected, their social data is serialized into individual fields in the user model. The serialized object is the exact same as what the social provider's graph response returns. For example:
-##### Using only with Omniauth
+ p current_user.facebook
+ # =>
+ {
+ "video_upload_limits" => {
+ "length" => 1200.0,
+ "size" => 1073741824.0
+ },
+ "locale" => "en_US",
+ "link" => "http://www.facebook.com/joe.smith",
+ "updated_time" => "2012-09-27T19:04:38+0000",
+ "currency" => {
+ "user_currency" => "USD",
+ "currency_exchange" => 10.0,
+ "currency_exchange_inverse" => 0.1,
+ "currency_offset" => 100.0
+ },
+ "picture" => {
+ "data" => {
+ "url" => "http://profile.ak.fbcdn.net/hprofile-ak-ash4/370570_1039690812_2022945351_q.jpg",
+ "is_silhouette" => false
+ }
+ },
+ "id" => "1092609812",
+ "third_party_id" => "cBLDKnqlfYlReV7Jo4yRAFB1a4I",
+ "first_name" => "Joe",
+ "username" => "jsmitty",
+ "bio" => "shred the gnar.",
+ "email" => "jsmitty@dailycred.com",
+ "verified" => true,
+ "name" => "Joe Smith",
+ "last_name" => "Stoever",
+ "gender" => "male",
+ "access_token" =>"AAAFHsZAi9ddUBAKPMOKPDrmJlclwCoVHCfwflF5ZCyLZC70SOo0MPvj62lhHZAnV6jk8DEfBSjLtfcyC7Bx25a9CLphzoayv3EtvbE2tAQZDZD"
+ }
-If you already have omniauth set up and only want to use Dailycred as another OAuth provider, just add this line to your omniauth initializer file
+You can also connect additional social accounts to an existing user:
- provider :dailycred, 'CLIENT_ID', 'SECRET_KEY'
+ <%= link_to 'connect with facebook', connect_user(:facebook) %>
-##### Events
+`connect_user` defaults to connecting the `current_user`, but you can explicitly connect any user:
-To fire an event to be logged in Dailycred:
+ <%= link_to 'connect with google', connect_user(:google, @user) %>
- #in your controller
+---
+##Helpers
+
+There are a few other helper methods available:
+
+#### current_user
+
+Returns the current logged in user or nil. Example usage:
+
+ if !current_user.nil?
+ redirect_to :controller => 'welcome', :action => 'thanks'
+ end
+
+#### dailycred
+
+A helper for instantiating a dailycred client instance. Use as a `before_filter` to load a @dailycred instance variable, or just use it as a helper method. Example usage:
+
+As a before filter:
+
before_filter :dailycred
- def create
- ...
+ def index
+ @dailycred.event(current_user.uid, "New Task", @task.name)
+ end
- # after successfully saving the model:
- @dailycred.event(current_user.uid, 'Created Post', @post.name)
+or just as a helper
+ def index
+ dailycred.event(current_user.uid, "New Task", @task.name)
end
-## SSL Error
+#### Tagging a User
-You may get an error such as the following:
+Dailycred provides the ability to 'tag' users, whether for reference in analytics or any other reason. Note that this is a very simple 'tagging' system, and not something you should use for dynamic tagging situations in your application.
- Faraday::Error::ConnectionFailed (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed):
+ @user.tag 'awesome'
+ @user.untag 'awesome'
-If that is the case, consider following fixes explained [here](https://github.com/technoweenie/faraday/wiki/Setting-up-SSL-certificates) or [here](http://martinottenwaelter.fr/2010/12/ruby19-and-the-ssl-error).
+#### Firing Events
+You can also fire events tied to a specific user - this is helpful for goal tracking and tying actions to a specific user in analytics. We already fire many events for when a user signs up, resets a password, and much more, but you can also use the event system for something more specific for your application.
+
+ # user#fire_event(key, value)
+ @user.fire_event 'task added', @task.name
+
+#### Building Referral URLs
+
+To easily build referral URLs to track sharing amongst your users, use `referral_link(my_site)`, where *my_site* is the url that you wish referred users to be sent to.
+
+ current_user.referral_link("http://www.mysite.com")
+
+#### Testing Controllers
+
+Testing controllers that have the `authenticate` before filter is easy:
+
+ # with mocha
+ @controller.expects(:current_user).returns(@user)
+
+See `dummy/test/functional/post_controller_test.rb` for an example.
+
+#### Dailycred API
+
+For reference, have a look at the [annotated source code.](https://www.dailycred.com/public/docs/ruby/lib/dailycred.html)
+
+For all API calls, you must first initalize a Dailycred client:
+
+ @dailycred = Dailycred.new "YOUR_CLIENT_ID", "your_secret_key", opts
+
+Where opts is an optional hash for passing options. After initializing your client, you can create events as well as tag and untag users:
+
+ @dailycred.event(current_user.uid, "New Task", @task.name) # user_id, key, value
+ @dailycred.tag(current_user.uid, "Failed Checkout") # user_id, key
+ @dailycred.untag(current_user.uid, "Failed Checkout") # user_id, key
+
+
+#### Configuration
+
+To specify where users should be redirected after authentication actions, setup configure an `after_auth` property on a `Rails.configuration.DAILYCRED_OPTIONS` variable. Example:
+
+ # configure where users should be redirected after authentication
+ #
+ # Rails.configuration.DAILYCRED_OPTIONS = {
+ # :after_auth => '/hello', #after login
+ # :after_unauth => '/goodbye' #after logout
+ # }
+
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
-omniauth-dailycred
+![](https://www.dailycred.com/dc.gif?client_id=dailycred&title=rails_repo "dailycred")
-OmniAuth adapter for dailycred using their OAuth2 Strategy