monban 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +149 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +65 -0
  6. data/Rakefile +6 -0
  7. data/lib/generators/monban/controllers/controllers_generator.rb +30 -0
  8. data/lib/generators/monban/scaffold/scaffold_generator.rb +42 -0
  9. data/lib/generators/monban/templates/app/controllers/sessions_controller.rb +30 -0
  10. data/lib/generators/monban/templates/app/controllers/users_controller.rb +26 -0
  11. data/lib/generators/monban/templates/app/models/user.rb +7 -0
  12. data/lib/generators/monban/templates/app/views/sessions/new.html.erb +13 -0
  13. data/lib/generators/monban/templates/app/views/users/new.html.erb +13 -0
  14. data/lib/generators/monban/templates/db/migrate/create_users.rb +10 -0
  15. data/lib/generators/monban/templates/scaffold_readme +4 -0
  16. data/lib/monban.rb +38 -0
  17. data/lib/monban/configuration.rb +27 -0
  18. data/lib/monban/controller_helpers.rb +56 -0
  19. data/lib/monban/controller_helpers/authentication.rb +26 -0
  20. data/lib/monban/controller_helpers/sign_in.rb +12 -0
  21. data/lib/monban/controller_helpers/sign_out.rb +11 -0
  22. data/lib/monban/controller_helpers/sign_up.rb +23 -0
  23. data/lib/monban/field_map.rb +38 -0
  24. data/lib/monban/railtie.rb +9 -0
  25. data/lib/monban/strategies/password_strategy.rb +15 -0
  26. data/lib/monban/version.rb +3 -0
  27. data/lib/monban/warden_setup.rb +11 -0
  28. data/monban.gemspec +29 -0
  29. data/spec/features/visitor/visitor_signs_up_spec.rb +12 -0
  30. data/spec/monban/controller_helpers/authentication_spec.rb +25 -0
  31. data/spec/monban/controller_helpers/sign_in_spec.rb +12 -0
  32. data/spec/monban/controller_helpers/sign_out_spec.rb +11 -0
  33. data/spec/monban/controller_helpers/sign_up_spec.rb +17 -0
  34. data/spec/monban/controller_helpers_spec.rb +124 -0
  35. data/spec/monban/field_map_spec.rb +18 -0
  36. data/spec/monban_spec.rb +7 -0
  37. data/spec/rails_app/Rakefile +7 -0
  38. data/spec/rails_app/app/assets/images/rails.png +0 -0
  39. data/spec/rails_app/app/assets/javascripts/application.js +13 -0
  40. data/spec/rails_app/app/assets/stylesheets/application.css +13 -0
  41. data/spec/rails_app/app/controllers/application_controller.rb +4 -0
  42. data/spec/rails_app/app/controllers/posts_controller.rb +7 -0
  43. data/spec/rails_app/app/controllers/sessions_controller.rb +18 -0
  44. data/spec/rails_app/app/controllers/users_controller.rb +15 -0
  45. data/spec/rails_app/app/helpers/application_helper.rb +2 -0
  46. data/spec/rails_app/app/models/user.rb +4 -0
  47. data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
  48. data/spec/rails_app/app/views/users/new.html.erb +5 -0
  49. data/spec/rails_app/config.ru +4 -0
  50. data/spec/rails_app/config/application.rb +58 -0
  51. data/spec/rails_app/config/boot.rb +6 -0
  52. data/spec/rails_app/config/database.yml +25 -0
  53. data/spec/rails_app/config/environment.rb +5 -0
  54. data/spec/rails_app/config/environments/development.rb +29 -0
  55. data/spec/rails_app/config/environments/production.rb +54 -0
  56. data/spec/rails_app/config/environments/test.rb +29 -0
  57. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  58. data/spec/rails_app/config/initializers/inflections.rb +15 -0
  59. data/spec/rails_app/config/initializers/secret_token.rb +7 -0
  60. data/spec/rails_app/config/routes.rb +8 -0
  61. data/spec/rails_app/db/seeds.rb +7 -0
  62. data/spec/rails_app/public/404.html +26 -0
  63. data/spec/rails_app/public/422.html +26 -0
  64. data/spec/rails_app/public/500.html +25 -0
  65. data/spec/rails_app/public/favicon.ico +0 -0
  66. data/spec/rails_app/script/rails +6 -0
  67. data/spec/spec_helper.rb +7 -0
  68. metadata +299 -0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ spec/rails_app/log/*
2
+ spec/rails_app/tmp/*
3
+ *.sqlite3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in monban.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,149 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ monban (0.0.1)
5
+ bcrypt-ruby
6
+ rails
7
+ warden
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionmailer (3.2.11)
13
+ actionpack (= 3.2.11)
14
+ mail (~> 2.4.4)
15
+ actionpack (3.2.11)
16
+ activemodel (= 3.2.11)
17
+ activesupport (= 3.2.11)
18
+ builder (~> 3.0.0)
19
+ erubis (~> 2.7.0)
20
+ journey (~> 1.0.4)
21
+ rack (~> 1.4.0)
22
+ rack-cache (~> 1.2)
23
+ rack-test (~> 0.6.1)
24
+ sprockets (~> 2.2.1)
25
+ active_hash (0.9.13)
26
+ activesupport (>= 2.2.2)
27
+ activemodel (3.2.11)
28
+ activesupport (= 3.2.11)
29
+ builder (~> 3.0.0)
30
+ activerecord (3.2.11)
31
+ activemodel (= 3.2.11)
32
+ activesupport (= 3.2.11)
33
+ arel (~> 3.0.2)
34
+ tzinfo (~> 0.3.29)
35
+ activeresource (3.2.11)
36
+ activemodel (= 3.2.11)
37
+ activesupport (= 3.2.11)
38
+ activesupport (3.2.11)
39
+ i18n (~> 0.6)
40
+ multi_json (~> 1.0)
41
+ arel (3.0.2)
42
+ bcrypt-ruby (3.0.1)
43
+ builder (3.0.4)
44
+ capybara (2.0.2)
45
+ mime-types (>= 1.16)
46
+ nokogiri (>= 1.3.3)
47
+ rack (>= 1.0.0)
48
+ rack-test (>= 0.5.4)
49
+ selenium-webdriver (~> 2.0)
50
+ xpath (~> 1.0.0)
51
+ childprocess (0.3.7)
52
+ ffi (~> 1.0, >= 1.0.6)
53
+ coderay (1.0.8)
54
+ diff-lcs (1.1.3)
55
+ erubis (2.7.0)
56
+ ffi (1.3.1)
57
+ hike (1.2.1)
58
+ i18n (0.6.1)
59
+ journey (1.0.4)
60
+ json (1.7.6)
61
+ mail (2.4.4)
62
+ i18n (>= 0.4.0)
63
+ mime-types (~> 1.16)
64
+ treetop (~> 1.4.8)
65
+ method_source (0.8.1)
66
+ mime-types (1.20.1)
67
+ multi_json (1.5.0)
68
+ nokogiri (1.5.6)
69
+ polyglot (0.3.3)
70
+ pry (0.9.11.4)
71
+ coderay (~> 1.0.5)
72
+ method_source (~> 0.8)
73
+ slop (~> 3.4)
74
+ rack (1.4.4)
75
+ rack-cache (1.2)
76
+ rack (>= 0.4)
77
+ rack-ssl (1.3.3)
78
+ rack
79
+ rack-test (0.6.2)
80
+ rack (>= 1.0)
81
+ rails (3.2.11)
82
+ actionmailer (= 3.2.11)
83
+ actionpack (= 3.2.11)
84
+ activerecord (= 3.2.11)
85
+ activeresource (= 3.2.11)
86
+ activesupport (= 3.2.11)
87
+ bundler (~> 1.0)
88
+ railties (= 3.2.11)
89
+ railties (3.2.11)
90
+ actionpack (= 3.2.11)
91
+ activesupport (= 3.2.11)
92
+ rack-ssl (~> 1.3.2)
93
+ rake (>= 0.8.7)
94
+ rdoc (~> 3.4)
95
+ thor (>= 0.14.6, < 2.0)
96
+ rake (10.0.3)
97
+ rdoc (3.12.1)
98
+ json (~> 1.4)
99
+ rspec (2.12.0)
100
+ rspec-core (~> 2.12.0)
101
+ rspec-expectations (~> 2.12.0)
102
+ rspec-mocks (~> 2.12.0)
103
+ rspec-core (2.12.2)
104
+ rspec-expectations (2.12.1)
105
+ diff-lcs (~> 1.1.3)
106
+ rspec-mocks (2.12.2)
107
+ rspec-rails (2.12.0)
108
+ actionpack (>= 3.0)
109
+ activesupport (>= 3.0)
110
+ railties (>= 3.0)
111
+ rspec-core (~> 2.12.0)
112
+ rspec-expectations (~> 2.12.0)
113
+ rspec-mocks (~> 2.12.0)
114
+ rubyzip (0.9.9)
115
+ selenium-webdriver (2.29.0)
116
+ childprocess (>= 0.2.5)
117
+ multi_json (~> 1.0)
118
+ rubyzip
119
+ websocket (~> 1.0.4)
120
+ slop (3.4.3)
121
+ sprockets (2.2.2)
122
+ hike (~> 1.2)
123
+ multi_json (~> 1.0)
124
+ rack (~> 1.0)
125
+ tilt (~> 1.1, != 1.3.0)
126
+ sqlite3 (1.3.7)
127
+ thor (0.17.0)
128
+ tilt (1.3.3)
129
+ treetop (1.4.12)
130
+ polyglot
131
+ polyglot (>= 0.3.1)
132
+ tzinfo (0.3.35)
133
+ warden (1.2.1)
134
+ rack (>= 1.0)
135
+ websocket (1.0.7)
136
+ xpath (1.0.0)
137
+ nokogiri (~> 1.3)
138
+
139
+ PLATFORMS
140
+ ruby
141
+
142
+ DEPENDENCIES
143
+ active_hash
144
+ capybara
145
+ monban!
146
+ pry
147
+ rspec
148
+ rspec-rails
149
+ sqlite3
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 halogenandtoast
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Monban 門番
2
+
3
+ Monban is designed to be very simple and extensible user authentication. It's goal is to give all the power to the developer instead of
4
+ forcing them to make Monban work with their system
5
+
6
+ # Why use Monban?
7
+
8
+ Monban makes authentication simple:
9
+
10
+ - Uses warden
11
+ - Provides convenient controller helpers
12
+ - TODO: Very customizable
13
+ - TODO: provides a generator for default controllers and views
14
+
15
+ Monban doesn't do the following:
16
+
17
+ - Doesn't automatically add routes to your application
18
+ - Doesn't force you to use engine based controllers or views
19
+ - Doesn't require you to make changes to your user model
20
+
21
+
22
+ ## Installation
23
+
24
+ Monban was designed to work with Rails > 3.1. Add this line to your Gemfile:
25
+
26
+ gem 'monban'
27
+
28
+ Then inside of your ApplicationController add the following:
29
+
30
+ include Monban::ControllerHelpers
31
+
32
+ ## Usage
33
+
34
+ Monban does currently have some expectations, but these will change. Here are the current requirements:
35
+
36
+ - Your model must be called `User`
37
+ - You must have an `email` and `password_digest` column on your `User`
38
+ - Passwords will be run through BCrypt
39
+
40
+ ### Controller Additions
41
+
42
+ Monban provides the following controller methods:
43
+
44
+ - `sign_in(user)`
45
+ - `sign_out`
46
+ - `sign_up(user)`
47
+ - `authenticate_session(session_params)`
48
+ - `authenticate(user, password)`
49
+
50
+ These helpers:
51
+
52
+ - `current_user`
53
+ - `signed_in?`
54
+
55
+ And this filter:
56
+
57
+ - `require_login`
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,30 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Monban
4
+ module Generators
5
+ class ControllersGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../../templates", __FILE__)
7
+
8
+ def copy_controllers
9
+ template 'app/controllers/sessions_controller.rb', 'app/controllers/sessions_controller.rb', config
10
+ template 'app/controllers/users_controller.rb', 'app/controllers/users_controller.rb', config
11
+ end
12
+
13
+ private
14
+
15
+ def config
16
+ @_config ||= {
17
+ use_strong_parameters: using_strong_parameters
18
+ }
19
+ end
20
+
21
+ def using_strong_parameters
22
+ if Kernel.const_defined?("StrongParameters")
23
+ true
24
+ else
25
+ yes?("Using strong_parameters?")
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ require 'rails/generators/active_record'
2
+ require 'generators/monban/controllers/controllers_generator'
3
+
4
+ module Monban
5
+ module Generators
6
+ class ScaffoldGenerator < ControllersGenerator
7
+ include Rails::Generators::Migration
8
+ source_root File.expand_path("../../templates", __FILE__)
9
+
10
+ def add_routes
11
+ route("resources :users, only: [:new, :create]")
12
+ route("resource :session, only: [:new, :create, :destroy]")
13
+ end
14
+
15
+ def add_views
16
+ copy_file 'app/views/users/new.html.erb'
17
+ copy_file 'app/views/sessions/new.html.erb'
18
+ end
19
+
20
+ def copy_migration
21
+ migration_template 'db/migrate/create_users.rb'
22
+ end
23
+
24
+ def add_helper_module_to_application_controller
25
+ inject_into_class "app/controllers/application_controller.rb", ApplicationController, " include Monban::ControllerHelpers\n"
26
+ end
27
+
28
+ def self.next_migration_number(dir)
29
+ ActiveRecord::Generators::Base.next_migration_number(dir)
30
+ end
31
+
32
+ def add_model
33
+ template 'app/models/user.rb', 'app/models/user.rb', config
34
+ end
35
+
36
+ def display_readme
37
+ readme 'scaffold_readme'
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,30 @@
1
+ class SessionsController < ApplicationController
2
+ def new
3
+ end
4
+
5
+ def create
6
+ if user = authenticate_session(session_params)
7
+ sign_in user
8
+ redirect_to root_path
9
+ else
10
+ flash.now.notice = "Invalid username or password"
11
+ render :new
12
+ end
13
+ end
14
+
15
+ def destroy
16
+ sign_out
17
+ redirect_to root_path
18
+ end
19
+
20
+ private
21
+
22
+ def session_params
23
+ <% if config[:use_strong_parameters] -%>
24
+ params.require(:session).permit(:email, :password)
25
+ <% else -%>
26
+ params[:session]
27
+ <% end -%>
28
+ end
29
+ end
30
+
@@ -0,0 +1,26 @@
1
+ class UsersController < ApplicationController
2
+ def new
3
+ @user = User.new
4
+ end
5
+
6
+ def create
7
+ user = sign_up(user_params)
8
+ if sign_in(user)
9
+ redirect_to root_path
10
+ else
11
+ @user = user
12
+ render :new
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def user_params
19
+ <% if config[:use_strong_parameters] -%>
20
+ params.require(:user).permit(:email, :password)
21
+ <% else -%>
22
+ params[:user]
23
+ <% end -%>
24
+ end
25
+ end
26
+
@@ -0,0 +1,7 @@
1
+ class User < ActiveRecord::Base
2
+ <% if !config[:use_strong_parameters] -%>
3
+ attr_accessible :email, :password_digest
4
+ <% elsif Gem::Version.new(Rails.version) < Gem::Version.new('4') -%>
5
+ include ActiveModel::ForbiddenAttributesProtection
6
+ <% end -%>
7
+ end
@@ -0,0 +1,13 @@
1
+ <%= form_for :session, url: session_path do |form| %>
2
+ <div>
3
+ <%= form.label :email %>
4
+ <%= form.email_field :email %>
5
+ </div>
6
+ <div>
7
+ <%= form.label :password %>
8
+ <%= form.password_field :password %>
9
+ </div>
10
+ <div>
11
+ <%= form.submit "Sign in" %>
12
+ </div>
13
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%= form_for @user do |form| %>
2
+ <div>
3
+ <%= form.label :email %>
4
+ <%= form.email_field :email %>
5
+ </div>
6
+ <div>
7
+ <%= form.label :password %>
8
+ <%= form.password_field :password %>
9
+ </div>
10
+ <div>
11
+ <%= form.submit "Sign up" %>
12
+ </div>
13
+ <% end %>
@@ -0,0 +1,10 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :email
5
+ t.string :password_digest
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+
2
+ Final Steps
3
+ run:
4
+ rake db:migrate