scottmotte-merb-auth-remember-me 0.0.2 → 0.1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
File without changes
data/README.markdown ADDED
@@ -0,0 +1,51 @@
1
+ ### PnMerbAuthRememberMe
2
+
3
+ This plugin provides a remember me function based on MerbAuth. Most of codes are from [RestfulAuthentication on Rails](http://github.com/technoweenie/restful-authentication/tree/master)
4
+
5
+ This plugin adds a mixin that you should include in your user model to provide 2 fields to remember the token and time to expire. The mixin will automatically select the correct sub mixin for all supported orms.
6
+
7
+ <pre><code>class User
8
+ include DataMapper::Resource
9
+ include Merb::Authentication::Mixins::AuthenticatedUser
10
+
11
+ property :id, Serial
12
+ end
13
+ </code></pre>
14
+
15
+ ### Migration Requirements
16
+
17
+ The mixin requires some fields to be in-place on your model. Where needed include these in your migrations.
18
+ <pre><code> :remember_token_expires_at, DateTime
19
+ :remember_token, String
20
+ </code></pre>
21
+
22
+ ### Configuration Options
23
+
24
+ declare in your _merb/merb-auth/strategies.rb_ file
25
+
26
+ Merb::Authentication.activate!(:remember_me)
27
+
28
+
29
+ ------------------------------------------------------------------------------
30
+
31
+ ### Instructions for installation:
32
+
33
+ Rake tasks to package/install the gem - edit this to modify the manifest.
34
+
35
+ file: config/dependencies.rb
36
+
37
+ \# add the plugin as a regular dependency
38
+
39
+ dependency 'merb-auth-remember-me'
40
+
41
+ file: slice/merb-auth-slice-password/app/controllers/sessions.rb or the logout action
42
+
43
+ \# clear :auth\_token after log out
44
+
45
+ cookies.delete :auth_token
46
+
47
+ In your unauthenticated.html.erb(Login page)
48
+
49
+ %input#rememberme{ :name => "remember_me" , :type => "checkbox", :value => "1"}
50
+ Remember Me
51
+
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
1
  require 'rubygems'
2
2
  require 'rake/gempackagetask'
3
- require 'spec/rake/spectask'
4
3
 
5
4
  require 'merb-core'
6
5
  require 'merb-core/tasks/merb'
7
6
 
8
7
  GEM_NAME = "merb-auth-remember-me"
9
- GEM_VERSION = "0.0.2"
10
- AUTHOR = "Surasit Liangpornrattana"
11
- EMAIL = "punneng@gmail.com"
12
- HOMEPAGE = "https://github.com/PunNeng/pn-merb-auth-remember-me"
8
+ GEM_VERSION = "0.1.3.2"
9
+ AUTHOR = "Jacques Crocker"
10
+ ORIGINAL_AUTHOR = "Surasit Liangpornrattana"
11
+ EMAIL = "merbjedi@gmail.com"
12
+ HOMEPAGE = "https://github.com/merbjedi/merb-auth-remember-me"
13
13
  SUMMARY = "Merb plugin that provides remember me for merb-auth-slice-password"
14
14
 
15
15
  spec = Gem::Specification.new do |s|
@@ -18,15 +18,16 @@ spec = Gem::Specification.new do |s|
18
18
  s.version = GEM_VERSION
19
19
  s.platform = Gem::Platform::RUBY
20
20
  s.has_rdoc = true
21
- s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
21
+ s.extra_rdoc_files = ["README.markdown", "LICENSE", 'TODO']
22
22
  s.summary = SUMMARY
23
23
  s.description = s.summary
24
- s.author = AUTHOR
24
+ s.authors = [AUTHOR, ORIGINAL_AUTHOR]
25
25
  s.email = EMAIL
26
26
  s.homepage = HOMEPAGE
27
- s.add_dependency('merb-core', '>= 1.0')
27
+ s.add_dependency('merb-core', '>= 1.0.9')
28
28
  s.require_path = 'lib'
29
- s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
29
+ s.files = %w(LICENSE README.markdown Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
30
+
30
31
  end
31
32
 
32
33
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -49,9 +50,3 @@ task :gemspec do
49
50
  file.puts spec.to_ruby
50
51
  end
51
52
  end
52
-
53
- Spec::Rake::SpecTask.new do |t|
54
- t.warning = true
55
- t.spec_opts = ["--format", "specdoc", "--colour"]
56
- t.spec_files = Dir['spec/**/*_spec.rb'].sort
57
- end
data/TODO CHANGED
@@ -1,2 +0,0 @@
1
- TODO:
2
- make token refresh with each request ??
@@ -1,35 +1,35 @@
1
+ # make sure we're running inside Merb
1
2
  if defined?(Merb::Plugins)
3
+
2
4
  $:.unshift File.dirname(__FILE__)
3
5
 
4
- # register the authentication strategy
5
6
  require(File.expand_path(File.dirname(__FILE__) / "merb-auth-remember-me" / "mixins") / "authenticated_user")
6
7
  strategy_path = File.expand_path(File.dirname(__FILE__)) / "merb-auth-remember-me" / "strategies"
7
- Merb.logger.info('Registering and activating RememberMe strategy')
8
+
8
9
  Merb::Authentication.register(:remember_me, strategy_path / "remember_me.rb")
9
- Merb::Authentication.activate!(:remember_me) # and activate it
10
+ # require(strategy_path / "remember_me.rb")
10
11
 
11
- # Plugin configurations
12
- Merb::Plugins.config[:merb_auth_remember_me] = {:include_model_methods => true }
12
+ Merb::Plugins.add_rakefiles "merb-auth-remember-me/merbtasks"#, "merb-auth-remember-me/slicetasks", "merb-auth-remember-me/spectasks"
13
+
14
+ # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
15
+ Merb::Plugins.config[:pn_merb_auth_remember_me] = {
16
+ :chickens => false
17
+ }
18
+
19
+ Merb::BootLoader.before_app_loads do
20
+ # require code that must be loaded before the application
21
+ end
13
22
 
14
23
  Merb::BootLoader.after_app_loads do
24
+ # code that can be required after the application loads
15
25
  Merb::Authentication.after_authentication do |user,request,params|
16
26
  if params[:remember_me] == "1"
17
27
  user.remember_me
18
- request.cookies.set_cookie(
19
- :auth_token,
20
- user.remember_token,
21
- :expires => user.remember_token_expires_at.to_time
22
- )
28
+ request.cookies.set_cookie(:auth_token, user.remember_token, :expires => user.remember_token_expires_at.to_time)
23
29
  end
24
30
  user
25
- end # Merb::Authentication.after_authentication
26
-
27
- Merb::Authentication.user_class.class_eval do
28
- if Merb::Plugins.config[:merb_auth_remember_me][:include_model_methods]
29
- Merb.logger.info("Including RememberMe Mixin in #{Merb::Authentication.user_class}.
30
- To avoid this inclusion add 'Merb::Plugins.config[:merb_auth_remember_me][:include_model_methods] = false' in your config/init.rb before_app_loads method")
31
- include Merb::Authentication::Mixins::AuthenticatedUser
32
- end
33
- end # Merb::Authentication.user_class.class_eval
34
- end # Merb::BootLoader.after_app_loads
35
- end # if defined?(Merb::Plugins)
31
+ end
32
+ end
33
+
34
+ Merb::Plugins.add_rakefiles "merb-auth-remember-me/merbtasks"
35
+ end
@@ -0,0 +1,6 @@
1
+ namespace :pn_remember_me do
2
+ desc "Do something for merb-auth-remember-me"
3
+ task :default do
4
+ puts "merb-auth-remember-me doesn't do anything"
5
+ end
6
+ end
@@ -57,7 +57,7 @@ module Merb
57
57
  module InstanceMethods
58
58
  def remember_token?
59
59
  (!remember_token.blank?) &&
60
- remember_token_expires_at && (Time.now.utc < remember_token_expires_at.utc)
60
+ remember_token_expires_at && (DateTime.now < remember_token_expires_at)
61
61
  end
62
62
 
63
63
  # These create and unset the fields required for remembering users between browser closes
@@ -14,4 +14,4 @@ module Merb
14
14
  end # AuthenticatedUser
15
15
  end # Mixins
16
16
  end # Authentication
17
- end #Merb
17
+ end #Merb
@@ -1,12 +1,53 @@
1
- module Merb::Authentication::Strategies
2
- class RememberMeStrategy < Merb::Authentication::Strategy
3
- def run!
4
- if cookies[:auth_token]
5
- user = Merb::Authentication.user_class.first(
6
- :conditions => [ "remember_token = ?", cookies[:auth_token] ]
7
- )
8
- end
9
- user && user.remembered? ? user : nil
10
- end # run!
11
- end # RememberMeStrategy
12
- end # Merb::Authentication::Strategies
1
+ class RememberMe < Merb::Authentication::Strategy
2
+
3
+ # Called from #current_user. Finaly, attempt to login by an expiring token in the cookie.
4
+ # for the paranoid: we _should_ be storing user_token = hash(cookie_token, request IP)
5
+ def run!
6
+ current_user = cookies[:auth_token] && Merb::Authentication.user_class.first(:conditions => ["remember_token = ?", cookies[:auth_token]])
7
+ if current_user && current_user.remember_token?
8
+ handle_remember_cookie! false # freshen cookie token (keeping date)
9
+ current_user
10
+ end
11
+ end
12
+
13
+ def current_user
14
+ @current_user
15
+ end
16
+
17
+ def current_user=(new_user)
18
+ @current_user = new_user
19
+ end
20
+
21
+ #
22
+ # Remember_me Tokens
23
+ #
24
+ # Cookies shouldn't be allowed to persist past their freshness date,
25
+ # and they should be changed at each login
26
+
27
+ # Cookies shouldn't be allowed to persist past their freshness date,
28
+ # and they should be changed at each login
29
+
30
+ def valid_remember_cookie?
31
+ return nil unless current_user
32
+ (current_user.remember_token?) &&
33
+ (cookies[:auth_token] == current_user.remember_token)
34
+ end
35
+
36
+ # Refresh the cookie auth token if it exists, create it otherwise
37
+ def handle_remember_cookie! new_cookie_flag
38
+ return unless current_user
39
+ case
40
+ when valid_remember_cookie? then current_user.refresh_token # keeping same expiry date
41
+ when new_cookie_flag then current_user.remember_me
42
+ else current_user.forget_me
43
+ end
44
+ send_remember_cookie!
45
+ end
46
+
47
+ def send_remember_cookie!
48
+ cookies.set_cookie(:auth_token, current_user.remember_token, :expires => current_user.remember_token_expires_at.to_time)
49
+ end
50
+
51
+
52
+ end
53
+
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
File without changes
File without changes
metadata CHANGED
@@ -1,9 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scottmotte-merb-auth-remember-me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.3.2
5
5
  platform: ruby
6
6
  authors:
7
+ - Jacques Crocker
7
8
  - Surasit Liangpornrattana
8
9
  autorequire:
9
10
  bindir: bin
@@ -20,24 +21,25 @@ dependencies:
20
21
  requirements:
21
22
  - - ">="
22
23
  - !ruby/object:Gem::Version
23
- version: "1.0"
24
+ version: 1.0.9
24
25
  version:
25
26
  description: Merb plugin that provides remember me for merb-auth-slice-password
26
- email: punneng@gmail.com
27
+ email: merbjedi@gmail.com
27
28
  executables: []
28
29
 
29
30
  extensions: []
30
31
 
31
32
  extra_rdoc_files:
32
- - README
33
+ - README.markdown
33
34
  - LICENSE
34
35
  - TODO
35
36
  files:
36
37
  - LICENSE
37
- - README
38
+ - README.markdown
38
39
  - Rakefile
39
40
  - TODO
40
41
  - lib/merb-auth-remember-me
42
+ - lib/merb-auth-remember-me/merbtasks.rb
41
43
  - lib/merb-auth-remember-me/mixins
42
44
  - lib/merb-auth-remember-me/mixins/authenticated_user
43
45
  - lib/merb-auth-remember-me/mixins/authenticated_user/ar_authenticated_user.rb
@@ -55,7 +57,7 @@ files:
55
57
  - spec/strategies
56
58
  - spec/strategies/remember_me_spec.rb
57
59
  has_rdoc: false
58
- homepage: https://github.com/PunNeng/pn-merb-auth-remember-me
60
+ homepage: https://github.com/merbjedi/merb-auth-remember-me
59
61
  post_install_message:
60
62
  rdoc_options: []
61
63
 
data/README DELETED
@@ -1,43 +0,0 @@
1
- ### MerbAuthRememberMe
2
-
3
- This plugin provides a remember me strategy for Merb Auth. The original plugin was built by Pun Neng (http://github.com/PunNeng/).
4
-
5
- The plugin also provides some Merb::Authentication.user_class mixins to keep the models fat and the strategy code thin. The mixins are added to the user class by default. If you choose not to include these and would rather roll your own set the plugin configuration in your config/init.rb file like so:
6
- <pre><code>
7
- Merb::Plugins.config[:merb_auth_remember_me][:include_model_methods] = false
8
- </code></pre>
9
-
10
- This plugin automatically registers and activates the remember_me strategy with Merb Auth, so no additional configuration is necessary.
11
-
12
- ### Migration Requirements
13
-
14
- The plugin requires some fields your user authentication model. Right now there is ORM specific inclusions for Datamapper. The Sequel one needs to be built and a migration needs to be made for ActiveRecord. No migration generators are included but the plugin requires the following fields
15
- <pre><code>
16
- DateTime :remember_token_expires_at
17
- String :remember_token
18
- </code></pre>
19
-
20
- ------------------------------------------------------------------------------
21
-
22
- ### Instructions for installation:
23
-
24
- # Add the plugin as a regular dependency in your dependency.rb file
25
-
26
- dependency 'rughetto-merb-auth-remember-me', :require_as => 'merb-auth-remember-me'
27
-
28
- # To clear the :auth\_token after log out
29
-
30
- Unpack the merb-auth-password application code if it hasn't been done already:
31
- <pre><code>
32
- bin/rake slices:merb-auth-slice-password:freeze
33
- </code></pre>
34
-
35
- Change the #destroy method in slices/merb-auth-slice-password/app/controllers/session_override.rb to include
36
- <pre><code>
37
- cookies.delete :auth_token
38
- </code></pre>
39
-
40
- # Add the right form inputs into your unauthenticated.html.erb (login) page
41
-
42
- <input type="checkbox" id="remember_me" name="remember_me" value="1">
43
-