Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 1b98335cc7b6a9514b13adbdf61035750e8b873b @binarylogic binarylogic committed Oct 24, 2008
Showing with 9,678 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +20 −0 MIT-LICENSE
  3. +85 −0 Manifest
  4. +164 −0 README.rdoc
  5. +15 −0 Rakefile
  6. +2 −0 init.rb
  7. +18 −0 lib/authgasm.rb
  8. +200 −0 lib/authgasm/acts_as_authentic.rb
  9. +16 −0 lib/authgasm/controller.rb
  10. +30 −0 lib/authgasm/session/active_record_trickery.rb
  11. +365 −0 lib/authgasm/session/base.rb
  12. +47 −0 lib/authgasm/session/callbacks.rb
  13. +193 −0 lib/authgasm/session/config.rb
  14. +12 −0 lib/authgasm/session/errors.rb
  15. +13 −0 lib/authgasm/sha256_crypto_provider.rb
  16. +56 −0 lib/authgasm/version.rb
  17. +10 −0 test_app/.gitignore
  18. +256 −0 test_app/README
  19. +10 −0 test_app/Rakefile
  20. +46 −0 test_app/app/controllers/application.rb
  21. +25 −0 test_app/app/controllers/user_sessions_controller.rb
  22. +37 −0 test_app/app/controllers/users_controller.rb
  23. +3 −0 test_app/app/helpers/application_helper.rb
  24. +2 −0 test_app/app/helpers/user_sessions_helper.rb
  25. +2 −0 test_app/app/helpers/users_helper.rb
  26. +3 −0 test_app/app/models/user.rb
  27. +3 −0 test_app/app/models/user_session.rb
  28. +12 −0 test_app/app/views/asses/edit.html.erb
  29. +18 −0 test_app/app/views/asses/index.html.erb
  30. +11 −0 test_app/app/views/asses/new.html.erb
  31. +3 −0 test_app/app/views/asses/show.html.erb
  32. +25 −0 test_app/app/views/layouts/application.html.erb
  33. +13 −0 test_app/app/views/user_sessions/new.html.erb
  34. +15 −0 test_app/app/views/users/_form.erb
  35. +8 −0 test_app/app/views/users/edit.html.erb
  36. +8 −0 test_app/app/views/users/new.html.erb
  37. +19 −0 test_app/app/views/users/show.html.erb
  38. +109 −0 test_app/config/boot.rb
  39. +69 −0 test_app/config/environment.rb
  40. +17 −0 test_app/config/environments/development.rb
  41. +22 −0 test_app/config/environments/production.rb
  42. +22 −0 test_app/config/environments/test.rb
  43. +10 −0 test_app/config/initializers/inflections.rb
  44. +5 −0 test_app/config/initializers/mime_types.rb
  45. +17 −0 test_app/config/initializers/new_rails_defaults.rb
  46. +7 −0 test_app/config/routes.rb
  47. BIN test_app/db/development.sqlite3
  48. +17 −0 test_app/db/migrate/20081023040052_create_users.rb
  49. BIN test_app/db/test.sqlite3
  50. +2 −0 test_app/doc/README_FOR_APP
  51. +30 −0 test_app/public/404.html
  52. +30 −0 test_app/public/422.html
  53. +30 −0 test_app/public/500.html
  54. +10 −0 test_app/public/dispatch.cgi
  55. +24 −0 test_app/public/dispatch.fcgi
  56. +10 −0 test_app/public/dispatch.rb
  57. 0 test_app/public/favicon.ico
  58. BIN test_app/public/images/rails.png
  59. +2 −0 test_app/public/javascripts/application.js
  60. +963 −0 test_app/public/javascripts/controls.js
  61. +972 −0 test_app/public/javascripts/dragdrop.js
  62. +1,120 −0 test_app/public/javascripts/effects.js
  63. +4,225 −0 test_app/public/javascripts/prototype.js
  64. +5 −0 test_app/public/robots.txt
  65. +62 −0 test_app/public/stylesheets/scaffold.css
  66. +4 −0 test_app/script/about
  67. +3 −0 test_app/script/console
  68. +3 −0 test_app/script/dbconsole
  69. +3 −0 test_app/script/destroy
  70. +3 −0 test_app/script/generate
  71. +3 −0 test_app/script/performance/benchmarker
  72. +3 −0 test_app/script/performance/profiler
  73. +3 −0 test_app/script/performance/request
  74. +3 −0 test_app/script/plugin
  75. +3 −0 test_app/script/process/inspector
  76. +3 −0 test_app/script/process/reaper
  77. +3 −0 test_app/script/process/spawner
  78. +3 −0 test_app/script/runner
  79. +3 −0 test_app/script/server
  80. +6 −0 test_app/test/fixtures/users.yml
  81. +15 −0 test_app/test/functional/user_sessions_controller_test.rb
  82. +8 −0 test_app/test/functional/users_controller_test.rb
  83. +38 −0 test_app/test/test_helper.rb
  84. +8 −0 test_app/test/unit/ass_test.rb
  85. +8 −0 test_app/test/unit/user_test.rb
