authentication-service 0.0.1.a1 → 0.0.1.b

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,39 @@
1
+ = Authentication-Service
2
+
3
+ Authentication support for Rails applications. Can be also used with non Rails apps.
4
+
5
+ == Quick start
6
+
7
+ In your Gemfile:
8
+ gem 'authentication-service'
9
+
10
+ In your ApplicationController:
11
+ include AuthenticationService::Rails
12
+ authentication_service :account => Persistance::Account, :session => Persistance::Session
13
+ before_filter :authenticate
14
+
15
+ Generate required stuff:
16
+ rails generate authentication_service:all
17
+ It generates models (with corresponding migrations):
18
+ * persistance/account.rb - the account model
19
+ * persistance/session.rb - used to persist sessions
20
+ It generates sessions controller and view:
21
+ * sessions_controller.rb - controller to authenticate users
22
+ * views/sessions/new.html.erb - login form template
23
+ It injects routes.
24
+
25
+ == Enabling authentication
26
+
27
+ In ApplicationController before_filter enables authentication for entire app:
28
+ before_filter :authenticate
29
+
30
+ It can be also skipped for entire controller or for individual actions:
31
+ skip_filter :authenticate #Skips for entire controller
32
+ skip_filter :authenticate, :only => [:index] #Skips just for index action
33
+ before_filter :authenticate, :only => [:index] #Authenticates just index action.
34
+
35
+ == Testing
36
+
37
+ To mark your controller as authenticated just add following line:
38
+ @controller.current_session = mock(:current_session)
39
+
@@ -1,3 +1,3 @@
1
1
  module AuthenticationService
2
- VERSION = "0.0.1.a1"
2
+ VERSION = "0.0.1.b"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators/active_record/migration'
2
+ require 'active_record'
3
+ require 'rails/generators/authentication_service/authentication_service_generator'
4
+
5
+ module AuthenticationService
6
+ module Generators
7
+ class AccountGenerator < Base
8
+ include ::Rails::Generators::Migration
9
+ extend ActiveRecord::Generators::Migration
10
+
11
+ def create_module_file
12
+ template '../../templates/persistance_module.rb', 'app/models/persistance.rb'
13
+ end
14
+
15
+ def create_model_file
16
+ template 'account.rb', 'app/models/persistance/account.rb'
17
+ end
18
+
19
+ def create_migration_file
20
+ migration_template 'migration.rb', 'db/migrate/create_persistance_accounts.rb'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,2 @@
1
+ class Persistance::Account < ActiveRecord::Base
2
+ end
@@ -0,0 +1,12 @@
1
+ class CreatePersistanceAccounts < ActiveRecord::Migration
2
+ def change
3
+ create_table :accounts do |t|
4
+ t.string :email, :limit => 255, :null => false
5
+ t.string :password_hash, :limit => 1024, :null => false
6
+
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :accounts, [:email], :unique => true
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/authentication_service/authentication_service_generator'
2
+
3
+ module AuthenticationService
4
+ module Generators
5
+ class All < Base
6
+ def generate_all
7
+ ::Rails::Generators.invoke("authentication_service:account")
8
+ ::Rails::Generators.invoke("authentication_service:session")
9
+ ::Rails::Generators.invoke("authentication_service:sessions_controller")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails/generators/base'
2
+
3
+ module AuthenticationService
4
+ module Generators
5
+ class Base < ::Rails::Generators::Base
6
+ def self.base_root
7
+ File.expand_path("../../", __FILE__)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators/active_record/migration'
2
+ require 'active_record'
3
+ require 'rails/generators/authentication_service/authentication_service_generator'
4
+
5
+ module AuthenticationService
6
+ module Generators
7
+ class SessionGenerator < Base
8
+ include ::Rails::Generators::Migration
9
+ extend ActiveRecord::Generators::Migration
10
+
11
+ def create_module_file
12
+ template '../../templates/persistance_module.rb', 'app/models/persistance.rb'
13
+ end
14
+
15
+ def create_model_file
16
+ template 'session.rb', 'app/models/persistance/session.rb'
17
+ end
18
+
19
+ def create_migration_file
20
+ migration_template 'migration.rb', 'db/migrate/create_persistance_sessions.rb'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePersistanceSessions < ActiveRecord::Migration
2
+ def change
3
+ create_table :sessions do |t|
4
+ t.string :session_id, :null => false, :limit => 255
5
+ t.integer :account_id, :null => false
6
+ t.string :ip_address, :null => false, :limit => 100
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :sessions, [:account_id]
11
+ add_index :sessions, [:session_id], :unique => true
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class Persistance::Session < ActiveRecord::Base
2
+ belongs_to :account
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails/generators/authentication_service/authentication_service_generator'
2
+
3
+ module AuthenticationService
4
+ module Generators
5
+ class SessionsControllerGenerator < Base
6
+ def create_controller
7
+ template 'sessions_controller.rb', 'app/controllers/sessions_controller.rb'
8
+ end
9
+
10
+ def create_views
11
+ template 'new.erb', 'app/views/sessions/new.html.erb'
12
+ end
13
+
14
+ def add_routes
15
+ route %{get "sign-in" => "sessions#new", :as => :sign_in}
16
+ route %{post "sign-in" => "sessions#create", :as => :sign_in}
17
+ route %{post "sign-out" => "sessions#destroy", :as => :sign_out}
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ <h1>Sessions#new</h1>
2
+ <p>Find me in app/views/sessions/new.html.erb</p>
3
+ <p>Put your login form here. It should post to sessions/create</p>
@@ -0,0 +1,9 @@
1
+ class SessionsController < ApplicationController
2
+ # behave_as_sessins_controller injects following actions:
3
+ # GET new
4
+ # POST create, params: login(email), password
5
+ # POST destroy
6
+ #
7
+ # Please see module source 'AuthenticationService::Rails::SessionsControllerActions' for details
8
+ behave_as_sessins_controller
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authentication-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.a1
4
+ version: 0.0.1.b
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-27 00:00:00.000000000 Z
12
+ date: 2012-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70191597925800 !ruby/object:Gem::Requirement
16
+ requirement: &70145108259940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70191597925800
24
+ version_requirements: *70145108259940
25
25
  description: Provides authentication related stuff.
