monban 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e29be6de04544dc568a87d8d2c8d192d80c7eaf4
4
- data.tar.gz: b8b31096244cdb5314c42b18fcf03e8e2a2e5821
3
+ metadata.gz: a1cceb69d6f7307db5055ed206dae78583979907
4
+ data.tar.gz: 3a922f46cd094d19defc0eaa17e518da87f63190
5
5
  SHA512:
6
- metadata.gz: 645d7342a7f7c3d87fe8657a0c0b28f109338d7dd50fd86874d452adaa5ab0ed77652e511015f8a7b8a9d31460e8016dbc8bf3f78f3d4e7f0d9db7cd65720e21
7
- data.tar.gz: f15e3f355a53edd45e24f98cf2a71f8e2a360888fd0165690d0f4a13e2427c82ac30e3475f2e390b7b86972513fb517cf92c59317e1e487c64302f9e2309ed9d
6
+ metadata.gz: 2c14ee5a537e4d2dd9e003b46211e268bc49f22a62ef8218c6c36f917466d8a854de83f7b8196e10a9773a1c92610bdc0109a7e2fcc2cf6878e0d8ba205a7439
7
+ data.tar.gz: a60bee9c220c98b5a78289e0b0b076ecdfeb5f56b6c7313ac587db30c918fee86e82a9f482ccebefa2ff18ec2c0c231a2266c10ff323843eb3d51e1de1d28f74
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monban (0.0.9)
4
+ monban (0.0.11)
5
5
  bcrypt
6
6
  rails
7
7
  warden
@@ -39,7 +39,7 @@ GEM
39
39
  i18n (~> 0.6)
40
40
  multi_json (~> 1.0)
41
41
  arel (3.0.3)
42
- bcrypt (3.1.6)
42
+ bcrypt (3.1.7)
43
43
  builder (3.0.4)
44
44
  capybara (2.0.2)
45
45
  mime-types (>= 1.16)
@@ -122,7 +122,7 @@ GEM
122
122
  treetop (1.4.15)
123
123
  polyglot
124
124
  polyglot (>= 0.3.1)
125
- tzinfo (0.3.38)
125
+ tzinfo (0.3.39)
126
126
  warden (1.2.3)
127
127
  rack (>= 1.0)
128
128
  websocket (1.0.7)
data/README.md CHANGED
@@ -125,7 +125,7 @@ feature "A feature spec" do
125
125
  end
