entrance 0.4.8 → 0.5.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f93f2931fee64ff4cf3798c2773ded125d84494
4
+ data.tar.gz: 7fd53107e51f3c895724aa8534713747a49f90b7
5
+ SHA512:
6
+ metadata.gz: 5c201e15df23bbbbc24a089a5db10421cab3800846f48e7d12f6b6bf045e90979fa5084e627cb30d5c02066014a300ba97da90203f61136b12fb379420e63d41
7
+ data.tar.gz: cb5ee5269797176bc0b1ac999be9a84e747eb9674aea1377671ce95673140cbd27638d64f2429d0c8e36e4c46342ca5206f2b24707ca3e9ba9980f766c7d11d6
@@ -29,7 +29,7 @@ class User
29
29
 
30
30
  provides_entrance
31
31
 
32
- def active?
32
+ def can_login?
33
33
  state.to_sym == :active
34
34
  end
35
35
 
@@ -27,9 +27,11 @@ class User
27
27
  key :remember_token
28
28
  key :remember_token_expires_at, Time
29
29
 
30
+ ensure_index [[:auth_provider, 1], [:auth_uid, -1]], :unique => true
31
+
30
32
  provides_entrance :local => false, :remote => true
31
33
 
32
- def active?
34
+ def can_login?
33
35
  state.to_sym == :active
34
36
  end
35
37
 
@@ -40,7 +40,9 @@ module Entrance
40
40
 
41
41
  app.post '/login' do
42
42
  remember = ['on', 'true', '1'].include?(params[:remember])
43
- if user = authenticate_and_login(params[:username], params[:password], remember)
43
+ if params[:username].blank? or params[:password].blank?
44
+ redirect_with('/login', :error, "Both fields are required.")
45
+ elsif user = authenticate_and_login(params[:username], params[:password], remember)
44
46
  flash[:success] = 'Welcome back!'
45
47
  redirect_to_stored_or(to('/'))
46
48
  else
@@ -3,17 +3,16 @@ module Entrance
3
3
  class Config
4
4
 
5
5
  attr_accessor *%w(
6
- model cipher secret stretches
7
- unique_key username_attr password_attr salt_attr
8
- remember_token_attr remember_until_attr reset_token_attr reset_until_attr
6
+ model local_auth remote_auth cipher secret stretches
9
7
  access_denied_redirect_to access_denied_message_key
10
8
  reset_password_mailer reset_password_method reset_password_window remember_for
11
9
  cookie_domain cookie_secure cookie_path cookie_httponly
12
- name_attr auth_provider_attr auth_uid_attr
13
10
  )
14
11
 
15
12
  def initialize
16
13
  @model = 'User'
14
+ @local_auth = true
15
+ @remote_auth = false
17
16
 
18
17
  # strategies
19
18
  @cipher = Entrance::Ciphers::BCrypt # or Entrance::Ciphers::SHA1
@@ -53,9 +53,6 @@ module Entrance
53
53
  end
54
54
 
55
55
  Entrance.config.can?(what, true)
56
-
57
- mod = what.to_sym == :remember ? Entrance::Model::RememberMethods : Entrance::Model::ResetMethods
58
- Entrance.model.send(:include, mod)
59
56
  end
60
57
  end
61
58
 
@@ -8,10 +8,13 @@ module Entrance
8
8
  module ClassMethods
9
9
 
10
10
  def provides_entrance(options = {}, &block)
11
- Entrance.config.model = self.name
12
11
  local = options.delete(:local) != false # true by default
13
12
  remote = options.delete(:remote) == true # false by default
14
13
 
14
+ Entrance.config.model = self.name
15
+ Entrance.config.local_auth = local
16
+ Entrance.config.remote_auth = remote
17
+
15
18
  # if the target model class does not have a Model.where() method,
16
19
  # then login_by_session wont work, nor the ClassMethods below.
17
20
  # won't work so we cannot continue.
@@ -24,11 +27,11 @@ module Entrance
24
27
 
25
28
  # username and remember token are used both for local and remote (omniauth)
26
29
  fields.validate(:username)
27
- fields.validate_option(:remember)
30
+ include Entrance::Model::RememberMethods if fields.validate_option(:remember)
28
31
 
29
32
  if local # allows password & reset
30
33
  fields.validate(:password)
31
- fields.validate_option(:reset)
34
+ include Entrance::Model::ResetMethods if fields.validate_option(:reset)
32
35
 
33
36
  if self.respond_to?(:validates)
34
37
  validates :password, :presence => true, :length => 6..32, :if => :password_required?
@@ -44,6 +47,7 @@ module Entrance
44
47
  end
45
48
 
46
49
  def authenticate(username, password)
50
+ raise 'Local auth disabled!' unless Entrance.config.local_auth
47
51
  return if [username, password].any? { |v| v.nil? || v.strip == '' }
48
52
 
49
53
  query = {}
@@ -1,7 +1,7 @@
1
1
  module Entrance
2
2
  MAJOR = 0
3
- MINOR = 4
4
- PATCH = 8
3
+ MINOR = 5
4
+ PATCH = 0
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entrance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tomás Pollak
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-03-20 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bcrypt
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '3.0'
30
27
  description: Doesn't fiddle with your controllers and routes.
@@ -34,7 +31,7 @@ executables: []
34
31
  extensions: []
35
32
  extra_rdoc_files: []
36
33
  files:
37
- - .gitignore
34
+ - ".gitignore"
38
35
  - README.md
39
36
  - Rakefile
40
37
  - entrance.gemspec
@@ -132,26 +129,26 @@ files:
132
129
  - spec/fake_model.rb
133
130
  homepage: https://github.com/tomas/entrance
134
131
  licenses: []
132
+ metadata: {}
135
133
  post_install_message:
136
134
  rdoc_options: []
137
135
  require_paths:
138
136
  - lib
139
137
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
138
  requirements:
142
- - - ! '>='
139
+ - - ">="
143
140
  - !ruby/object:Gem::Version
144
141
  version: '0'
145
142
  required_rubygems_version: !ruby/object:Gem::Requirement
146
- none: false
147
143
  requirements:
148
- - - ! '>='
144
+ - - ">="
149
145
  - !ruby/object:Gem::Version
150
146
  version: 1.3.6
151
147
  requirements: []
152
148
  rubyforge_project: entrance
153
- rubygems_version: 1.8.23
149
+ rubygems_version: 2.2.0
154
150
  signing_key:
155
- specification_version: 3
151
+ specification_version: 4
156
152
  summary: Lean authentication alternative for Rails and Sinatra.
157
153
  test_files: []
154
+ has_rdoc: