entrance 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/examples/sinatra-app/app/routes.rb +3 -3
- data/examples/sinatra-app/config.ru +1 -1
- data/lib/entrance/ciphers.rb +0 -1
- data/lib/entrance/config.rb +2 -2
- data/lib/entrance/controller.rb +7 -5
- data/lib/entrance/model.rb +15 -17
- data/lib/entrance/version.rb +1 -1
- metadata +2 -2
data/.gitignore
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
%w(./app/models
|
1
|
+
%w(./app/models sinatra/base sinatra/flash entrance).each { |lib| require lib }
|
2
2
|
|
3
3
|
module Example
|
4
4
|
|
@@ -46,7 +46,7 @@ module Example
|
|
46
46
|
login!(user, remember)
|
47
47
|
|
48
48
|
flash[:success] = 'Welcome back!'
|
49
|
-
|
49
|
+
redirect_to_stored_or to('/')
|
50
50
|
else
|
51
51
|
flash[:error] = "Couldn't log you in. Please try again."
|
52
52
|
redirect to('/login')
|
@@ -61,4 +61,4 @@ module Example
|
|
61
61
|
|
62
62
|
end
|
63
63
|
|
64
|
-
end
|
64
|
+
end
|
data/lib/entrance/ciphers.rb
CHANGED
data/lib/entrance/config.rb
CHANGED
@@ -28,8 +28,8 @@ module Entrance
|
|
28
28
|
@access_denied_message_key = nil # e.g. 'messages.access_denied'
|
29
29
|
@reset_password_mailer = 'UserMailer'
|
30
30
|
@reset_password_method = 'reset_password_request'
|
31
|
-
@reset_password_window = 1.hour
|
32
|
-
@remember_for = 2.weeks
|
31
|
+
@reset_password_window = 60 * 60 # 1.hour
|
32
|
+
@remember_for = 60 * 24 * 14 # 2.weeks
|
33
33
|
@cookie_domain = nil
|
34
34
|
@cookie_secure = true
|
35
35
|
@cookie_path = '/'
|
data/lib/entrance/controller.rb
CHANGED
@@ -96,12 +96,13 @@ module Entrance
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def store_location
|
99
|
-
|
99
|
+
path = request.fullpath
|
100
|
+
session[:return_to] = path unless ['/favicon.ico'].include?(path)
|
100
101
|
end
|
101
102
|
|
102
103
|
def redirect_to_stored_or(default_path)
|
103
|
-
|
104
|
-
|
104
|
+
stored = session.delete(:return_to)
|
105
|
+
common_redirect(stored || default_path, true)
|
105
106
|
end
|
106
107
|
|
107
108
|
def redirect_to_back_or(default_path)
|
@@ -162,9 +163,10 @@ module Entrance
|
|
162
163
|
end
|
163
164
|
end
|
164
165
|
|
165
|
-
|
166
|
+
# when redirecting to stored_path
|
167
|
+
def common_redirect(url, with_base = false)
|
166
168
|
if respond_to?(:redirect)
|
167
|
-
redirect(to(url)) # sinatra
|
169
|
+
return with_base ? redirect(url) : redirect(to(url)) # sinatra
|
168
170
|
else
|
169
171
|
redirect_to(url) # rails
|
170
172
|
end
|
data/lib/entrance/model.rb
CHANGED
@@ -1,30 +1,27 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
1
|
module Entrance
|
4
2
|
module Model
|
5
|
-
extend ActiveSupport::Concern
|
6
3
|
|
7
|
-
included
|
4
|
+
def self.included(base)
|
8
5
|
|
9
6
|
# if the target model class does not have a Model.where() method,
|
10
7
|
# then login_by_session wont work, nor the ClassMethods below.
|
11
8
|
# won't work so we cannot continue.
|
12
|
-
unless respond_to?(:where)
|
13
|
-
raise "#{
|
9
|
+
unless base.respond_to?(:where)
|
10
|
+
raise "#{base.name} does not have a .where() class method. Cannot continue."
|
14
11
|
end
|
15
12
|
|
16
|
-
fields = if
|
17
|
-
|
18
|
-
elsif
|
19
|
-
|
13
|
+
fields = if base.respond_to?(:columns) # ActiveRecord::Base
|
14
|
+
base.columns.collect(&:name)
|
15
|
+
elsif base.respond_to?(:keys) # MongoMapper::Document
|
16
|
+
base.keys.keys
|
20
17
|
else # just get setters in the class
|
21
|
-
|
18
|
+
base.instance_methods(false).select { |m| m[/\=$/] }.map { |s| s.sub('=', '') }
|
22
19
|
end.map { |el| el.to_sym }
|
23
20
|
|
24
21
|
%w(username_attr password_attr).each do |key|
|
25
22
|
field = Entrance.config.send(key)
|
26
23
|
unless fields.include?(field.to_sym)
|
27
|
-
raise "Couldn't find '#{field}' in #{
|
24
|
+
raise "Couldn't find '#{field}' in #{base.name} model."
|
28
25
|
end
|
29
26
|
end
|
30
27
|
|
@@ -46,16 +43,17 @@ module Entrance
|
|
46
43
|
end
|
47
44
|
|
48
45
|
Entrance.config.can?(what, true)
|
49
|
-
include what.to_sym == :remember ? RememberMethods : ResetMethods
|
46
|
+
base.include what.to_sym == :remember ? RememberMethods : ResetMethods
|
50
47
|
end
|
51
48
|
end
|
52
49
|
|
53
|
-
if respond_to?(:validates)
|
54
|
-
validates :password, :presence => true, :length => 6..32, :if => :password_required?
|
55
|
-
validates :password, :confirmation => true, :if => :password_required?
|
56
|
-
validates :password_confirmation, :presence => true, :if => :password_required?
|
50
|
+
if base.respond_to?(:validates)
|
51
|
+
base.validates :password, :presence => true, :length => 6..32, :if => :password_required?
|
52
|
+
base.validates :password, :confirmation => true, :if => :password_required?
|
53
|
+
base.validates :password_confirmation, :presence => true, :if => :password_required?
|
57
54
|
end
|
58
55
|
|
56
|
+
base.extend(ClassMethods)
|
59
57
|
end
|
60
58
|
|
61
59
|
module ClassMethods
|
data/lib/entrance/version.rb
CHANGED