entrance 0.2.3 → 0.2.4

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.
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  .DS_Store
2
+ pkg
3
+ Gemfile.lock
@@ -1,4 +1,4 @@
1
- %w(./app/models logger sinatra/base sinatra/flash entrance).each { |lib| require lib }
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
- redirect(session[:return_to] || to('/'))
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
@@ -1,5 +1,5 @@
1
1
  require './app/routes'
2
2
 
3
3
  map '/' do
4
- run Example::Routes
4
+ run Example::Routes
5
5
  end
@@ -1,4 +1,3 @@
1
-
2
1
  module Entrance
3
2
 
4
3
  module Ciphers
@@ -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 = '/'
@@ -96,12 +96,13 @@ module Entrance
96
96
  end
97
97
 
98
98
  def store_location
99
- session[:return_to] = request.fullpath
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
- common_redirect(session[:return_to] || default_path)
104
- session[:return_to] = nil
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
- def common_redirect(url)
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
@@ -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 do
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 "#{Entrance.config.model} does not have a class .where() method. Cannot continue."
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 self.respond_to?(:columns) # ActiveRecord::Base
17
- self.columns.collect(&:name)
18
- elsif self.respond_to?(:keys) # MongoMapper::Document
19
- self.keys.keys
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
- self.instance_methods(false).select { |m| m[/\=$/] }.map { |s| s.sub('=', '') }
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 #{Entrance.config.model} model."
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
@@ -1,7 +1,7 @@
1
1
  module Entrance
2
2
  MAJOR = 0
3
3
  MINOR = 2
4
- PATCH = 3
4
+ PATCH = 4
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Tom\xC3\xA1s Pollak"