authentasaurus 0.8.4 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELIST +6 -2
- data/TODO +2 -0
- data/app/controllers/sessions_controller.rb +1 -1
- data/app/models/authentasaurus_emailer.rb +6 -6
- data/app/models/{session.rb → authentasaurus_session.rb} +1 -1
- data/app/views/authentasaurus_emailer/invitation_mail.html.erb +2 -2
- data/app/views/authentasaurus_emailer/recovery_mail.html.erb +2 -2
- data/app/views/authentasaurus_emailer/validation_mail.html.erb +2 -2
- data/lib/authentasaurus.rb +5 -1
- data/lib/authentasaurus/ac/acts_as_overrider.rb +6 -5
- data/lib/authentasaurus/ac/controllers/areas_controller.rb +52 -57
- data/lib/authentasaurus/ac/controllers/groups_controller.rb +55 -59
- data/lib/authentasaurus/ac/controllers/permissions_controller.rb +52 -57
- data/lib/authentasaurus/ac/controllers/recoveries_controller.rb +49 -54
- data/lib/authentasaurus/ac/controllers/registrations_controller.rb +23 -28
- data/lib/authentasaurus/ac/controllers/sessions_controller.rb +39 -40
- data/lib/authentasaurus/ac/controllers/user_invitations_controller.rb +29 -34
- data/lib/authentasaurus/ac/controllers/users_controller.rb +51 -56
- data/lib/authentasaurus/ac/controllers/validations_controller.rb +34 -39
- data/lib/authentasaurus/ac/routing.rb +70 -74
- data/lib/authentasaurus/ar/acts_as_authenticatable.rb +58 -64
- data/lib/authentasaurus/ar/acts_as_authenticatable_validatable.rb +13 -16
- data/lib/authentasaurus/ar/acts_as_overrider.rb +1 -3
- data/lib/authentasaurus/ar/authenticatable.rb +1 -3
- data/lib/authentasaurus/ar/migrations.rb +137 -145
- data/lib/authentasaurus/ar/models/recovery.rb +20 -23
- data/lib/authentasaurus/ar/models/session.rb +46 -46
- data/lib/authentasaurus/ar/models/user_invitation.rb +19 -22
- data/lib/authentasaurus/ar/models/validation.rb +12 -15
- data/lib/authentasaurus/arel/acts_as_authenticatable.rb +18 -23
- data/lib/authentasaurus/arel/authenticatable.rb +5 -9
- data/lib/authentasaurus/authorization.rb +11 -8
- data/lib/authentasaurus/configuration.rb +30 -0
- data/lib/authentasaurus/railtie.rb +3 -6
- data/lib/generators/authentasaurus/install/install_generator.rb +1 -2
- data/lib/generators/authentasaurus/install/templates/authentasaurus_tasks.rake +2 -2
- data/lib/generators/authentasaurus/install/templates/defaults.yml +4 -2
- data/lib/generators/authentasaurus/views/templates/authentasaurus_emailer/invitation_mail.html.erb +2 -2
- data/lib/generators/authentasaurus/views/templates/authentasaurus_emailer/recovery_mail.html.erb +2 -2
- data/lib/generators/authentasaurus/views/templates/authentasaurus_emailer/validation_mail.html.erb +2 -2
- data/lib/generators/authentasaurus/views/views_generator.rb +1 -1
- metadata +8 -8
- data/lib/generators/authentasaurus/install/templates/initializer.rb +0 -3
@@ -1,53 +1,48 @@
|
|
1
1
|
module Authentasaurus::Ac::Controllers
|
2
2
|
module ValidationsController
|
3
|
-
|
4
|
-
base.send :extend, ClassMethods
|
5
|
-
base.send :include, InstanceMethods
|
6
|
-
end
|
3
|
+
extend ActiveSupport::Concern
|
7
4
|
|
8
5
|
module ClassMethods
|
9
6
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
format.html
|
15
|
-
end
|
7
|
+
|
8
|
+
def validate
|
9
|
+
respond_to do |format|
|
10
|
+
format.html
|
16
11
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
12
|
+
end
|
13
|
+
|
14
|
+
def activate
|
15
|
+
respond_to do |format|
|
16
|
+
validation = Validation.find_by_validation_code(params[:vcode])
|
17
|
+
if validation
|
18
|
+
validation.user.activate
|
19
|
+
validation.destroy
|
20
|
+
format.html { redirect_to login_url, :notice => I18n.t(:validation_successful, :scope => [:authentasaurus, :messages, :validations])}
|
21
|
+
else
|
22
|
+
flash.now[:alert] = I18n.t(:validation_failed, :scope => [:authentasaurus, :messages, :validations])
|
23
|
+
format.html { render :validate }
|
29
24
|
end
|
30
25
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
end
|
27
|
+
|
28
|
+
def resend_validation_email
|
29
|
+
respond_to do |format|
|
30
|
+
format.html
|
36
31
|
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def do_resend_validation_email
|
35
|
+
validation = Validation.find_by_email params[:email]
|
37
36
|
|
38
|
-
|
39
|
-
validation
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
else
|
46
|
-
flash.now[:alert] = I18n.t(:validation_email_invalid, :scope => [:authentasaurus, :messages, :validations], :email => params[:email])
|
47
|
-
format.html { render :resend_validation_email }
|
48
|
-
end
|
37
|
+
respond_to do |format|
|
38
|
+
unless validation.nil?
|
39
|
+
validation.send_validation
|
40
|
+
format.html {redirect_to login_url, :notice => I18n.t(:validation_email_sent, :scope => [:authentasaurus, :messages, :validations])}
|
41
|
+
else
|
42
|
+
flash.now[:alert] = I18n.t(:validation_email_invalid, :scope => [:authentasaurus, :messages, :validations], :email => params[:email])
|
43
|
+
format.html { render :resend_validation_email }
|
49
44
|
end
|
50
45
|
end
|
51
46
|
end
|
52
|
-
end
|
47
|
+
end
|
53
48
|
end
|
@@ -1,90 +1,86 @@
|
|
1
1
|
## Authentasaurus routes helper
|
2
2
|
module Authentasaurus::Ac
|
3
3
|
module Routing
|
4
|
-
|
5
|
-
base.send :include, InstanceMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
module InstanceMethods
|
9
|
-
# TODO: add documentation here
|
10
|
-
def authentasaurus_routes(*opts)
|
11
|
-
options = opts.extract_options!
|
12
|
-
|
13
|
-
# Authenticatable
|
14
|
-
authentasaurus_sessions options.dup
|
15
|
-
authentasaurus_users options.dup
|
16
|
-
# Recoverable
|
17
|
-
authentasaurus_recoverable
|
18
|
-
|
19
|
-
# Authorizable
|
20
|
-
if opts.include?(:authorization)
|
21
|
-
authentasaurus_authorizable options.dup
|
22
|
-
end
|
4
|
+
extend ActiveSupport::Concern
|
23
5
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
# Invitable
|
30
|
-
if opts.include?(:invitation)
|
31
|
-
authentasaurus_invitable options.dup
|
32
|
-
authentasaurus_invitable_public
|
33
|
-
end
|
34
|
-
end
|
6
|
+
# TODO: add documentation here
|
7
|
+
def authentasaurus_routes(*opts)
|
8
|
+
options = opts.extract_options!
|
35
9
|
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
get "/sessions/no-access(.:format)" => "sessions#no_access", :as => :no_access_sessions
|
42
|
-
end
|
10
|
+
# Authenticatable
|
11
|
+
authentasaurus_sessions options.dup
|
12
|
+
authentasaurus_users options.dup
|
13
|
+
# Recoverable
|
14
|
+
authentasaurus_recoverable
|
43
15
|
|
44
|
-
#
|
45
|
-
|
46
|
-
options
|
47
|
-
|
48
|
-
resources :users, options.dup
|
16
|
+
# Authorizable
|
17
|
+
if opts.include?(:authorization)
|
18
|
+
authentasaurus_authorizable options.dup
|
49
19
|
end
|
50
20
|
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
resources :groups, options.dup
|
56
|
-
resources :areas, options.dup
|
57
|
-
resources :permissions, options.dup
|
21
|
+
# Validatable
|
22
|
+
if opts.include?(:validation)
|
23
|
+
authentasaurus_validatable
|
58
24
|
end
|
59
25
|
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
match "/resend-validation" => "validations#resend_validation_email", :via => :get, :as => 'recover_password'
|
65
|
-
match "/resend-validation" => "validations#do_resend_validation_email", :via => :post, :as => 'do_recover_password'
|
26
|
+
# Invitable
|
27
|
+
if opts.include?(:invitation)
|
28
|
+
authentasaurus_invitable options.dup
|
29
|
+
authentasaurus_invitable_public
|
66
30
|
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# TODO: add documentation here
|
34
|
+
def authentasaurus_sessions(*opts)
|
35
|
+
get "/sessions/sign-in(.:format)" => "sessions#new", :as => :new_authentasaurus_session
|
36
|
+
post "/sessions(.:format)" => "sessions#create", :as => :authentasaurus_sessions
|
37
|
+
delete "/sessions/sign-out(.:format)" => "sessions#destroy", :as => :authentasaurus_session
|
38
|
+
get "/sessions/no-access(.:format)" => "sessions#no_access", :as => :no_access_authentasaurus_sessions
|
39
|
+
end
|
40
|
+
|
41
|
+
# TODO: add documentation here
|
42
|
+
def authentasaurus_users(*opts)
|
43
|
+
options = opts.extract_options!
|
67
44
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
45
|
+
resources :users, options.dup
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO: add documentation here
|
49
|
+
def authentasaurus_authorizable(*opts)
|
50
|
+
options = opts.extract_options!
|
74
51
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
52
|
+
resources :groups, options.dup
|
53
|
+
resources :areas, options.dup
|
54
|
+
resources :permissions, options.dup
|
55
|
+
end
|
56
|
+
|
57
|
+
# TODO: add documentation here
|
58
|
+
def authentasaurus_validatable
|
59
|
+
match "/validate" => "validations#validate", :as => 'validate'
|
60
|
+
match "/activate" => "validations#activate", :as => 'activate'
|
61
|
+
match "/resend-validation" => "validations#resend_validation_email", :via => :get, :as => 'recover_password'
|
62
|
+
match "/resend-validation" => "validations#do_resend_validation_email", :via => :post, :as => 'do_recover_password'
|
63
|
+
end
|
64
|
+
|
65
|
+
# TODO: add documentation here
|
66
|
+
def authentasaurus_invitable(*opts)
|
67
|
+
options = opts.extract_options!
|
80
68
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
69
|
+
resources :user_invitations, options.dup.merge({:except => [:show, :edit, :update]})
|
70
|
+
end
|
71
|
+
|
72
|
+
def authentasaurus_invitable_public(*opts)
|
73
|
+
options = opts.extract_options!
|
74
|
+
|
75
|
+
resources :registrations, :only => [:new, :create], :path_prefix => "/:token", :requirements => {:token => /[0-9a-zA-Z]+/}
|
76
|
+
end
|
77
|
+
|
78
|
+
# TODO: add documentation here
|
79
|
+
def authentasaurus_recoverable
|
80
|
+
match "/forgot-password" => "recoveries#new", :via => :get, :as => 'forgot_password'
|
81
|
+
match "/forgot-password" => "recoveries#create", :via => :post, :as => 'do_forgot_password'
|
82
|
+
match "/recover-password/:token" => "recoveries#edit", :via => :get, :as => 'recover_password'
|
83
|
+
match "/recover-password/:token" => "recoveries#destroy", :via => :delete, :as => 'do_recover_password'
|
88
84
|
end
|
89
|
-
end
|
85
|
+
end
|
90
86
|
end
|
@@ -1,13 +1,9 @@
|
|
1
1
|
module Authentasaurus::Ar
|
2
2
|
module ActsAsAuthenticatable
|
3
|
-
|
4
|
-
base.send :extend, ClassMethods
|
5
|
-
base.send :include, InstanceMethods
|
6
|
-
end
|
3
|
+
extend ActiveSupport::Concern
|
7
4
|
|
8
5
|
module ClassMethods
|
9
|
-
|
10
|
-
case Rails.application.config.authentasaurus[:hashing]
|
6
|
+
case Authentasaurus::Configuration.instance.hashing
|
11
7
|
when "SHA2"
|
12
8
|
require 'digest/sha2'
|
13
9
|
when "SHA1"
|
@@ -37,7 +33,7 @@ module Authentasaurus::Ar
|
|
37
33
|
def encrypt_password(password, password_seed)
|
38
34
|
pass_to_hash=password + "Securasaurus" + password_seed
|
39
35
|
|
40
|
-
case
|
36
|
+
case Authentasaurus::Configuration.instance.hashing
|
41
37
|
when "SHA2"
|
42
38
|
Digest::SHA2.hexdigest(pass_to_hash)
|
43
39
|
when "SHA1"
|
@@ -51,63 +47,61 @@ module Authentasaurus::Ar
|
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
## Password attribute (used when creating a user)
|
60
|
-
def password
|
61
|
-
return @password
|
62
|
-
end
|
63
|
-
|
64
|
-
def password=(pwd)
|
65
|
-
@password = pwd
|
66
|
-
return if pwd.blank?
|
67
|
-
create_salt
|
68
|
-
self.hashed_password = self.class.encrypt_password(@password, self.password_seed)
|
69
|
-
end
|
70
|
-
|
71
|
-
## New password attribute (used when editing a user)
|
72
|
-
def new_password
|
73
|
-
return @new_password
|
74
|
-
end
|
75
|
-
|
76
|
-
def new_password=(pwd)
|
77
|
-
@new_password = pwd
|
78
|
-
return if pwd.blank?
|
79
|
-
create_salt
|
80
|
-
self.hashed_password = self.class.encrypt_password(@new_password, self.password_seed)
|
81
|
-
end
|
82
|
-
|
83
|
-
def activate
|
84
|
-
self.update_attribute :active, true
|
85
|
-
end
|
86
|
-
|
87
|
-
def deactivate
|
88
|
-
self.update_attribute :active, false
|
89
|
-
end
|
90
|
-
|
91
|
-
def create_remember_me_token
|
92
|
-
pass_to_hash=Time.now.to_i.to_s + "Securasaurus" + password_seed
|
93
|
-
self.update_attribute :remember_me_token, Digest::SHA1.hexdigest(pass_to_hash)
|
94
|
-
self.remember_me_token
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
def new_password_blank?
|
99
|
-
self.new_password.blank?
|
100
|
-
end
|
101
|
-
|
102
|
-
## Creates password seed (salt)
|
103
|
-
def create_salt
|
104
|
-
self.password_seed = self.object_id.to_s + rand.to_s
|
105
|
-
end
|
50
|
+
def username=(username)
|
51
|
+
super(username.downcase)
|
52
|
+
end
|
106
53
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
54
|
+
## Password attribute (used when creating a user)
|
55
|
+
def password
|
56
|
+
return @password
|
57
|
+
end
|
58
|
+
|
59
|
+
def password=(pwd)
|
60
|
+
@password = pwd
|
61
|
+
return if pwd.blank?
|
62
|
+
create_salt
|
63
|
+
self.hashed_password = self.class.encrypt_password(@password, self.password_seed)
|
64
|
+
end
|
65
|
+
|
66
|
+
## New password attribute (used when editing a user)
|
67
|
+
def new_password
|
68
|
+
return @new_password
|
69
|
+
end
|
70
|
+
|
71
|
+
def new_password=(pwd)
|
72
|
+
@new_password = pwd
|
73
|
+
return if pwd.blank?
|
74
|
+
create_salt
|
75
|
+
self.hashed_password = self.class.encrypt_password(@new_password, self.password_seed)
|
76
|
+
end
|
77
|
+
|
78
|
+
def activate
|
79
|
+
self.update_attribute :active, true
|
80
|
+
end
|
81
|
+
|
82
|
+
def deactivate
|
83
|
+
self.update_attribute :active, false
|
84
|
+
end
|
85
|
+
|
86
|
+
def create_remember_me_token
|
87
|
+
pass_to_hash=Time.now.to_i.to_s + "Securasaurus" + password_seed
|
88
|
+
self.update_attribute :remember_me_token, Digest::SHA1.hexdigest(pass_to_hash)
|
89
|
+
self.remember_me_token
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def new_password_blank?
|
94
|
+
self.new_password.blank?
|
95
|
+
end
|
96
|
+
|
97
|
+
## Creates password seed (salt)
|
98
|
+
def create_salt
|
99
|
+
self.password_seed = self.object_id.to_s + rand.to_s
|
100
|
+
end
|
101
|
+
|
102
|
+
## Dont delete the last user
|
103
|
+
def dont_delete_admin
|
104
|
+
raise "You cannot delete the last admin" if self.id == 1 || User.count == 1
|
111
105
|
end
|
112
|
-
end
|
106
|
+
end
|
113
107
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module Authentasaurus::Ar
|
2
2
|
module ActsAsAuthenticatableValidatable
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
base.send :include, InstanceMethods
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
include ActsAsAuthenticatable
|
8
7
|
end
|
9
8
|
|
10
9
|
module ClassMethods
|
@@ -23,16 +22,14 @@ module Authentasaurus::Ar
|
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
25
|
+
private
|
26
|
+
def send_validation
|
27
|
+
unless self.active
|
28
|
+
validation = self.build_validation(:email => self.email, :validation_code => User.encrypt_password(self.username,self.password_seed))
|
29
|
+
unless validation.save
|
30
|
+
raise "Could not create validation record"
|
31
|
+
end
|
32
|
+
end
|
36
33
|
end
|
37
|
-
end
|
34
|
+
end
|
38
35
|
end
|
@@ -2,9 +2,7 @@ module Authentasaurus::Ar
|
|
2
2
|
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
3
3
|
|
4
4
|
module ActsAsOverrider
|
5
|
-
|
6
|
-
base.send :extend, ClassMethods
|
7
|
-
end
|
5
|
+
extend ActiveSupport::Concern
|
8
6
|
|
9
7
|
module ClassMethods
|
10
8
|
def acts_as_area
|