authpwn_rails 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,7 +6,7 @@ User authentication for a Ruby on Rails 3 application. Works with Facebook.
6
6
 
7
7
  Scaffold user accounts, session controller views, and Facebook extensions.
8
8
  rails g authpwn_rails:users
9
- rails g authpwn_rails:session_views
9
+ rails g authpwn_rails:session
10
10
  rails g authpwn_rails:facebook
11
11
 
12
12
  Wire authentication into your ApplicationController.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{authpwn_rails}
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Victor Costan"]
@@ -24,15 +24,13 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
- "app/controllers/session_controller.rb",
28
27
  "app/helpers/session_helper.rb",
29
28
  "authpwn_rails.gemspec",
30
- "config/routes.rb",
31
29
  "lib/authpwn_rails.rb",
32
30
  "lib/authpwn_rails/engine.rb",
33
31
  "lib/authpwn_rails/facebook_extensions.rb",
34
32
  "lib/authpwn_rails/generators/facebook_generator.rb",
35
- "lib/authpwn_rails/generators/session_views_generator.rb",
33
+ "lib/authpwn_rails/generators/session_generator.rb",
36
34
  "lib/authpwn_rails/generators/templates/001_create_users.rb",
37
35
  "lib/authpwn_rails/generators/templates/002_create_facebook_tokens.rb",
38
36
  "lib/authpwn_rails/generators/templates/facebook_token.rb",
@@ -40,6 +38,7 @@ Gem::Specification.new do |s|
40
38
  "lib/authpwn_rails/generators/templates/session/home.html.erb",
41
39
  "lib/authpwn_rails/generators/templates/session/new.html.erb",
42
40
  "lib/authpwn_rails/generators/templates/session/welcome.html.erb",
41
+ "lib/authpwn_rails/generators/templates/session_controller.rb",
43
42
  "lib/authpwn_rails/generators/templates/user.rb",
44
43
  "lib/authpwn_rails/generators/templates/users.yml",
45
44
  "lib/authpwn_rails/generators/user_generator.rb",
@@ -15,11 +15,11 @@ class Engine < Rails::Engine
15
15
  # paths.config = "config"
16
16
  # paths.config.initializers = "config/initializers"
17
17
  # paths.config.locales = "config/locales"
18
- paths.config.routes = "config/routes.rb"
18
+ # paths.config.routes = "config/routes.rb"
19
19
 
20
20
  generators do
21
21
  require 'authpwn_rails/generators/facebook_generator.rb'
22
- require 'authpwn_rails/generators/session_views_generator.rb'
22
+ require 'authpwn_rails/generators/session_generator.rb'
23
23
  require 'authpwn_rails/generators/user_generator.rb'
24
24
  end
25
25
  end # class AuthpwnRails::Engine
@@ -2,16 +2,20 @@
2
2
  module AuthpwnRails
3
3
 
4
4
 
5
- class SessionViewsGenerator < Rails::Generators::Base
5
+ class SessionGenerator < Rails::Generators::Base
6
6
  source_root File.expand_path("../templates", __FILE__)
7
7
 
8
- def create_session_views
8
+ def create_session
9
+ copy_file 'session_controller.rb',
10
+ File.join('app', 'controllers', 'session_controller.rb')
9
11
  copy_file File.join('session', 'home.html.erb'),
10
12
  File.join('app', 'views', 'session', 'home.html.erb')
11
13
  copy_file File.join('session', 'new.html.erb'),
12
14
  File.join('app', 'views', 'session', 'new.html.erb')
13
15
  copy_file File.join('session', 'welcome.html.erb'),
14
16
  File.join('app', 'views', 'session', 'welcome.html.erb')
17
+
18
+ route "resource :session, :controller => 'session'"
15
19
  end
16
20
  end # class AuthpwnRails::SessionViewsGenerator
17
21
 
@@ -0,0 +1,22 @@
1
+ # Manages logging in and out of the application.
2
+ class SessionController < ApplicationController
3
+ authpwn_session_controller
4
+
5
+ # Sets up the 'session/welcome' view. No user is logged in.
6
+ def welcome
7
+ # You can brag about some statistics.
8
+ @user_count = User.count
9
+ end
10
+ private :welcome
11
+
12
+ # Sets up the 'session/home' view. A user is logged in.
13
+ def home
14
+ # Pull information about the current user.
15
+ @user = current_user
16
+ end
17
+ private :home
18
+
19
+ # You shouldn't extend the session controller, so you can benefit from future
20
+ # features, like Facebook / Twitter / OpenID integration. But, if you must,
21
+ # you can do it here.
22
+ end
@@ -24,6 +24,15 @@ module ControllerClassMethods
24
24
  include ControllerInstanceMethods
25
25
  before_filter :authenticate_using_session, options
26
26
  end
27
+
28
+ # Turns the current controller into the session processing controller.
29
+ #
30
+ # Right now, this should be called from SessionController. The controller name
31
+ # is hardwired in other parts of the implementation.
32
+ def authpwn_session_controller
33
+ include SessionControllerInstanceMethods
34
+ authenticates_using_session
35
+ end
27
36
  end
28
37
 
29
38
  # Included in controllers that call authenticates_using_session.
@@ -48,8 +57,62 @@ module ControllerInstanceMethods
48
57
  private :authenticate_using_session
49
58
  end
50
59
 