@@ -0,0 +1,7 @@
+.DS_Store
+*.log
+pkg/*
+coverage/*
+doc/*
+benchmarks/*
+
@@ -0,0 +1,20 @@
+Copyright (c) 2007 Ben Johnson of Binary Logic (binarylogic.com)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,85 @@
+init.rb
+lib/authgasm/acts_as_authentic.rb
+lib/authgasm/controller.rb
+lib/authgasm/session/active_record_trickery.rb
+lib/authgasm/session/base.rb
+lib/authgasm/session/callbacks.rb
+lib/authgasm/session/config.rb
+lib/authgasm/session/errors.rb
+lib/authgasm/sha256_crypto_provider.rb
+lib/authgasm/version.rb
+lib/authgasm.rb
+Manifest
+MIT-LICENSE
+Rakefile
+README.rdoc
+test_app/app/controllers/application.rb
+test_app/app/controllers/user_sessions_controller.rb
+test_app/app/controllers/users_controller.rb
+test_app/app/helpers/application_helper.rb
+test_app/app/helpers/user_sessions_helper.rb
+test_app/app/helpers/users_helper.rb
+test_app/app/models/user.rb
+test_app/app/models/user_session.rb
+test_app/app/views/asses/edit.html.erb
+test_app/app/views/asses/index.html.erb
+test_app/app/views/asses/new.html.erb
+test_app/app/views/asses/show.html.erb
+test_app/app/views/layouts/application.html.erb
+test_app/app/views/user_sessions/new.html.erb
+test_app/app/views/users/_form.erb
+test_app/app/views/users/edit.html.erb
+test_app/app/views/users/new.html.erb
+test_app/app/views/users/show.html.erb
+test_app/config/boot.rb
+test_app/config/database.yml
+test_app/config/environment.rb
+test_app/config/environments/development.rb
+test_app/config/environments/production.rb
+test_app/config/environments/test.rb
+test_app/config/initializers/inflections.rb
+test_app/config/initializers/mime_types.rb
+test_app/config/initializers/new_rails_defaults.rb
+test_app/config/routes.rb
+test_app/db/development.sqlite3
+test_app/db/migrate/20081023040052_create_users.rb
+test_app/db/schema.rb
+test_app/db/test.sqlite3
+test_app/doc/README_FOR_APP
+test_app/public/404.html
+test_app/public/422.html
+test_app/public/500.html
+test_app/public/dispatch.cgi
+test_app/public/dispatch.fcgi
+test_app/public/dispatch.rb
+test_app/public/favicon.ico
+test_app/public/images/rails.png
+test_app/public/javascripts/application.js
+test_app/public/javascripts/controls.js
+test_app/public/javascripts/dragdrop.js
+test_app/public/javascripts/effects.js
+test_app/public/javascripts/prototype.js
+test_app/public/robots.txt
+test_app/public/stylesheets/scaffold.css
+test_app/Rakefile
+test_app/README
+test_app/script/about
+test_app/script/console
+test_app/script/dbconsole
+test_app/script/destroy
+test_app/script/generate
+test_app/script/performance/benchmarker
+test_app/script/performance/profiler
+test_app/script/performance/request
+test_app/script/plugin
+test_app/script/process/inspector
+test_app/script/process/reaper
+test_app/script/process/spawner
+test_app/script/runner
+test_app/script/server
+test_app/test/fixtures/users.yml
+test_app/test/functional/user_sessions_controller_test.rb
+test_app/test/functional/users_controller_test.rb
+test_app/test/test_helper.rb
+test_app/test/unit/ass_test.rb
+test_app/test/unit/user_test.rb
@@ -0,0 +1,164 @@
+= Authgasm
+
+Authgasm is "RESTful rails authentication done right"
+
+The last thing we need is another authentication solution for rails, right? That's what I thought. It was disappointing to find that all of the solutions were overly complicated, bloated, made too many assumptions about my app, written poorly, or were just plain confusing. I wanted something simple. Something that feels like it is a part of rails. Something that I could understand and not feel like authentication is this daunting / annoying task that litters my application with redundant code. So I decided to scratch my own itch by creating Authgasm.
+
+Wouldn't it be nice if we could do something like:
+
+ class UserSessionsController < ApplicationController
+ def new
+ @user_session = UserSession.new
+ end
+
+ def create
+ @user_session = UserSession.new(params[:user_session])
+ if @user_session.create
+ redirect_to my_account_url
+ else
+ render :action => :new
+ end
+ end
+
+ def destroy
+ @user_session.destroy
+ end
+ end
+
+Look familiar? If you didn't know any better, you would think UserSession was an ActiveRecord model. I think that's pretty cool. Why is that cool? Because it fits nicely into the RESTful development pattern and its a style we all know and love. Wouldn't this be cool too...
+
+ <%= error_messages_for "user_session" %>
+ <% form_for @user_session do |f| %>
+ <%= f.label :login %><br />
+ <%= f.text_field :login %><br />
+ <br />
+ <%= f.label :password %><br />
+ <%= f.password_field :password %><br />
+ <br />
+ <%= f.submit "Login" %>
+ <% end %>
+
+Oh, and how about this...
+
+ class ApplicationController
+ before_filter :load_user
+
+ protected
+ def load_user
+ @user_session = UserSession.find
+ @current_user = @user_session && @user_session.record
+ end
+ end
+
+Authgasm makes this a reality. Hopefully I got your interest. This is just the tip of the ice berg. Keep reading to find out everything Authgasm can do.
+
+== Helpful links
+
+* <b>Documentation:</b> http://authgasm.rubyforge.org
+* <b>Authgasm tutorial:</b> coming soon...
+* <b>Live example of the tutorial above (with source):</b> coming soon....
+* <b>Bugs / feature suggestions:</b> http://binarylogic.lighthouseapp.com/projects/18752-authgasm
+
+== Install and use
+
+Installing Authgasm and setting it up is very simple. Just like rails, Authgasm favors convention over configuration. As a result, it assumes a few things about your app. This guide will walk you through setting up Authgasm in your app and what Authgasm assumes.
+
+=== Install the gem / plugin
+
+ $ sudo gem install authgasm
+ $ cd vendor/plugins
+ $ sudo gem unpack authgasm
+
+Or as a plugin
+
+ script/plugin install git://github.com/binarylogic/authgasm.git
+
+=== Configuration
+
+Before we start, it is important you understand the basics behind Authgasm. Authgasm is split into 2 parts.
+
+1. Your model that you will be authenticating with, such as User
+2. Your session that represents a login, such as UserSession
+
+Each have their own configuration, so it can be as flexible as you need it to be. What's convenient is that the configuration for your model defaults to the configuration you set in your session. So if you set the configuration in your session, you won't have to repeat yourself in your model.
+
+For information on configuration please see Searchgasm::ActsAsAuthentic and Authgasm::Session::Config::ClassMethods
+
+=== Set up your model
+
+Make sure you have a model that you will be authenticating with. For this example let's say you have a User model:
+
+ class User < ActiveRecord::Base
+ acts_as_authentic # for options see documentation: Authgasm::ActsAsAuthentic
+ end
+
+The user model needs to have the following columns. The names of these columns can be changed with configuration.
+
+ t.string :login, :null => false
+ t.string :crypted_password, :null => false
+ t.string :password_salt, :null => false # not needed if you are encrypting your pw instead of using a hash algorithm
+ t.string :remember_token, :null => false
+ t.integer :loging_count # This is optional, it is a "magic" column, just like "created_at". See below for a list of all magic columns.
+
+Create your user_session.rb file:
+
+ # app/models/user_session.rb
+ class UserSession < Authgasm::Session::Base
+ end
+
+Done! Now go use it just like you would with any other ActiveRecord model (see above).
+
+== Magic Columns
+
+Just like ActiveRecord has "magic" columns, such as: created_at and updated_at. Authgasm has its own "magic" columns too:
+
+ Column name Description
+ login_count Increased every time and explicit login is made. This will *NOT* increase if logging in by a session, cookie, or basic http auth
+ last_click_at Updates every time the user logs in, either by explicitly logging in, or logging in by cookie, session, or http auth
+ current_login_at Updates with the current time when an explicit login is made.
+ last_login_at Updates with the value of current_login_at before it is reset.
+ current_login_ip Updates with the request remote_ip when an explicit login is made.
+ last_login_ip Updates with the value of current_login_ip before it is reset.
+
+== Magic States
+
+Authgasm tries to check the state of the record before creating the session. If your record responds to the following methods and any of them return false, validation will fail:
+
+ Method name Description
+ approved? Has the record been approved?
+ confirmed? Has the record been conirmed?
+ inactive? Is the record marked as inactive?
+
+What's neat about these is that these are checked upon any type of login. When logging in explicitly, by cookie, session, or basic http auth. If any of these return false validation will fail and a session will not be created.
+
+== Hooks / Callbacks
+
+Just like ActiveRecord you can create your own hooks / callbacks so that you can do whatever you want when certain actions are performed. Here they are:
+
+ before_create
+ after_create
+ before_destroy
+ after_destroy
+ before_update
+ after_update
+ before_validation
+ after_validation
+
+== Automatic Session Updating
+
+This is one of my favorite features that I think is pretty cool. What if a user changes their password? You have to re-log them in with the new password, recreate the session, etc, pain in the ass. Or what if a user creates a new user account? You have to do the same thing. It makes your UsersController kind of dirty and it's kind of annoying. What's cool about this is that we pulled the UserSession down into the models, where we can play around with it. Why not have the User model take care of this for us in an after_save? Whoa! Now you don't have to worry about it at all. In fact, the acts_as_authentic method has an option to do this automatically for you. Zing! Man, Authgasm might be a little too awesome. So...
+
+ @current_user.password = "my new password"
+ @current_user.confirm_password = "my new password"
+ @current_user.save # automatically updates the sessions for you!
+
+When things come together like this I think its a sign that you are doing something right. Put that in your pipe and smoke it!
+
+== How it works
+
+Interested in how this all works. Basically a before_filter is set in your controller which lets Authgasm know about the current controller object. This allows Authgasm to set sessions, cookies, login via basic http auth, etc. Don't worry, this is thread safe.
+
+From there is it pretty simple. When you try to create a new session the record is authenticated and then all of the session / cookie magic is done for you.
+
+
+Copyright (c) 2008 Ben Johnson of [Binary Logic](http://www.binarylogic.com), released under the MIT license
@@ -0,0 +1,15 @@
+require 'rubygems'
+require 'echoe'
+
+require File.dirname(__FILE__) << "/lib/authgasm/version"
+
+Echoe.new 'authgasm' do |p|
+ p.version = Authgasm::Version::STRING
+ p.author = "Ben Johnson of Binary Logic"
+ p.email = 'bjohnson@binarylogic.com'
+ p.project = 'authgasm'
+ p.summary = "Rails authentication done right"
+ p.url = "http://github.com/binarylogic/authgasm"
+ p.dependencies = %w(activesupport activerecord)
+ p.include_rakefile = true
+end
@@ -0,0 +1,2 @@
+require "digest/sha2"
+require "authgasm"
@@ -0,0 +1,18 @@
+require File.dirname(__FILE__) + "/authgasm/version"
+require File.dirname(__FILE__) + "/authgasm/controller"
+require File.dirname(__FILE__) + "/authgasm/sha256_crypto_provider"
+require File.dirname(__FILE__) + "/authgasm/acts_as_authentic"
+require File.dirname(__FILE__) + "/authgasm/session/active_record_trickery"
+require File.dirname(__FILE__) + "/authgasm/session/callbacks"
+require File.dirname(__FILE__) + "/authgasm/session/config"
+require File.dirname(__FILE__) + "/authgasm/session/errors"
+require File.dirname(__FILE__) + "/authgasm/session/base"
+
+module Authgasm
+ module Session
+ class Base
+ include ActiveRecordTrickery
+ include Callbacks
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 1b98335

Please sign in to comment.