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
@@ -0,0 +1,113 @@
|
|
1
|
+
module Authentasaurus::Ar
|
2
|
+
module ActsAsAuthenticatable
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
base.send :include, InstanceMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
case Rails.application.config.authentasaurus[:hashing]
|
11
|
+
when "SHA2"
|
12
|
+
require 'digest/sha2'
|
13
|
+
when "SHA1"
|
14
|
+
require 'digest/sha1'
|
15
|
+
when "MD5"
|
16
|
+
require 'digest/md5'
|
17
|
+
else
|
18
|
+
require 'digest/sha2'
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
## Authenticates the username (or email) and password
|
23
|
+
def authenticate(username_or_email, password, remember = false)
|
24
|
+
user=self.find_by_username(username_or_email) || self.find_by_email(username_or_email)
|
25
|
+
if user
|
26
|
+
expected_password=encrypt_password(password, user.password_seed)
|
27
|
+
unless expected_password == user.hashed_password && user.active
|
28
|
+
user = nil
|
29
|
+
else
|
30
|
+
user.create_remember_me_token if remember
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return user
|
34
|
+
end
|
35
|
+
|
36
|
+
## Encrypts the password using the given seed
|
37
|
+
def encrypt_password(password, password_seed)
|
38
|
+
pass_to_hash=password + "Securasaurus" + password_seed
|
39
|
+
|
40
|
+
case Rails.application.config.authentasaurus[:hashing]
|
41
|
+
when "SHA2"
|
42
|
+
Digest::SHA2.hexdigest(pass_to_hash)
|
43
|
+
when "SHA1"
|
44
|
+
Digest::SHA1.hexdigest(pass_to_hash)
|
45
|
+
when "MD5"
|
46
|
+
Digest::MD5.hexdigest(pass_to_hash)
|
47
|
+
else
|
48
|
+
Digest::SHA2.hexdigest(pass_to_hash)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module InstanceMethods
|
55
|
+
def username=(username)
|
56
|
+
super(username.downcase)
|
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
|
106
|
+
|
107
|
+
## Dont delete the last user
|
108
|
+
def dont_delete_admin
|
109
|
+
raise "You cannot delete the last admin" if self.id == 1 || User.count == 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Authentasaurus::Ar
|
2
|
+
module ActsAsAuthenticatableValidatable
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ActsAsAuthenticatable::ClassMethods
|
5
|
+
base.send :include, ActsAsAuthenticatable::InstanceMethods
|
6
|
+
base.send :extend, ClassMethods
|
7
|
+
base.send :include, InstanceMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
## Authenticates the username (or email) and password
|
12
|
+
def authenticate(username_or_email, password, remember = false)
|
13
|
+
user=self.find_by_username(username_or_email) || self.find_by_email(username_or_email)
|
14
|
+
if user
|
15
|
+
expected_password=encrypt_password(password, user.password_seed)
|
16
|
+
unless expected_password == user.hashed_password && user.active && user.validation.nil?
|
17
|
+
user = nil
|
18
|
+
else
|
19
|
+
user.create_remember_me_token if remember
|
20
|
+
end
|
21
|
+
end
|
22
|
+
return user
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module InstanceMethods
|
27
|
+
private
|
28
|
+
def send_validation
|
29
|
+
unless self.active
|
30
|
+
validation = self.build_validation(:email => self.email, :validation_code => User.encrypt_password(self.username,self.password_seed))
|
31
|
+
unless validation.save
|
32
|
+
raise "Could not create validation record"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Authentasaurus::Ar
|
2
|
+
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
3
|
+
|
4
|
+
module ActsAsOverrider
|
5
|
+
def self.included(base)
|
6
|
+
base.send :extend, ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def acts_as_area
|
11
|
+
unloadable
|
12
|
+
|
13
|
+
has_many :permissions, :dependent => :destroy
|
14
|
+
has_many :groups, :through => :permissions
|
15
|
+
|
16
|
+
validates_presence_of :name
|
17
|
+
end
|
18
|
+
|
19
|
+
def acts_as_group
|
20
|
+
has_many :permissions, :dependent => :destroy
|
21
|
+
has_many :areas, :through => :permissions
|
22
|
+
|
23
|
+
validates_presence_of :name
|
24
|
+
end
|
25
|
+
|
26
|
+
def acts_as_permission
|
27
|
+
unloadable
|
28
|
+
|
29
|
+
belongs_to :group
|
30
|
+
belongs_to :area
|
31
|
+
|
32
|
+
# Check that everything is there
|
33
|
+
validates_presence_of :group_id, :area_id
|
34
|
+
# Check foreign keys
|
35
|
+
validates_associated :group, :area
|
36
|
+
end
|
37
|
+
|
38
|
+
def acts_as_recovery
|
39
|
+
include Authentasaurus::Ar::Models::Recovery
|
40
|
+
end
|
41
|
+
|
42
|
+
def acts_as_user_invitation
|
43
|
+
include Authentasaurus::Ar::Models::UserInvitation
|
44
|
+
end
|
45
|
+
|
46
|
+
def acts_as_validation
|
47
|
+
include Authentasaurus::Ar::Models::Validation
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Authentasaurus::Ar
|
2
|
+
module Authenticatable
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def authenticatable(*args)
|
9
|
+
options = args.extract_options!
|
10
|
+
args = args.flatten
|
11
|
+
# Associations
|
12
|
+
belongs_to :group
|
13
|
+
has_many :permissions, :through => :group
|
14
|
+
# Validation
|
15
|
+
# basic attributes
|
16
|
+
validates_presence_of :username, :hashed_password, :password_seed, :email, :name
|
17
|
+
validates_uniqueness_of :username, :email
|
18
|
+
validates_format_of :username, :with => /^[a-z0-9]*([a-z0-9]{4})+[a-z0-9]*$/ # alpha-numeric only and at least 4 characters
|
19
|
+
validates_format_of :email, :with => %r{[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}}
|
20
|
+
# password validations
|
21
|
+
validates_confirmation_of :password, :on => :create, :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
22
|
+
validates_presence_of :password, :on => :create, :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
23
|
+
validates_length_of :password, :minimum => 6, :on => :create, :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
24
|
+
# new password
|
25
|
+
validates_confirmation_of :new_password, :on => :update, :unless => :new_password_blank?
|
26
|
+
validates_length_of :new_password, :minimum => 6, :on => :update, :unless => :new_password_blank?
|
27
|
+
# format of password
|
28
|
+
if args.include?(:strong_password)
|
29
|
+
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? }
|
30
|
+
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? }
|
31
|
+
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? }
|
32
|
+
validates_format_of :password, :with => %r{[@$%!&]}, :on => :create, :message => :"authenticatable.symbol_password", :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
33
|
+
# new password
|
34
|
+
validates_format_of :new_password, :with => %r{[a-z]}, :on => :update, :message => :"authenticatable.lower_case_password", :unless => :new_password_blank?
|
35
|
+
validates_format_of :new_password, :with => %r{[A-Z]}, :on => :update, :message => :"authenticatable.upper_case_password", :unless => :new_password_blank?
|
36
|
+
validates_format_of :new_password, :with => %r{[0-9]}, :on => :update, :message => :"authenticatable.digit_password", :unless => :new_password_blank?
|
37
|
+
validates_format_of :new_password, :with => %r{[@$%!&]}, :on => :update, :message => :"authenticatable.symbol_password", :unless => :new_password_blank?
|
38
|
+
end
|
39
|
+
|
40
|
+
# Accessors
|
41
|
+
attr_accessor :password_confirmation, :new_password_confirmation
|
42
|
+
|
43
|
+
# default data
|
44
|
+
class << self
|
45
|
+
attr_accessor :default_data
|
46
|
+
end
|
47
|
+
|
48
|
+
@default_data = {}
|
49
|
+
|
50
|
+
# dont delete admin
|
51
|
+
before_destroy :dont_delete_admin
|
52
|
+
|
53
|
+
#validation
|
54
|
+
if args.include?(:validatable)
|
55
|
+
has_one :validation, :as => :user
|
56
|
+
after_create :send_validation
|
57
|
+
# include authentication methods including validation
|
58
|
+
include ActsAsAuthenticatableValidatable
|
59
|
+
else
|
60
|
+
# include authentication methods
|
61
|
+
include ActsAsAuthenticatable
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module Authentasaurus::Ar
|
2
|
+
module Migrations
|
3
|
+
# Extends ActiveRecord::ConnectionAdapters::SchemaStatements
|
4
|
+
module Tables
|
5
|
+
def self.included(base) # :nodoc:
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
# creates all tables
|
11
|
+
def authentasaurus_tables
|
12
|
+
authentasaurus_user :authorizable
|
13
|
+
authentasaurus_group
|
14
|
+
authentasaurus_area
|
15
|
+
authentasaurus_permission
|
16
|
+
authentasaurus_validation
|
17
|
+
authentasaurus_user_invitation
|
18
|
+
authentasaurus_recovery
|
19
|
+
end
|
20
|
+
|
21
|
+
# creates users table
|
22
|
+
def authentasaurus_user(*opts)
|
23
|
+
create_table :users do |t|
|
24
|
+
t.string :username, :null => false
|
25
|
+
t.string :hashed_password, :null => false
|
26
|
+
t.string :password_seed, :null => false
|
27
|
+
t.string :name, :null => false
|
28
|
+
t.string :email, :null => false
|
29
|
+
t.boolean :active, :null => false, :default => false
|
30
|
+
t.string :remember_me_token
|
31
|
+
|
32
|
+
if opts.include?(:authorizable) || opts.include?("authorizable")
|
33
|
+
t.integer :group_id, :null => false
|
34
|
+
end
|
35
|
+
|
36
|
+
t.timestamps
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# creates groups table
|
41
|
+
def authentasaurus_group
|
42
|
+
create_table :groups do |t|
|
43
|
+
t.string :name, :null => false
|
44
|
+
|
45
|
+
t.timestamps
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# creates areas table
|
50
|
+
def authentasaurus_area
|
51
|
+
create_table :areas do |t|
|
52
|
+
t.string :name, :null => false
|
53
|
+
|
54
|
+
t.timestamps
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# creates permissions table
|
59
|
+
def authentasaurus_permission
|
60
|
+
create_table :permissions do |t|
|
61
|
+
t.integer :group_id, :null => false
|
62
|
+
t.integer :area_id, :null => false
|
63
|
+
t.boolean :read, :null => false, :default => false
|
64
|
+
t.boolean :write, :null => false, :default => false
|
65
|
+
|
66
|
+
t.timestamps
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# creates validations table
|
71
|
+
def authentasaurus_validation
|
72
|
+
create_table :validations do |t|
|
73
|
+
t.integer :user_id, :null => false
|
74
|
+
t.string :user_type, :null => false
|
75
|
+
t.string :email, :null => false
|
76
|
+
t.string :validation_code, :null => false
|
77
|
+
|
78
|
+
t.timestamps
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# creates user_invitations table
|
83
|
+
def authentasaurus_user_invitation
|
84
|
+
create_table :user_invitations do |t|
|
85
|
+
t.string :token, :null => false, :unique => true
|
86
|
+
t.string :email
|
87
|
+
|
88
|
+
t.timestamps
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# creates recoveries table
|
93
|
+
def authentasaurus_recovery
|
94
|
+
create_table :recoveries do |t|
|
95
|
+
t.integer :user_id, :null => false
|
96
|
+
t.string :email, :null => false
|
97
|
+
t.string :token, :null => false, :unique => true
|
98
|
+
|
99
|
+
t.timestamps
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# drops all tables
|
104
|
+
def authentasaurus_drop_tables
|
105
|
+
authentasaurus_drop_user
|
106
|
+
authentasaurus_drop_group
|
107
|
+
authentasaurus_drop_area
|
108
|
+
authentasaurus_drop_permission
|
109
|
+
authentasaurus_drop_validation
|
110
|
+
authentasaurus_drop_user_invitation
|
111
|
+
authentasaurus_drop_recovery
|
112
|
+
end
|
113
|
+
|
114
|
+
# drops users table
|
115
|
+
def authentasaurus_drop_user
|
116
|
+
drop_table :users
|
117
|
+
end
|
118
|
+
|
119
|
+
# drops groups table
|
120
|
+
def authentasaurus_drop_group
|
121
|
+
drop_table :groups
|
122
|
+
end
|
123
|
+
|
124
|
+
# drops areas table
|
125
|
+
def authentasaurus_drop_area
|
126
|
+
drop_table :areas
|
127
|
+
end
|
128
|
+
|
129
|
+
# drops permissions table
|
130
|
+
def authentasaurus_drop_permission
|
131
|
+
drop_table :permissions
|
132
|
+
end
|
133
|
+
|
134
|
+
# drops validations table
|
135
|
+
def authentasaurus_drop_validation
|
136
|
+
drop_table :validations
|
137
|
+
end
|
138
|
+
|
139
|
+
# drops user_invitations table
|
140
|
+
def authentasaurus_drop_user_invitation
|
141
|
+
drop_table :user_invitations
|
142
|
+
end
|
143
|
+
|
144
|
+
# drops recoveries table
|
145
|
+
def authentasaurus_drop_recovery
|
146
|
+
drop_table :recoveries
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Extends ActiveRecord::ConnectionAdapters::TableDefinition
|
152
|
+
module Columns
|
153
|
+
def self.included(base) # :nodoc:
|
154
|
+
base.send :include, InstanceMethods
|
155
|
+
end
|
156
|
+
|
157
|
+
module InstanceMethods
|
158
|
+
def user(*opts)
|
159
|
+
string :username, :null => false
|
160
|
+
string :hashed_password, :null => false
|
161
|
+
string :password_seed, :null => false
|
162
|
+
string :name, :null => false
|
163
|
+
string :email, :null => false
|
164
|
+
string :remember_me_token
|
165
|
+
boolean :active, :null => false, :default => false
|
166
|
+
if opts.include?(:authorizable)
|
167
|
+
integer :group_id, :null => false
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Authentasaurus::Models
|
1
|
+
module Authentasaurus::Ar::Models
|
2
2
|
module Recovery
|
3
3
|
def self.included(base) # :nodoc:
|
4
4
|
base.send :extend, ClassMethods
|
@@ -10,10 +10,10 @@ module Authentasaurus::Models
|
|
10
10
|
|
11
11
|
base.send :belongs_to, :user
|
12
12
|
|
13
|
-
base.send :
|
13
|
+
base.send :before_validation, :make_token!, :on => :create
|
14
14
|
base.send :before_save, :send_recovery
|
15
15
|
|
16
|
-
base.send :
|
16
|
+
base.send :scope, :valid, lambda { { :conditions => ["updated_at <= ?", Rails.application.config.authentasaurus[:modules][:recoverable][:token_expires_after].days.from_now] } }
|
17
17
|
|
18
18
|
base.send :validates_uniqueness_of, :user_id
|
19
19
|
base.send :validates_presence_of, :email
|