60
+ # Included in controllers that call authenticates_using_session.
61
+ module SessionControllerInstanceMethods
62
+ # GET /session/new
63
+ def new
64
+ @user = User.new
65
+ redirect_to session_url if current_user
66
+ end
67
+
68
+ # GET /session
69
+ def show
70
+ @user = current_user || User.new
71
+ if @user.new_record?
72
+ welcome
73
+ render :action => :welcome
74
+ else
75
+ home
76
+ render :action => :home
77
+ end
78
+ end
79
+
80
+ # POST /session
81
+ def create
82
+ @user = User.new params[:user]
83
+ self.current_user =
84
+ User.find_by_email_and_password @user.email, @user.password
85
+
86
+ respond_to do |format|
87
+ if current_user
88
+ format.html { redirect_to session_url }
89
+ else
90
+ flash[:notice] = 'Invalid e-mail or password'
91
+ format.html { redirect_to session_url }
92
+ end
93
+ end
94
+ end
95
+
96
+ # DELETE /session
97
+ def destroy
98
+ self.current_user = nil
99
+ redirect_to session_url
100
+ end
101
+
102
+ # Hook for setting up the home view.
103
+ def home
104
+ end
105
+ private :home
106
+
107
+ # Hook for setting up the welcome view.
108
+ def welcome
109
+ end
110
+ private :welcome
111
+ end # module Authpwn::Session::SessionControllerInstanceMethods
112
+
51
113
  ActionController::Base.send :include, ControllerMixin
52
114
 
115
+
53
116
  # :nodoc: add session modification
54
117
  class ActionController::TestCase
55
118
  # Sets the authenticated user in the test session.
@@ -5,6 +5,7 @@ class ActionController::TestCase
5
5
  @routes.draw do
6
6
  resource :cookie, :controller => 'cookie'
7
7
  resource :facebook, :controller => 'facebook'
8
+ # NOTE: this route should be kept in sync with the session template.
8
9
  resource :session, :controller => 'session'
9
10
  root :to => 'session#index'
10
11
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path('../test_helper', __FILE__)
2
2
 
3
- require File.expand_path('../../app/controllers/session_controller', __FILE__)
3
+ require 'authpwn_rails/generators/templates/session_controller.rb'
4
4
 
5
5
  class SessionControllerTest < ActionController::TestCase
6
6
  setup do
@@ -11,6 +11,8 @@ class SessionControllerTest < ActionController::TestCase
11
11
  get :show
12
12
  assert_template :welcome
13
13
  assert_nil assigns(:current_user)
14
+ assert_equal User.count, assigns(:user_count),
15
+ 'welcome controller method not called'
14
16
  end
15
17
 
16
18
  test "show renders home with a user" do
@@ -18,6 +20,7 @@ class SessionControllerTest < ActionController::TestCase
18
20
  get :show
19
21
  assert_template :home
20
22
  assert_equal @user, assigns(:current_user)
23
+ assert_equal @user, assigns(:user), 'home controller method not called'
21
24
  end
22
25
 
23
26
  test "new redirects homes with a user" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authpwn_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 2
10
- version: 0.4.2
9
+ - 3
10
+ version: 0.4.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Victor Costan
@@ -84,15 +84,13 @@ files:
84
84
  - README.rdoc
85
85
  - Rakefile
86
86
  - VERSION
87
- - app/controllers/session_controller.rb
88
87
  - app/helpers/session_helper.rb
89
88
  - authpwn_rails.gemspec
90
- - config/routes.rb
91
89
  - lib/authpwn_rails.rb
92
90
  - lib/authpwn_rails/engine.rb
93
91
  - lib/authpwn_rails/facebook_extensions.rb
94
92
  - lib/authpwn_rails/generators/facebook_generator.rb
95
- - lib/authpwn_rails/generators/session_views_generator.rb
93
+ - lib/authpwn_rails/generators/session_generator.rb
96
94
  - lib/authpwn_rails/generators/templates/001_create_users.rb
97
95
  - lib/authpwn_rails/generators/templates/002_create_facebook_tokens.rb
98
96
  - lib/authpwn_rails/generators/templates/facebook_token.rb
@@ -100,6 +98,7 @@ files:
100
98
  - lib/authpwn_rails/generators/templates/session/home.html.erb
101
99
  - lib/authpwn_rails/generators/templates/session/new.html.erb
102
100
  - lib/authpwn_rails/generators/templates/session/welcome.html.erb
101
+ - lib/authpwn_rails/generators/templates/session_controller.rb
103
102
  - lib/authpwn_rails/generators/templates/user.rb
104
103
  - lib/authpwn_rails/generators/templates/users.yml
105
104
  - lib/authpwn_rails/generators/user_generator.rb
@@ -1,42 +0,0 @@
1
- # Manages logging in and out of the application.
2
- class SessionController < ApplicationController
3
- authenticates_using_session
4
-
5
- # GET /session/new
6
- def new
7
- @user = User.new
8
- redirect_to session_url if current_user
9
- end
10
-
11
- # GET /session
12
- def show
13
- @user = current_user || User.new
14
- if @user.new_record?
15
- render :action => :welcome
16
- else
17
- render :action => :home
18
- end
19
- end
20
-
21
- # POST /session
22
- def create
23
- @user = User.new params[:user]
24
- self.current_user =
25
- User.find_by_email_and_password @user.email, @user.password
26
-
27
- respond_to do |format|
28
- if current_user
29
- format.html { redirect_to session_url }
30
- else
31
- flash[:notice] = 'Invalid e-mail or password'
32
- format.html { redirect_to session_url }
33
- end
34
- end
35
- end
36
-
37
- # DELETE /session
38
- def destroy
39
- self.current_user = nil
40
- redirect_to session_url
41
- end
42
- end
data/config/routes.rb DELETED
@@ -1,3 +0,0 @@
1
- Rails::Application.routes.draw do |map|
2
- resource :session, :controller => 'session'
3
- end