126
126
  ```
127
127
 
128
- ## Controller Specs
128
+ ### Controller Specs
129
129
 
130
130
  If you are going to write controller tests, helpers are provided for those as well:
131
131
 
@@ -1,15 +1,15 @@
1
1
  class SessionsController < ApplicationController
2
- respond_to :html
3
-
4
2
  def new
5
3
  end
6
4
 
7
5
  def create
8
6
  user = authenticate_session(session_params)
9
- sign_in(user) do
10
- respond_with(user, location: root_path) and return
7
+
8
+ if sign_in(user)
9
+ redirect_to root_path
10
+ else
11
+ render :new
11
12
  end
12
- render :new
13
13
  end
14
14
 
15
15
  def destroy
@@ -1,16 +1,17 @@
1
1
  class UsersController < ApplicationController
2
- respond_to :html
3
-
4
2
  def new
5
3
  @user = User.new
6
4
  end
7
5
 
8
6
  def create
9
7
  @user = sign_up(user_params)
10
- sign_in(@user) do
11
- respond_with(@user, location: root_path) and return
8
+
9
+ if @user.valid?
10
+ sign_in(@user)
11
+ redirect_to root_path
12
+ else
13
+ render :new
12
14
  end
13
- render :new
14
15
  end
15
16
 
16
17
  private
@@ -0,0 +1,24 @@
1
+ module Monban
2
+ class BackDoor
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ sign_in_through_the_back_door(env)
9
+ @app.call(env)
10
+ end
11
+
12
+ private
13
+
14
+ def sign_in_through_the_back_door(env)
15
+ params = Rack::Utils.parse_query(env['QUERY_STRING'])
16
+ user_id = params['as']
17
+
18
+ if user_id.present?
19
+ user = Monban.user_class.find(user_id)
20
+ env["warden"].set_user(user)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -9,12 +9,16 @@ module Monban
9
9
  if @field_map
10
10
  params_from_field_map
11
11
  else
12
- @params
12
+ params_with_symbolized_keys
13
13
  end
14
14
  end
15
15
 
16
16
  private
17
17
 
18
+ def params_with_symbolized_keys
19
+ @params.inject({}){|hash,(key,value)| hash.merge(key.to_sym => value) }
20
+ end
21
+
18
22
  def params_from_field_map
19
23
  [query_string, *([value] * lookup_keys.length)]
20
24
  end
@@ -1,3 +1,3 @@
1
1
  module Monban
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
data/lib/monban.rb CHANGED
@@ -3,6 +3,7 @@ require "monban/configuration"
3
3
  require "monban/services"
4
4
  require "monban/controller_helpers"
5
5
  require "monban/railtie"
6
+ require "monban/back_door"
6
7
  require "monban/warden_setup"
7
8
  require "monban/field_map"
8
9
  require "monban/strategies/password_strategy"
@@ -41,12 +42,18 @@ module Monban
41
42
 
42
43
  def self.test_mode!
43
44
  Warden.test_mode!
45
+ self.config ||= Monban::Configuration.new
44
46
  config.encryption_method = ->(password) { password }
45
47
  config.token_comparison = ->(digest, unencrypted_password) do
46
48
  digest == unencrypted_password
47
49
  end
48
50
  end
49
51
 
52
+ def self.configure(&block)
53
+ self.config = Monban::Configuration.new
54
+ yield self.config
55
+ end
56
+
50
57
  def self.test_reset!
51
58
  Warden.test_reset!
52
59
  end
@@ -54,7 +61,7 @@ module Monban
54
61
  private
55
62
 
56
63
  def self.setup_config
57
- self.config = Monban::Configuration.new
64
+ self.config ||= Monban::Configuration.new
58
65
  if block_given?
59
66
  yield config
60
67
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Visitor signs up' do
4
+ scenario 'with an email and password' do
5
+ visit sign_up_path
6
+ click_on 'go'
7
+
8
+ expect(page).not_to have_content("Sign out")
9
+ end
10
+ end
@@ -2,8 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  module Monban
4
4
  describe FieldMap do
5
- it 'returns the params without a field map' do
5
+ it 'returns the params with symbolized keys without a field map' do
6
6
  params = double()
7
+ allow(params).to receive(:inject).and_return(params)
7
8
  field_map = FieldMap.new(params, nil)
8
9
  expect(field_map.to_fields).to eq(params)
9
10
  end
@@ -1,11 +1,13 @@
1
1
  class SessionsController < ApplicationController
2
- def new; end
2
+ respond_to :html
3
+
4
+ def new
5
+ end
3
6
 
4
7
  def create
5
- user = User.where(email: params[:session][:email]).first
8
+ user = authenticate_session(session_params)
6
9
 
7
- if authenticate(user, params[:session][:password])
8
- sign_in user
10
+ if sign_in(user)
9
11
  redirect_to posts_path
10
12
  else
11
13
  redirect_to root_path, notice: "Invalid email or password"
@@ -16,4 +18,11 @@ class SessionsController < ApplicationController
16
18
  sign_out
17
19
  redirect_to root_path
18
20
  end
21
+
22
+ private
23
+
24
+ def session_params
25
+ params[:session]
26
+ end
19
27
  end
28
+
@@ -1,15 +1,25 @@
1
1
  class UsersController < ApplicationController
2
+ respond_to :html
3
+
2
4
  def new
3
5
  @user = User.new
4
6
  end
5
7
 
6
8
  def create
7
- @user = sign_up(params[:user])
8
- if @user
9
+ @user = sign_up(user_params)
10
+
11
+ if @user.valid?
9
12
  sign_in(@user)
10
13
  redirect_to posts_path
11
14
  else
12
15
  render :new
13
16
  end
14
17
  end
18
+
19
+ private
20
+
21
+ def user_params
22
+ params[:user]
23
+ end
15
24
  end
25
+
@@ -1,4 +1,6 @@
1
1
  require 'active_hash'
2
2
  class User < ActiveHash::Base
3
+ include ActiveModel::Validations
3
4
  attr_accessor :email, :password_digest, :password
5
+ validates :email, presence: true
4
6
  end
@@ -1,4 +1,4 @@
1
- <%= form_for @user do |f| %>
1
+ <%= form_for @user, url: users_path do |f| %>
2
2
  <%= f.text_field :email %>
3
3
  <%= f.text_field :password %>
4
4
  <%= f.submit 'go' %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - halogenandtoast
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-18 00:00:00.000000000 Z
12
+ date: 2014-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -159,6 +159,7 @@ files:
159
159
  - lib/generators/monban/templates/app/views/users/new.html.erb
160
160
  - lib/generators/monban/templates/scaffold_readme
161
161
  - lib/monban.rb
162
+ - lib/monban/back_door.rb
162
163
  - lib/monban/configuration.rb
163
164
  - lib/monban/controller_helpers.rb
164
165
  - lib/monban/field_map.rb
@@ -175,6 +176,7 @@ files:
175
176
  - lib/monban/version.rb
176
177
  - lib/monban/warden_setup.rb
177
178
  - monban.gemspec
179
+ - spec/features/visitor/visitor_fails_to_sign_up_spec.rb
178
180
  - spec/features/visitor/visitor_is_unauthorized_spec.rb
179
181
  - spec/features/visitor/visitor_signs_up_spec.rb
180
182
  - spec/features/visitor/visitor_uses_remember_token_spec.rb
@@ -247,6 +249,7 @@ signing_key:
247
249
  specification_version: 4
248
250
  summary: Making rails authentication as simple as possible
249
251
  test_files:
252
+ - spec/features/visitor/visitor_fails_to_sign_up_spec.rb
250
253
  - spec/features/visitor/visitor_is_unauthorized_spec.rb
251
254
  - spec/features/visitor/visitor_signs_up_spec.rb
252
255
  - spec/features/visitor/visitor_uses_remember_token_spec.rb