26
26
  email:
27
27
  - evgeny.myasishchev@gmail.com
@@ -33,7 +33,7 @@ files:
33
33
  - .rspec
34
34
  - .rvmrc
35
35
  - Gemfile
36
- - README
36
+ - README.rdoc
37
37
  - Rakefile
38
38
  - authentication-service.gemspec
39
39
  - lib/authentication-service.rb
@@ -46,6 +46,18 @@ files:
46
46
  - lib/authentication-service/rails/sessions-controller-actions.rb
47
47
  - lib/authentication-service/session.rb
48
48
  - lib/authentication-service/version.rb
49
+ - lib/rails/generators/authentication_service/account/account_generator.rb
50
+ - lib/rails/generators/authentication_service/account/templates/account.rb
51
+ - lib/rails/generators/authentication_service/account/templates/migration.rb
52
+ - lib/rails/generators/authentication_service/all_generator.rb
53
+ - lib/rails/generators/authentication_service/authentication_service_generator.rb
54
+ - lib/rails/generators/authentication_service/session/session_generator.rb
55
+ - lib/rails/generators/authentication_service/session/templates/migration.rb
56
+ - lib/rails/generators/authentication_service/session/templates/session.rb
57
+ - lib/rails/generators/authentication_service/sessions_controller/sessions_controller_generator.rb
58
+ - lib/rails/generators/authentication_service/sessions_controller/templates/new.erb
59
+ - lib/rails/generators/authentication_service/sessions_controller/templates/sessions_controller.rb
60
+ - lib/rails/generators/authentication_service/templates/persistance_module.rb
49
61
  - spec/lib/account_spec.rb
50
62
  - spec/lib/base_spec.rb
51
63
  - spec/lib/persistance/accounts_repository_spec.rb
data/README DELETED
File without changes