entrance 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,10 +13,9 @@ Clean, adaptable authentication library for Rails and Sinatra.
13
13
  require 'entrance'
14
14
 
15
15
  Entrance.configure do |config|
16
- config.username_attr = 'email'
17
- config.password_attr = 'password_hash' # make sure you map the right attribute name
18
- config.access_denied_message_key = 'messages.access_denied'
16
+ config.access_denied_redirect_to = '/login'
19
17
  config.remember_for = 1.month
18
+ config.reset_password_window = 2.hours
20
19
  config.cookie_secure = Rails.env.production?
21
20
  end
22
21
 
@@ -37,7 +36,10 @@ class User
37
36
 
38
37
  ... (setup fields)
39
38
 
40
- validate_entrance! # ensures fields for authentication/remember/reset are present
39
+ provides_entrance do |fields|
40
+ fields.username = :email
41
+ fields.password = :password
42
+ end
41
43
  end
42
44
  ```
43
45
 
@@ -84,23 +86,22 @@ All available options, along with their defaults.
84
86
 
85
87
  ``` rb
86
88
  Entrance.configure do |config|
87
- config.model = 'User'
89
+ # strategies
88
90
  config.cipher = Entrance::Ciphers::BCrypt # can also be Entrance::Ciphers::SHA1
89
91
  config.secret = nil
90
92
  config.stretches = 10
91
- config.salt_attr = nil
92
- config.username_attr = 'email'
93
- config.password_attr = 'password_hash'
94
- config.remember_token_attr = 'remember_token'
95
- config.remember_until_attr = 'remember_token_expires_at'
96
- config.reset_token_attr = 'reset_token'
97
- config.reset_until_attr = 'reset_token_expires_at'
98
- config.access_denied_redirect_to = '/'
99
- config.access_denied_message_key = nil
93
+
94
+ # access denied
95
+ config.access_denied_redirect_to = '/login'
96
+ config.access_denied_message_key = nil # e.g. 'messages.access_denied'
97
+
98
+ # reset password
100
99
  config.reset_password_mailer = 'UserMailer'
101
100
  config.reset_password_method = 'reset_password_request'
102
- config.reset_password_window = 1.hour
103
- config.remember_for = 2.weeks
101
+ config.reset_password_window = 60 * 60 # 1.hour
102
+
103
+ # remember me & cookies
104
+ config.remember_for = 60 * 24 * 14 # 2.weeks
104
105
  config.cookie_domain = nil
105
106
  config.cookie_secure = true
106
107
  config.cookie_path = '/'
@@ -108,6 +109,33 @@ Entrance.configure do |config|
108
109
  end
109
110
  ```
110
111
 
112
+ ## Entrance::Fields
113
+
114
+ As declared in your model. Options and their defaults are:
115
+
116
+ ``` rb
117
+ provides_entrance do |fields|
118
+ # base
119
+ fields.unique_key = 'id'
120
+ fields.salt = nil # only required for SHA1 strategy
121
+
122
+ # username & password
123
+ fields.name = 'name' # only used by omniauth addon
124
+ fields.username = 'email'
125
+ fields.password = 'password_hash'
126
+
127
+ # remember and reset
128
+ fields.remember_token = 'remember_token'
129
+ fields.remember_until = 'remember_token_expires_at'
130
+ fields.reset_token = 'reset_token'
131
+ fields.reset_until = 'reset_token_expires_at'
132
+
133
+ # omniauth
134
+ fields.auth_provider = 'auth_provider'
135
+ fields.auth_uid = 'auth_uid'
136
+ end
137
+ ```
138
+
111
139
  ## Entrance::Controller
112
140
 
113
141
  When including it into your controller, this module will provide the following methods:
@@ -127,7 +155,7 @@ And the following helpers:
127
155
 
128
156
  Provides:
129
157
 
130
- - .validate_entrance!
158
+ - .provides_entrance(&block)
131
159
  - .authenticate(username, password)
132
160
  - .with_password_reset_token(token)
133
161
  - #password and #password=(value)
@@ -51,7 +51,9 @@ module Entrance
51
51
 
52
52
  app.settings.auth_providers.each do |name, options|
53
53
  # puts "Initializing #{name} provider: #{options.inspect}"
54
- provider(name, options)
54
+ # omniauth expects provider(:name, arg1, arg2, arg3), so we need to map only the values
55
+ opts = options && options.any? ? options.values : []
56
+ provider(name, *opts)
55
57
  end
56
58
  end
57
59
 
@@ -1,7 +1,7 @@
1
1
  module Entrance
2
2
  MAJOR = 0
3
3
  MINOR = 4
4
- PATCH = 0
4
+ PATCH = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entrance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: