authentasaurus 0.7.3 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO +3 -0
- data/app/controllers/areas_controller.rb +1 -1
- data/app/controllers/groups_controller.rb +1 -1
- data/app/controllers/permissions_controller.rb +1 -1
- data/app/controllers/recoveries_controller.rb +1 -1
- data/app/controllers/registrations_controller.rb +1 -1
- data/app/controllers/sessions_controller.rb +1 -1
- data/app/controllers/user_invitations_controller.rb +1 -1
- data/app/controllers/users_controller.rb +1 -1
- data/app/controllers/validations_controller.rb +1 -1
- data/app/models/area.rb +1 -1
- data/app/models/group.rb +1 -1
- data/app/models/permission.rb +1 -1
- data/app/models/recovery.rb +1 -1
- data/app/models/session.rb +1 -1
- data/app/models/user_invitation.rb +1 -1
- data/app/models/validation.rb +1 -1
- data/lib/authentasaurus.rb +22 -36
- data/lib/authentasaurus/ac/acts_as_overrider.rb +47 -0
- data/lib/authentasaurus/ac/controllers/areas_controller.rb +80 -0
- data/lib/authentasaurus/ac/controllers/groups_controller.rb +81 -0
- data/lib/authentasaurus/ac/controllers/permissions_controller.rb +81 -0
- data/lib/authentasaurus/ac/controllers/recoveries_controller.rb +72 -0
- data/lib/authentasaurus/ac/controllers/registrations_controller.rb +45 -0
- data/lib/authentasaurus/ac/controllers/sessions_controller.rb +58 -0
- data/lib/authentasaurus/ac/controllers/user_invitations_controller.rb +50 -0
- data/lib/authentasaurus/ac/controllers/users_controller.rb +80 -0
- data/lib/authentasaurus/ac/controllers/validations_controller.rb +53 -0
- data/lib/authentasaurus/ac/routing.rb +90 -0
- data/lib/authentasaurus/ar/acts_as_authenticatable.rb +113 -0
- data/lib/authentasaurus/ar/acts_as_authenticatable_validatable.rb +38 -0
- data/lib/authentasaurus/ar/acts_as_overrider.rb +51 -0
- data/lib/authentasaurus/ar/authenticatable.rb +66 -0
- data/lib/authentasaurus/ar/migrations.rb +173 -0
- data/lib/authentasaurus/{models → ar/models}/recovery.rb +3 -3
- data/lib/authentasaurus/{models → ar/models}/session.rb +1 -1
- data/lib/authentasaurus/{models → ar/models}/user_invitation.rb +1 -1
- data/lib/authentasaurus/{models → ar/models}/validation.rb +1 -1
- data/lib/authentasaurus/arel/acts_as_authenticatable.rb +72 -0
- data/lib/authentasaurus/arel/authenticatable.rb +25 -0
- data/lib/authentasaurus/authorization.rb +341 -0
- data/lib/authentasaurus/railtie.rb +4 -4
- data/lib/generators/authentasaurus/install/templates/initializer.rb +1 -1
- data/rdoc/apple-touch-icon.png +0 -0
- data/rdoc/classes/Authentasaurus.html +65 -0
- data/rdoc/classes/Authentasaurus/Ac.html +72 -0
- data/rdoc/classes/Authentasaurus/Ac/ActsAsOverrider.html +104 -0
- data/rdoc/classes/Authentasaurus/Ac/ActsAsOverrider/ClassMethods.html +397 -0
- data/rdoc/classes/Authentasaurus/Ac/Routing.html +61 -0
- data/rdoc/classes/Authentasaurus/Ac/Routing/InstanceMethods.html +390 -0
- data/rdoc/classes/Authentasaurus/Ar.html +77 -0
- data/rdoc/classes/Authentasaurus/Ar/ActsAsAuthenticatable.html +107 -0
- data/rdoc/classes/Authentasaurus/Ar/ActsAsAuthenticatable/ClassMethods.html +168 -0
- data/rdoc/classes/Authentasaurus/Ar/ActsAsAuthenticatable/InstanceMethods.html +357 -0
- data/rdoc/classes/Authentasaurus/Ar/ActsAsAuthenticatableValidatable.html +109 -0
- data/rdoc/classes/Authentasaurus/Ar/ActsAsAuthenticatableValidatable/ClassMethods.html +113 -0
- data/rdoc/classes/Authentasaurus/Ar/ActsAsAuthenticatableValidatable/InstanceMethods.html +54 -0
- data/rdoc/classes/Authentasaurus/Ar/ActsAsOverrider.html +104 -0
- data/rdoc/classes/Authentasaurus/Ar/ActsAsOverrider/ClassMethods.html +320 -0
- data/rdoc/classes/Authentasaurus/Ar/Authenticatable.html +104 -0
- data/rdoc/classes/Authentasaurus/Ar/Authenticatable/ClassMethods.html +182 -0
- data/rdoc/classes/Authentasaurus/Ar/Migrations.html +63 -0
- data/rdoc/classes/Authentasaurus/Ar/Migrations/Columns.html +68 -0
- data/rdoc/classes/Authentasaurus/Ar/Migrations/Columns/InstanceMethods.html +106 -0
- data/rdoc/classes/Authentasaurus/Ar/Migrations/Tables.html +68 -0
- data/rdoc/classes/Authentasaurus/Ar/Migrations/Tables/InstanceMethods.html +703 -0
- data/rdoc/classes/Authentasaurus/Arel.html +65 -0
- data/rdoc/classes/Authentasaurus/Arel/ActsAsAuthenticatable.html +107 -0
- data/rdoc/classes/Authentasaurus/Arel/ActsAsAuthenticatable/ClassMethods.html +139 -0
- data/rdoc/classes/Authentasaurus/Arel/ActsAsAuthenticatable/InstanceMethods.html +113 -0
- data/rdoc/classes/Authentasaurus/Arel/Authenticatable.html +105 -0
- data/rdoc/classes/Authentasaurus/Arel/Authenticatable/ClassMethods.html +119 -0
- data/rdoc/classes/Authentasaurus/Authorization.html +230 -0
- data/rdoc/classes/Authentasaurus/Authorization/ActionController.html +63 -0
- data/rdoc/classes/Authentasaurus/Authorization/ActionController/ClassMethods.html +263 -0
- data/rdoc/classes/Authentasaurus/Authorization/ActionController/InstanceMethods.html +54 -0
- data/rdoc/classes/Authentasaurus/Authorization/ActionView.html +54 -0
- data/rdoc/classes/Authentasaurus/Authorization/CommonInstanceMethods.html +240 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/css/main.css +278 -0
- data/rdoc/css/panel.css +383 -0
- data/rdoc/css/reset.css +53 -0
- data/rdoc/favicon.ico +0 -0
- data/rdoc/files/README_rdoc.html +366 -0
- data/rdoc/files/TODO.html +64 -0
- data/rdoc/files/lib/authentasaurus/ac/acts_as_overrider_rb.html +52 -0
- data/rdoc/files/lib/authentasaurus/ac/routing_rb.html +60 -0
- data/rdoc/files/lib/authentasaurus/ar/acts_as_authenticatable_rb.html +52 -0
- data/rdoc/files/lib/authentasaurus/ar/acts_as_authenticatable_validatable_rb.html +52 -0
- data/rdoc/files/lib/authentasaurus/ar/acts_as_overrider_rb.html +52 -0
- data/rdoc/files/lib/authentasaurus/ar/authenticatable_rb.html +52 -0
- data/rdoc/files/lib/authentasaurus/ar/migrations_rb.html +52 -0
- data/rdoc/files/lib/authentasaurus/arel/acts_as_authenticatable_rb.html +52 -0
- data/rdoc/files/lib/authentasaurus/arel/authenticatable_rb.html +72 -0
- data/rdoc/files/lib/authentasaurus/authorization_rb.html +208 -0
- data/rdoc/i/arrows.png +0 -0
- data/rdoc/i/results_bg.png +0 -0
- data/rdoc/i/tree_bg.png +0 -0
- data/rdoc/index.html +15 -0
- data/rdoc/js/jquery-1.3.2.min.js +19 -0
- data/rdoc/js/jquery-effect.js +593 -0
- data/rdoc/js/main.js +22 -0
- data/rdoc/js/searchdoc.js +628 -0
- data/rdoc/panel/index.html +71 -0
- data/rdoc/panel/search_index.js +1 -0
- data/rdoc/panel/tree.js +1 -0
- metadata +92 -44
- data/lib/action_controller/authorization.rb +0 -215
- data/lib/action_view/authorization.rb +0 -52
- data/lib/active_record/acts_as_authenticatable.rb +0 -111
- data/lib/active_record/acts_as_authenticatable_validatable.rb +0 -36
- data/lib/active_record/authenticatable.rb +0 -64
- data/lib/active_resource/acts_as_authenticatable.rb +0 -70
- data/lib/active_resource/authenticatable.rb +0 -24
- data/lib/authentasaurus/areas_controller.rb +0 -78
- data/lib/authentasaurus/groups_controller.rb +0 -79
- data/lib/authentasaurus/models/area.rb +0 -21
- data/lib/authentasaurus/models/group.rb +0 -19
- data/lib/authentasaurus/models/permission.rb +0 -24
- data/lib/authentasaurus/permissions_controller.rb +0 -79
- data/lib/authentasaurus/recoveries_controller.rb +0 -70
- data/lib/authentasaurus/registrations_controller.rb +0 -43
- data/lib/authentasaurus/sessions_controller.rb +0 -56
- data/lib/authentasaurus/user_invitations_controller.rb +0 -48
- data/lib/authentasaurus/users_controller.rb +0 -78
- data/lib/authentasaurus/validations_controller.rb +0 -51
- data/lib/helpers/migrations.rb +0 -171
- data/lib/helpers/routing.rb +0 -87
@@ -1,52 +0,0 @@
|
|
1
|
-
# Defines authorization helpers for ActionController
|
2
|
-
module ActionView::Authorization
|
3
|
-
|
4
|
-
def self.included(base) # :nodoc:
|
5
|
-
base.send :include, InstanceMethods
|
6
|
-
end
|
7
|
-
|
8
|
-
module InstanceMethods
|
9
|
-
private
|
10
|
-
# Returns an object of the current user
|
11
|
-
def current_user(user_model = nil)
|
12
|
-
user_model = User if user_model.nil?
|
13
|
-
return user_model.find session[:user_id] if session[:user_id]
|
14
|
-
end
|
15
|
-
|
16
|
-
# Checks if the current user is logged in but takes no further action
|
17
|
-
def is_logged_in?(user_model = nil)
|
18
|
-
user_model = User if user_model.nil?
|
19
|
-
unless user_model.find_by_id(session[:user_id])
|
20
|
-
return false
|
21
|
-
end
|
22
|
-
return true
|
23
|
-
end
|
24
|
-
|
25
|
-
# Checks if the current user has the appropriate permission
|
26
|
-
#
|
27
|
-
# *ex*: has?(:write) or has?(:read, :users)
|
28
|
-
def has?(permission, area = nil, user_model = User)
|
29
|
-
return false unless is_logged_in? user_model
|
30
|
-
check = false
|
31
|
-
case permission
|
32
|
-
when :write
|
33
|
-
unless area
|
34
|
-
user_permissions = session[:user_permissions]
|
35
|
-
check = user_permissions[:write].find { |perm| perm==self.controller_name || perm=="all" }
|
36
|
-
else
|
37
|
-
user_permissions = session[:user_permissions]
|
38
|
-
check = user_permissions[:write].find { |perm| perm==area.to_s || perm=="all" }
|
39
|
-
end
|
40
|
-
when :read
|
41
|
-
unless area
|
42
|
-
user_permissions = session[:user_permissions]
|
43
|
-
check = user_permissions[:read].find { |perm| perm==self.controller_name || perm=="all" }
|
44
|
-
else
|
45
|
-
user_permissions = session[:user_permissions]
|
46
|
-
check = user_permissions[:read].find { |perm| perm==area.to_s || perm=="all" }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
return check
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
module ActiveRecord::ActsAsAuthenticatable
|
2
|
-
def self.included(base)
|
3
|
-
base.send :extend, ClassMethods
|
4
|
-
base.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
|
9
|
-
case Rails.application.config.authentasaurus[:hashing]
|
10
|
-
when "SHA2"
|
11
|
-
require 'digest/sha2'
|
12
|
-
when "SHA1"
|
13
|
-
require 'digest/sha1'
|
14
|
-
when "MD5"
|
15
|
-
require 'digest/md5'
|
16
|
-
else
|
17
|
-
require 'digest/sha2'
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
## Authenticates the username (or email) and password
|
22
|
-
def authenticate(username_or_email, password, remember = false)
|
23
|
-
user=self.find_by_username(username_or_email) || self.find_by_email(username_or_email)
|
24
|
-
if user
|
25
|
-
expected_password=encrypt_password(password, user.password_seed)
|
26
|
-
unless expected_password == user.hashed_password && user.active
|
27
|
-
user = nil
|
28
|
-
else
|
29
|
-
user.create_remember_me_token if remember
|
30
|
-
end
|
31
|
-
end
|
32
|
-
return user
|
33
|
-
end
|
34
|
-
|
35
|
-
## Encrypts the password using the given seed
|
36
|
-
def encrypt_password(password, password_seed)
|
37
|
-
pass_to_hash=password + "Securasaurus" + password_seed
|
38
|
-
|
39
|
-
case Rails.application.config.authentasaurus[:hashing]
|
40
|
-
when "SHA2"
|
41
|
-
Digest::SHA2.hexdigest(pass_to_hash)
|
42
|
-
when "SHA1"
|
43
|
-
Digest::SHA1.hexdigest(pass_to_hash)
|
44
|
-
when "MD5"
|
45
|
-
Digest::MD5.hexdigest(pass_to_hash)
|
46
|
-
else
|
47
|
-
Digest::SHA2.hexdigest(pass_to_hash)
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
module InstanceMethods
|
54
|
-
def username=(username)
|
55
|
-
super(username.downcase)
|
56
|
-
end
|
57
|
-
|
58
|
-
## Password attribute (used when creating a user)
|
59
|
-
def password
|
60
|
-
return @password
|
61
|
-
end
|
62
|
-
|
63
|
-
def password=(pwd)
|
64
|
-
@password = pwd
|
65
|
-
return if pwd.blank?
|
66
|
-
create_salt
|
67
|
-
self.hashed_password = self.class.encrypt_password(@password, self.password_seed)
|
68
|
-
end
|
69
|
-
|
70
|
-
## New password attribute (used when editing a user)
|
71
|
-
def new_password
|
72
|
-
return @new_password
|
73
|
-
end
|
74
|
-
|
75
|
-
def new_password=(pwd)
|
76
|
-
@new_password = pwd
|
77
|
-
return if pwd.blank?
|
78
|
-
create_salt
|
79
|
-
self.hashed_password = self.class.encrypt_password(@new_password, self.password_seed)
|
80
|
-
end
|
81
|
-
|
82
|
-
def activate
|
83
|
-
self.update_attribute :active, true
|
84
|
-
end
|
85
|
-
|
86
|
-
def deactivate
|
87
|
-
self.update_attribute :active, false
|
88
|
-
end
|
89
|
-
|
90
|
-
def create_remember_me_token
|
91
|
-
pass_to_hash=Time.now.to_i.to_s + "Securasaurus" + password_seed
|
92
|
-
self.update_attribute :remember_me_token, Digest::SHA1.hexdigest(pass_to_hash)
|
93
|
-
self.remember_me_token
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
def new_password_blank?
|
98
|
-
self.new_password.blank?
|
99
|
-
end
|
100
|
-
|
101
|
-
## Creates password seed (salt)
|
102
|
-
def create_salt
|
103
|
-
self.password_seed = self.object_id.to_s + rand.to_s
|
104
|
-
end
|
105
|
-
|
106
|
-
## Dont delete the last user
|
107
|
-
def dont_delete_admin
|
108
|
-
raise "You cannot delete the last admin" if self.id == 1 || User.count == 1
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module ActiveRecord::ActsAsAuthenticatableValidatable
|
2
|
-
def self.included(base)
|
3
|
-
base.send :extend, ActiveRecord::ActsAsAuthenticatable::ClassMethods
|
4
|
-
base.send :include, ActiveRecord::ActsAsAuthenticatable::InstanceMethods
|
5
|
-
base.send :extend, ClassMethods
|
6
|
-
base.send :include, InstanceMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
## Authenticates the username (or email) and password
|
11
|
-
def authenticate(username_or_email, password, remember = false)
|
12
|
-
user=self.find_by_username(username_or_email) || self.find_by_email(username_or_email)
|
13
|
-
if user
|
14
|
-
expected_password=encrypt_password(password, user.password_seed)
|
15
|
-
unless expected_password == user.hashed_password && user.active && user.validation.nil?
|
16
|
-
user = nil
|
17
|
-
else
|
18
|
-
user.create_remember_me_token if remember
|
19
|
-
end
|
20
|
-
end
|
21
|
-
return user
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module InstanceMethods
|
26
|
-
private
|
27
|
-
def send_validation
|
28
|
-
unless self.active
|
29
|
-
validation = self.build_validation(:email => self.email, :validation_code => User.encrypt_password(self.username,self.password_seed))
|
30
|
-
unless validation.save
|
31
|
-
raise "Could not create validation record"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module ActiveRecord::Authenticatable
|
2
|
-
def self.included(base)
|
3
|
-
base.send :extend, ClassMethods
|
4
|
-
end
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
def authenticatable(*args)
|
8
|
-
options = args.extract_options!
|
9
|
-
args = args.flatten
|
10
|
-
# Associations
|
11
|
-
belongs_to :group
|
12
|
-
has_many :permissions, :through => :group
|
13
|
-
# Validation
|
14
|
-
# basic attributes
|
15
|
-
validates_presence_of :username, :hashed_password, :password_seed, :email, :name
|
16
|
-
validates_uniqueness_of :username, :email
|
17
|
-
validates_format_of :username, :with => /^[a-z0-9]*([a-z0-9]{4})+[a-z0-9]*$/ # alpha-numeric only and at least 4 characters
|
18
|
-
validates_format_of :email, :with => %r{[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}}
|
19
|
-
# password validations
|
20
|
-
validates_confirmation_of :password, :on => :create, :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
21
|
-
validates_presence_of :password, :on => :create, :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
22
|
-
validates_length_of :password, :minimum => 6, :on => :create, :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
23
|
-
# new password
|
24
|
-
validates_confirmation_of :new_password, :on => :update, :unless => :new_password_blank?
|
25
|
-
validates_length_of :new_password, :minimum => 6, :on => :update, :unless => :new_password_blank?
|
26
|
-
# format of password
|
27
|
-
if args.include?(:strong_password)
|
28
|
-
validates_format_of :password, :with => %r{[a-z]}, :on => :create, :message => :"authenticatable.lower_case_password", :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
29
|
-
validates_format_of :password, :with => %r{[A-Z]}, :on => :create, :message => :"authenticatable.upper_case_password", :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
30
|
-
validates_format_of :password, :with => %r{[0-9]}, :on => :create, :message => :"authenticatable.digit_password", :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
31
|
-
validates_format_of :password, :with => %r{[@$%!&]}, :on => :create, :message => :"authenticatable.symbol_password", :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
32
|
-
# new password
|
33
|
-
validates_format_of :new_password, :with => %r{[a-z]}, :on => :update, :message => :"authenticatable.lower_case_password", :unless => :new_password_blank?
|
34
|
-
validates_format_of :new_password, :with => %r{[A-Z]}, :on => :update, :message => :"authenticatable.upper_case_password", :unless => :new_password_blank?
|
35
|
-
validates_format_of :new_password, :with => %r{[0-9]}, :on => :update, :message => :"authenticatable.digit_password", :unless => :new_password_blank?
|
36
|
-
validates_format_of :new_password, :with => %r{[@$%!&]}, :on => :update, :message => :"authenticatable.symbol_password", :unless => :new_password_blank?
|
37
|
-
end
|
38
|
-
|
39
|
-
# Accessors
|
40
|
-
attr_accessor :password_confirmation, :new_password_confirmation
|
41
|
-
|
42
|
-
# default data
|
43
|
-
class << self
|
44
|
-
attr_accessor :default_data
|
45
|
-
end
|
46
|
-
|
47
|
-
@default_data = {}
|
48
|
-
|
49
|
-
# dont delete admin
|
50
|
-
before_destroy :dont_delete_admin
|
51
|
-
|
52
|
-
#validation
|
53
|
-
if args.include?(:validatable)
|
54
|
-
has_one :validation, :as => :user
|
55
|
-
after_create :send_validation
|
56
|
-
# include authentication methods including validation
|
57
|
-
include ActiveRecord::ActsAsAuthenticatableValidatable
|
58
|
-
else
|
59
|
-
# include authentication methods
|
60
|
-
include ActiveRecord::ActsAsAuthenticatable
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module ActiveResource::ActsAsAuthenticatable
|
2
|
-
def self.included(base)
|
3
|
-
base.send :extend, ClassMethods
|
4
|
-
base.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
## Authenticates the username and password
|
9
|
-
def authenticate(username, password, remember = false)
|
10
|
-
case(self.format)
|
11
|
-
when ActiveResource::Formats::XmlFormat
|
12
|
-
user = self.new Hash.from_xml(self.post(:signin,:username => username, :password => password, :remember => remember).body).values.first
|
13
|
-
when ActiveResource::Formats::JsonFormat
|
14
|
-
user = self.new ActiveSupport::JSON.decode(self.post(:signin,:username => username, :password => password, :remember => remember).body)
|
15
|
-
else
|
16
|
-
user = self.new Hash.from_xml(self.post(:signin,:username => username, :password => password, :remember => remember).body).values.first
|
17
|
-
end
|
18
|
-
|
19
|
-
unless user.nil?
|
20
|
-
if self.sync && !self.sync_to.nil?
|
21
|
-
last_update = user.attributes.delete "updated_at"
|
22
|
-
local_user = self.sync_to.find_or_initialize_by_username user.username, user.attributes
|
23
|
-
|
24
|
-
unless local_user.new_record?
|
25
|
-
last_update_datetime = (last_update.kind_of?(String)) ? (DateTime.parse(last_update)) : (last_update)
|
26
|
-
|
27
|
-
if local_user.updated_at < last_update_datetime
|
28
|
-
local_user.update_attributes user.attributes
|
29
|
-
end
|
30
|
-
else
|
31
|
-
local_user.password = password
|
32
|
-
local_user.password_confirmation = password
|
33
|
-
|
34
|
-
local_user.hashed_password = user.hashed_password
|
35
|
-
local_user.password_seed = user.password_seed
|
36
|
-
|
37
|
-
self.sync_to.default_data.each do |key,value|
|
38
|
-
local_user.send(key.to_s + '=', value)
|
39
|
-
end
|
40
|
-
|
41
|
-
local_user.save
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
return user
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
module InstanceMethods
|
50
|
-
def sync
|
51
|
-
if self.class.sync && !self.class.sync_to.nil?
|
52
|
-
user = self.dup
|
53
|
-
last_update = user.attributes.delete "updated_at"
|
54
|
-
local_user = self.class.sync_to.find_or_initialize_by_username user.username, user.attributes
|
55
|
-
|
56
|
-
unless local_user.new_record?
|
57
|
-
local_user.update_attributes user.attributes
|
58
|
-
else
|
59
|
-
self.sync_to.default_data.each do |key,value|
|
60
|
-
local_user.send(key.to_s + '=', value)
|
61
|
-
end
|
62
|
-
|
63
|
-
local_user.save
|
64
|
-
end
|
65
|
-
else
|
66
|
-
false
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'active_resource/acts_as_authenticatable'
|
2
|
-
module ActiveResource::Authenticatable
|
3
|
-
def self.included(base)
|
4
|
-
base.send :extend, ClassMethods
|
5
|
-
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
|
10
|
-
def authenticatable(*args)
|
11
|
-
self.unloadable
|
12
|
-
options = args.extract_options!
|
13
|
-
|
14
|
-
self.site = options[:site] || Rails.application.config.authentasaurus[:modules][:remote][self.name.underscore.gsub(/_sync/, "").to_sym][:site]
|
15
|
-
self.element_name = options[:session_element].try(:to_s) || Rails.application.config.authentasaurus[:modules][:remote][self.name.underscore.gsub(/_sync/, "").to_sym][:session_element]
|
16
|
-
self.sync = options[:sync] || Rails.application.config.authentasaurus[:modules][:remote][self.name.underscore.gsub(/_sync/, "").to_sym][:sync]
|
17
|
-
self.sync_to = options[:sync_to].try(:to_s).try(:camelize).try(:constantize) || Rails.application.config.authentasaurus[:modules][:remote][self.name.underscore.gsub(/_sync/, "").to_sym][:sync_to].camelize.constantize
|
18
|
-
|
19
|
-
|
20
|
-
# include authentication methods
|
21
|
-
include ActiveResource::ActsAsAuthenticatable
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
module Authentasaurus::AreasController
|
2
|
-
def self.included(base) # :nodoc:
|
3
|
-
base.send :extend, ClassMethods
|
4
|
-
base.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
end
|
9
|
-
|
10
|
-
module InstanceMethods
|
11
|
-
def index
|
12
|
-
@areas= Area.find :all
|
13
|
-
|
14
|
-
respond_to do |format|
|
15
|
-
format.html
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def show
|
20
|
-
@area = Area.find params[:id]
|
21
|
-
|
22
|
-
respond_to do |format|
|
23
|
-
format.html
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def new
|
28
|
-
@area = Area.new
|
29
|
-
|
30
|
-
respond_to do |format|
|
31
|
-
format.html
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def create
|
36
|
-
@area = Area.new params[:area]
|
37
|
-
|
38
|
-
respond_to do |format|
|
39
|
-
if @area.save
|
40
|
-
format.html { redirect_to :action=>:index, :notice => "Area Created" }
|
41
|
-
else
|
42
|
-
flash.now[:alert] = I18n.t(:create_failed, :scope => [:authentasaurus, :messages, :areas])
|
43
|
-
format.html { render :new }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def edit
|
49
|
-
@area = Area.find params[:id]
|
50
|
-
|
51
|
-
respond_to do |format|
|
52
|
-
format.html
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def update
|
57
|
-
@area = Area.find params[:id]
|
58
|
-
|
59
|
-
respond_to do |format|
|
60
|
-
if @area.update_attributes(params[:area])
|
61
|
-
format.html { redirect_to :action => :index, :notice => "Area updated" }
|
62
|
-
else
|
63
|
-
flash.now[:alert] = I18n.t(:update_failed, :scope => [:authentasaurus, :messages, :areas])
|
64
|
-
format.html { render :edit }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def destroy
|
70
|
-
@area = Area.find params[:id]
|
71
|
-
@area.destroy
|
72
|
-
|
73
|
-
respond_to do |format|
|
74
|
-
format.html { redirect_to :action=>:index }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
module Authentasaurus::GroupsController
|
2
|
-
def self.included(base) # :nodoc:
|
3
|
-
base.send :extend, ClassMethods
|
4
|
-
base.send :include, InstanceMethods
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
end
|
9
|
-
|
10
|
-
module InstanceMethods
|
11
|
-
def index
|
12
|
-
@groups = Group.find :all
|
13
|
-
|
14
|
-
respond_to do |format|
|
15
|
-
format.html
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def show
|
20
|
-
@group = Group.find params[:id]
|
21
|
-
|
22
|
-
respond_to do |format|
|
23
|
-
format.html
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def new
|
28
|
-
@group = Group.new
|
29
|
-
|
30
|
-
respond_to do |format|
|
31
|
-
format.html
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def create
|
36
|
-
@group = Group.new params[:group]
|
37
|
-
|
38
|
-
respond_to do |format|
|
39
|
-
if @group.save
|
40
|
-
format.html { redirect_to :action=>:index, :notice => "Group created" }
|
41
|
-
else
|
42
|
-
flash.now[:alert] = I18n.t(:create_failed, :scope => [:authentasaurus, :messages, :groups])
|
43
|
-
format.html { render :new }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def edit
|
49
|
-
@group = Group.find params[:id]
|
50
|
-
|
51
|
-
respond_to do |format|
|
52
|
-
format.html
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def update
|
57
|
-
@group = Group.find params[:id]
|
58
|
-
|
59
|
-
respond_to do |format|
|
60
|
-
if @group.update_attributes(params[:group])
|
61
|
-
format.html { redirect_to :action => :index, :notice => "Group updated" }
|
62
|
-
else
|
63
|
-
flash.now[:alert] = I18n.t(:update_failed, :scope => [:authentasaurus, :messages, :groups])
|
64
|
-
format.html { render :edit }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
def destroy
|
71
|
-
@group = Group.find params[:id]
|
72
|
-
@group.destroy
|
73
|
-
|
74
|
-
respond_to do |format|
|
75
|
-
format.html { redirect_to :action=>:index }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|