merb-auth-more 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -2
- data/Rakefile +4 -2
- data/lib/merb-auth-more/mixins/redirect_back.rb +24 -10
- data/lib/merb-auth-more/mixins/salted_user.rb +5 -0
- data/lib/merb-auth-more/mixins/salted_user/relaxdb_salted_user.rb +34 -0
- data/lib/merb-auth-more/strategies/basic/password_form.rb +5 -1
- data/spec/mixins/redirect_back_spec.rb +2 -3
- metadata +6 -5
data/README.textile
CHANGED
@@ -10,7 +10,7 @@ Strategies are really simple to implement, but we've made some basic ones availa
|
|
10
10
|
|
11
11
|
The built in ones are basic but should be enough to get you going for most things.
|
12
12
|
|
13
|
-
To specify them, simply require them. For example,in
|
13
|
+
To specify them, simply require them. For example,in Merb.root/merb/merb-auth/strategies.rb
|
14
14
|
|
15
15
|
<pre><code>
|
16
16
|
Merb::Authentication.activate!(:default_password_form)
|
@@ -33,7 +33,7 @@ h3. "User" mixins
|
|
33
33
|
|
34
34
|
To assist with your authenticating needs, there is user mixins available to enhance your user model
|
35
35
|
for basic cases. These really are just for the basic case, so if you need something extra you should
|
36
|
-
overwrite the methods, or implement
|
36
|
+
overwrite the methods, or implement your requirements.
|
37
37
|
|
38
38
|
To use these, require the specific mixin, and then include it into your "User" class.
|
39
39
|
|
data/Rakefile
CHANGED
@@ -10,7 +10,9 @@ require 'rake/testtask'
|
|
10
10
|
require File.join(File.dirname(__FILE__), "../../merb-core/lib/merb-core/version.rb")
|
11
11
|
|
12
12
|
GEM_NAME = "merb-auth-more"
|
13
|
-
|
13
|
+
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
14
|
+
GEM_VERSION = Merb::VERSION + PKG_BUILD
|
15
|
+
|
14
16
|
AUTHOR = "Daniel Neighman"
|
15
17
|
EMAIL = "has.sox@gmail.com"
|
16
18
|
HOMEPAGE = "http://merbivore.com/"
|
@@ -28,7 +30,7 @@ spec = Gem::Specification.new do |s|
|
|
28
30
|
s.author = AUTHOR
|
29
31
|
s.email = EMAIL
|
30
32
|
s.homepage = HOMEPAGE
|
31
|
-
s.add_dependency("merb-auth-core", "
|
33
|
+
s.add_dependency("merb-auth-core", ">= #{Merb::VERSION}")
|
32
34
|
s.require_path = 'lib'
|
33
35
|
s.files = %w(LICENSE README.textile Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
34
36
|
|
@@ -31,22 +31,31 @@ module Merb::AuthenticatedHelper
|
|
31
31
|
redirect default_url, opts
|
32
32
|
end
|
33
33
|
session.authentication.return_to_url = nil
|
34
|
+
"Redirecting to <a href='#{default_url}'>#{default_url}</a>"
|
34
35
|
end
|
35
36
|
|
36
37
|
end
|
37
38
|
|
39
|
+
# This mixin is mixed into the Exceptions controller to setup the correct methods
|
40
|
+
# And filters. It is implemented as a mixin so that it is completely overwritable in
|
41
|
+
# your controllers
|
42
|
+
module Merb::Authentication::Mixins
|
43
|
+
module RedirectBack
|
44
|
+
def self.included(base)
|
45
|
+
base.class_eval do
|
46
|
+
after :_set_return_to, :only => :unauthenticated
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def _set_return_to
|
52
|
+
session.authentication.return_to_url ||= request.uri unless request.exceptions.blank?
|
53
|
+
end
|
38
54
|
|
39
|
-
|
40
|
-
|
41
|
-
class Exceptions < Application
|
42
|
-
after :_set_return_to, :only => :unauthenticated
|
43
|
-
|
44
|
-
private
|
45
|
-
def _set_return_to
|
46
|
-
session.authentication.return_to_url ||= request.uri unless request.exceptions.blank?
|
47
|
-
end
|
48
|
-
end
|
55
|
+
end # RedirectBack
|
56
|
+
end # Merb::Authentication::Mixins
|
49
57
|
|
58
|
+
# Adds required methods to the Authentication object for redirection
|
50
59
|
class Merb::Authentication
|
51
60
|
|
52
61
|
def return_to_url
|
@@ -56,4 +65,9 @@ class Merb::Authentication
|
|
56
65
|
def return_to_url=(return_url)
|
57
66
|
@return_to_url = session[:return_to] = return_url
|
58
67
|
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Mixin the RedirectBack mixin before the after_app_loads block (i.e. make sure there is an exceptions controller)
|
71
|
+
Merb::Authentication.customize_default do
|
72
|
+
Exceptions.class_eval{ include Merb::Authentication::Mixins::RedirectBack }
|
59
73
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require "digest/sha1"
|
2
|
+
require File.expand_path(File.dirname(__FILE__) / "..") / "strategies" / "abstract_password"
|
3
|
+
|
2
4
|
class Merb::Authentication
|
3
5
|
module Mixins
|
4
6
|
# This mixin provides basic salted user password encryption.
|
@@ -33,6 +35,9 @@ class Merb::Authentication
|
|
33
35
|
elsif defined?(Sequel) && ancestors.include?(Sequel::Model)
|
34
36
|
require path / "sq_salted_user"
|
35
37
|
extend(Merb::Authentication::Mixins::SaltedUser::SQClassMethods)
|
38
|
+
elsif defined?(RelaxDB) && ancestors.include?(RelaxDB::Document)
|
39
|
+
require path / "relaxdb_salted_user"
|
40
|
+
extend(Merb::Authentication::Mixins::SaltedUser::RDBClassMethods)
|
36
41
|
end
|
37
42
|
|
38
43
|
end # base.class_eval
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Merb::Authentication
|
2
|
+
module Mixins
|
3
|
+
module SaltedUser
|
4
|
+
module RDBClassMethods
|
5
|
+
|
6
|
+
def self.extended(base)
|
7
|
+
base.class_eval do
|
8
|
+
|
9
|
+
property :crypted_password
|
10
|
+
property :salt
|
11
|
+
|
12
|
+
before_save :password_checks
|
13
|
+
|
14
|
+
def password_checks
|
15
|
+
if password_required?
|
16
|
+
return false unless !password.blank? && password == password_confirmation
|
17
|
+
end
|
18
|
+
encrypt_password
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def authenticate(login, password)
|
26
|
+
login_param = Merb::Authentication::Strategies::Basic::Base.login_param
|
27
|
+
@u = all.sorted_by(login_param) { |q| q.key(login) }.first
|
28
|
+
@u && @u.authenticated?(password) ? @u : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end # RDBClassMethods
|
32
|
+
end # SaltedUser
|
33
|
+
end # Mixins
|
34
|
+
end # Merb::Authentication
|
@@ -20,12 +20,16 @@ class Merb::Authentication
|
|
20
20
|
user = user_class.authenticate(request.params[login_param], request.params[password_param])
|
21
21
|
if !user
|
22
22
|
request.session.authentication.errors.clear!
|
23
|
-
request.session.authentication.errors.add(login_param,
|
23
|
+
request.session.authentication.errors.add(login_param, strategy_error_message)
|
24
24
|
end
|
25
25
|
user
|
26
26
|
end
|
27
27
|
end # run!
|
28
28
|
|
29
|
+
def strategy_error_message
|
30
|
+
"#{login_param.to_s.capitalize} or #{password_param.to_s.capitalize} were incorrect"
|
31
|
+
end
|
32
|
+
|
29
33
|
end # Form
|
30
34
|
end # Password
|
31
35
|
end # Strategies
|
@@ -15,15 +15,14 @@ describe "redirect_back" do
|
|
15
15
|
|
16
16
|
class Application < Merb::Controller; end
|
17
17
|
|
18
|
-
class Exceptions <
|
18
|
+
class Exceptions < Merb::Controller
|
19
|
+
include Merb::Authentication::Mixins::RedirectBack
|
19
20
|
def unauthenticated; end
|
20
21
|
end
|
21
22
|
|
22
23
|
class MyController < Application
|
23
24
|
before :ensure_authenticated
|
24
|
-
|
25
25
|
def index; "HERE!" end
|
26
|
-
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-auth-more
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Neighman
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-21 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.10
|
24
24
|
version:
|
25
25
|
description: Additional resources for use with the merb-auth-core authentication framework.
|
26
26
|
email: has.sox@gmail.com
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/merb-auth-more/mixins/salted_user
|
45
45
|
- lib/merb-auth-more/mixins/salted_user/ar_salted_user.rb
|
46
46
|
- lib/merb-auth-more/mixins/salted_user/dm_salted_user.rb
|
47
|
+
- lib/merb-auth-more/mixins/salted_user/relaxdb_salted_user.rb
|
47
48
|
- lib/merb-auth-more/mixins/salted_user/sq_salted_user.rb
|
48
49
|
- lib/merb-auth-more/mixins/salted_user.rb
|
49
50
|
- lib/merb-auth-more/strategies
|
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
81
|
requirements: []
|
81
82
|
|
82
83
|
rubyforge_project: merb
|
83
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.3.0
|
84
85
|
signing_key:
|
85
86
|
specification_version: 2
|
86
87
|
summary: Additional resources for use with the merb-auth-core authentication framework.
|