authentasaurus 0.6.21 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/models/authentasaurus_emailer.rb +6 -6
- 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/action_controller/authorization.rb +1 -1
- data/lib/active_record/acts_as_authenticatable.rb +2 -2
- data/lib/active_record/authenticatable.rb +1 -1
- data/lib/active_resource/authenticatable.rb +4 -4
- data/lib/authentasaurus.rb +61 -17
- data/lib/authentasaurus/models/area.rb +17 -15
- data/lib/authentasaurus/models/group.rb +15 -13
- data/lib/authentasaurus/models/permission.rb +20 -18
- data/lib/authentasaurus/models/recovery.rb +34 -32
- data/lib/authentasaurus/models/session.rb +63 -56
- data/lib/authentasaurus/models/user_invitation.rb +27 -25
- data/lib/authentasaurus/models/validation.rb +26 -24
- data/lib/authentasaurus/railtie.rb +13 -0
- data/lib/authentasaurus/sessions_controller.rb +0 -1
- data/lib/generators/authentasaurus/install/USAGE +5 -0
- data/lib/generators/authentasaurus/install/install_generator.rb +11 -0
- data/{generators/authentasaurus → lib/generators/authentasaurus/install}/templates/authentasaurus_tasks.rake +2 -2
- data/{generators/authentasaurus → lib/generators/authentasaurus/install}/templates/defaults.yml +0 -0
- data/lib/generators/authentasaurus/install/templates/initializer.rb +3 -0
- data/{generators/authentasaurus_views → lib/generators/authentasaurus/views}/USAGE +1 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/areas/edit.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/areas/index.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/areas/new.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/areas/show.html.erb +0 -0
- data/lib/generators/authentasaurus/views/templates/authentasaurus_emailer/invitation_mail.html.erb +4 -0
- data/lib/generators/authentasaurus/views/templates/authentasaurus_emailer/recovery_mail.html.erb +7 -0
- data/lib/generators/authentasaurus/views/templates/authentasaurus_emailer/validation_mail.html.erb +6 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/groups/edit.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/groups/index.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/groups/new.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/groups/show.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/permissions/edit.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/permissions/index.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/permissions/new.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/permissions/show.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/recoveries/edit.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/recoveries/new.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/registrations/new.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/sessions/new.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/sessions/no_access.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/user_invitations/index.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/user_invitations/new.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/users/edit.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/users/index.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/users/new.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/users/show.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/validations/resend_validation_email.html.erb +0 -0
- data/{generators/authentasaurus_views/templates/views → lib/generators/authentasaurus/views/templates}/validations/validate.html.erb +0 -0
- data/lib/generators/authentasaurus/views/views_generator.rb +76 -0
- data/lib/helpers/migrations.rb +1 -1
- data/lib/helpers/routing.rb +18 -22
- metadata +67 -56
- data/generators/authentasaurus/USAGE +0 -2
- data/generators/authentasaurus/authentasaurus_generator.rb +0 -9
- data/generators/authentasaurus/templates/initializer.rb +0 -3
- data/generators/authentasaurus_views/authentasaurus_views_generator.rb +0 -91
- data/generators/authentasaurus_views/templates/views/authentasaurus_emailer/invitation_mail.html.erb +0 -4
- data/generators/authentasaurus_views/templates/views/authentasaurus_emailer/recovery_mail.html.erb +0 -7
- data/generators/authentasaurus_views/templates/views/authentasaurus_emailer/validation_mail.html.erb +0 -6
- data/rails/init.rb +0 -41
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
class AuthentasaurusEmailer < ActionMailer::Base
|
|
2
2
|
def validation_mail(name, email, validation_code, sent_at = Time.now)
|
|
3
|
-
subject
|
|
3
|
+
subject Rails.application.config.authentasaurus[:modules][:validatable][:mail_subject]
|
|
4
4
|
recipients email
|
|
5
|
-
from
|
|
5
|
+
from Rails.application.config.authentasaurus[:modules][:validatable][:mail_from]
|
|
6
6
|
sent_on sent_at
|
|
7
7
|
|
|
8
8
|
body :name => name, :vcode => validation_code
|
|
@@ -10,9 +10,9 @@ class AuthentasaurusEmailer < ActionMailer::Base
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def recovery_mail(user, token, sent_at = Time.now)
|
|
13
|
-
subject
|
|
13
|
+
subject Rails.application.config.authentasaurus[:modules][:recoverable][:mail_subject]
|
|
14
14
|
recipients user.email
|
|
15
|
-
from
|
|
15
|
+
from Rails.application.config.authentasaurus[:modules][:recoverable][:mail_from] # dont forget to change me
|
|
16
16
|
sent_on sent_at
|
|
17
17
|
|
|
18
18
|
body :name => user.name, :token => token
|
|
@@ -20,9 +20,9 @@ class AuthentasaurusEmailer < ActionMailer::Base
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def invitation_mail(email, token, sent_at = Time.now)
|
|
23
|
-
subject
|
|
23
|
+
subject Rails.application.config.authentasaurus[:modules][:invitable][:mail_subject]
|
|
24
24
|
recipients email
|
|
25
|
-
from
|
|
25
|
+
from Rails.application.config.authentasaurus[:modules][:invitable][:mail_from]
|
|
26
26
|
sent_on sent_at
|
|
27
27
|
|
|
28
28
|
body :token => token
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<p>You've been invited to create an account at <%=
|
|
1
|
+
<p>You've been invited to create an account at <%= Rails.application.config.authentasaurus[:mail][:host] %> follow this <%= link_to "link", new_registrations_url(:host => Rails.application.config.authentasaurus[:mail][:host], :token => @token) %> to respond to the invitation.</p>
|
|
2
2
|
|
|
3
3
|
<p>Best Regards,</p>
|
|
4
|
-
<p><%=
|
|
4
|
+
<p><%= Rails.application.config.authentasaurus[:mail][:host] %> Team</p>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p>Dear <%= @name %>,</p>
|
|
2
2
|
|
|
3
3
|
<p>A request has been made to recover your account's password.</p>
|
|
4
|
-
<p>Please visit this <%= link_to "link", recover_password_url(:host =>
|
|
4
|
+
<p>Please visit this <%= link_to "link", recover_password_url(:host => Rails.application.config.authentasaurus[:mail][:host], :token => @token) %> and follow the instructions.</p>
|
|
5
5
|
|
|
6
6
|
<p>Best Regards,</p>
|
|
7
|
-
<p><%=
|
|
7
|
+
<p><%= Rails.application.config.authentasaurus[:mail][:host] %> Team</p>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p>Dear <%= @name %>,</p>
|
|
2
2
|
|
|
3
|
-
<p>Please validate your account at <%=
|
|
3
|
+
<p>Please validate your account at <%= Rails.application.config.authentasaurus[:mail][:host] %> by visiting this <%= link_to "link", activate_url(:host => Rails.application.config.authentasaurus[:mail][:host] , :code => @vcode) %>.</p>
|
|
4
4
|
|
|
5
5
|
<p>Best Regards,</p>
|
|
6
|
-
<p><%=
|
|
6
|
+
<p><%= Rails.application.config.authentasaurus[:mail][:host] %> Team</p>
|
|
@@ -156,7 +156,7 @@ module ActionController::Authorization
|
|
|
156
156
|
user_model = User if user_model.nil?
|
|
157
157
|
|
|
158
158
|
if cookies[:remember_me_token]
|
|
159
|
-
user = user_model.find_by_remember_me_token cookies
|
|
159
|
+
user = user_model.find_by_remember_me_token cookies[:remember_me_token]
|
|
160
160
|
if user.nil?
|
|
161
161
|
cookies.delete :remember_me_token
|
|
162
162
|
return false
|
|
@@ -6,7 +6,7 @@ module ActiveRecord::ActsAsAuthenticatable
|
|
|
6
6
|
|
|
7
7
|
module ClassMethods
|
|
8
8
|
|
|
9
|
-
case
|
|
9
|
+
case Rails.application.config.authentasaurus[:hashing]
|
|
10
10
|
when "SHA2"
|
|
11
11
|
require 'digest/sha2'
|
|
12
12
|
when "SHA1"
|
|
@@ -36,7 +36,7 @@ module ActiveRecord::ActsAsAuthenticatable
|
|
|
36
36
|
def encrypt_password(password, password_seed)
|
|
37
37
|
pass_to_hash=password + "Securasaurus" + password_seed
|
|
38
38
|
|
|
39
|
-
case
|
|
39
|
+
case Rails.application.config.authentasaurus[:hashing]
|
|
40
40
|
when "SHA2"
|
|
41
41
|
Digest::SHA2.hexdigest(pass_to_hash)
|
|
42
42
|
when "SHA1"
|
|
@@ -14,7 +14,7 @@ module ActiveRecord::Authenticatable
|
|
|
14
14
|
# basic attributes
|
|
15
15
|
validates_presence_of :username, :hashed_password, :password_seed, :email, :name
|
|
16
16
|
validates_uniqueness_of :username, :email
|
|
17
|
-
validates_format_of :username, :with => /^[a-z0-9]*([a-z0-
|
|
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
18
|
validates_format_of :email, :with => %r{[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}}
|
|
19
19
|
# password validations
|
|
20
20
|
validates_confirmation_of :password, :on => :create, :if => Proc.new {|user| user.hashed_password.nil? || user.password_seed.nil? }
|
|
@@ -11,10 +11,10 @@ module ActiveResource::Authenticatable
|
|
|
11
11
|
self.unloadable
|
|
12
12
|
options = args.extract_options!
|
|
13
13
|
|
|
14
|
-
self.site = options[:site] ||
|
|
15
|
-
self.element_name = options[:session_element].try(:to_s) ||
|
|
16
|
-
self.sync = options[:sync] ||
|
|
17
|
-
self.sync_to = options[:sync_to].try(:to_s).try(:camelize).try(:constantize) ||
|
|
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
18
|
|
|
19
19
|
|
|
20
20
|
# include authentication methods
|
data/lib/authentasaurus.rb
CHANGED
|
@@ -1,21 +1,65 @@
|
|
|
1
1
|
module Authentasaurus
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
# NEVER EVER REMOVE THIS !!!
|
|
3
|
+
require 'authentasaurus/railtie' if defined?(Rails)
|
|
4
|
+
# Controller stubs
|
|
5
|
+
require 'authentasaurus/areas_controller' if defined?(ActionController)
|
|
6
|
+
require 'authentasaurus/groups_controller' if defined?(ActionController)
|
|
7
|
+
require 'authentasaurus/permissions_controller' if defined?(ActionController)
|
|
8
|
+
require 'authentasaurus/recoveries_controller' if defined?(ActionController)
|
|
9
|
+
require 'authentasaurus/registrations_controller' if defined?(ActionController)
|
|
10
|
+
require 'authentasaurus/sessions_controller' if defined?(ActionController)
|
|
11
|
+
require 'authentasaurus/user_invitations_controller' if defined?(ActionController)
|
|
12
|
+
require 'authentasaurus/users_controller' if defined?(ActionController)
|
|
13
|
+
require 'authentasaurus/validations_controller' if defined?(ActionController)
|
|
14
|
+
# Model stubs
|
|
15
|
+
require 'authentasaurus/models/area' if defined?(ActiveRecord)
|
|
16
|
+
require 'authentasaurus/models/group' if defined?(ActiveRecord)
|
|
17
|
+
require 'authentasaurus/models/permission' if defined?(ActiveRecord)
|
|
18
|
+
require 'authentasaurus/models/recovery' if defined?(ActiveRecord)
|
|
19
|
+
require 'authentasaurus/models/session' if defined?(ActiveRecord)
|
|
20
|
+
require 'authentasaurus/models/user_invitation' if defined?(ActiveRecord)
|
|
21
|
+
require 'authentasaurus/models/validation' if defined?(ActiveRecord)
|
|
22
|
+
# Overriders ^^
|
|
23
|
+
require 'action_controller/authorization'
|
|
24
|
+
require 'action_view/authorization'
|
|
25
|
+
require 'active_record/authenticatable'
|
|
26
|
+
require 'active_resource/authenticatable'
|
|
27
|
+
require 'helpers/migrations'
|
|
28
|
+
require 'helpers/routing'
|
|
29
|
+
|
|
30
|
+
if defined?(ActionController)
|
|
31
|
+
class ActionController::Base
|
|
32
|
+
include ActionController::Authorization
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class ActionView::Base
|
|
36
|
+
include ActionView::Authorization
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class ActionDispatch::Routing::Mapper
|
|
40
|
+
include Routing
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if defined?(ActiveRecord)
|
|
45
|
+
class ActiveRecord::Base
|
|
46
|
+
include ActiveRecord::Authenticatable
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class ActiveRecord::ConnectionAdapters::AbstractAdapter
|
|
50
|
+
include Migrations::Tables
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class ActiveRecord::ConnectionAdapters::TableDefinition
|
|
54
|
+
include Migrations::Columns
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
if defined?(ActiveResource)
|
|
59
|
+
class ActiveResource::Base
|
|
60
|
+
class_inheritable_accessor :sync, :sync_to
|
|
61
|
+
include ActiveResource::Authenticatable
|
|
19
62
|
end
|
|
20
63
|
end
|
|
64
|
+
|
|
21
65
|
end
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
module Authentasaurus::Models
|
|
2
|
-
|
|
3
|
-
base
|
|
4
|
-
|
|
1
|
+
module Authentasaurus::Models
|
|
2
|
+
module Area
|
|
3
|
+
def self.included(base) # :nodoc:
|
|
4
|
+
base.send :extend, ClassMethods
|
|
5
|
+
base.send :include, InstanceMethods
|
|
6
|
+
|
|
7
|
+
base.send :unloadable
|
|
8
|
+
|
|
9
|
+
base.send :has_many, :permissions, :dependent => :destroy
|
|
10
|
+
base.send :has_many, :groups, :through => :permissions
|
|
11
|
+
|
|
12
|
+
base.send :validates_presence_of, :name
|
|
13
|
+
end
|
|
5
14
|
|
|
6
|
-
|
|
15
|
+
module ClassMethods
|
|
16
|
+
end
|
|
7
17
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
base.send :validates_presence_of, :name
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
module ClassMethods
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
module InstanceMethods
|
|
18
|
+
module InstanceMethods
|
|
19
|
+
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
module Authentasaurus::Models
|
|
2
|
-
|
|
3
|
-
base
|
|
4
|
-
|
|
1
|
+
module Authentasaurus::Models
|
|
2
|
+
module Group
|
|
3
|
+
def self.included(base) # :nodoc:
|
|
4
|
+
base.send :extend, ClassMethods
|
|
5
|
+
base.send :include, InstanceMethods
|
|
6
|
+
|
|
7
|
+
base.send :has_many, :permissions, :dependent => :destroy
|
|
8
|
+
base.send :has_many, :areas, :through => :permissions
|
|
9
|
+
|
|
10
|
+
base.send :validates_presence_of, :name
|
|
11
|
+
end
|
|
5
12
|
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
module ClassMethods
|
|
14
|
+
end
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
module ClassMethods
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
module InstanceMethods
|
|
16
|
+
module InstanceMethods
|
|
17
|
+
end
|
|
16
18
|
end
|
|
17
19
|
end
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
module Authentasaurus::Models
|
|
2
|
-
|
|
3
|
-
base
|
|
4
|
-
|
|
1
|
+
module Authentasaurus::Models
|
|
2
|
+
module Permission
|
|
3
|
+
def self.included(base) # :nodoc:
|
|
4
|
+
base.send :extend, ClassMethods
|
|
5
|
+
base.send :include, InstanceMethods
|
|
6
|
+
|
|
7
|
+
base.send :unloadable
|
|
8
|
+
|
|
9
|
+
base.send :belongs_to, :group
|
|
10
|
+
base.send :belongs_to, :area
|
|
11
|
+
|
|
12
|
+
# Check that everything is there
|
|
13
|
+
base.send :validates_presence_of, :group_id, :area_id
|
|
14
|
+
# Check foreign keys
|
|
15
|
+
base.send :validates_associated, :group, :area
|
|
16
|
+
end
|
|
5
17
|
|
|
6
|
-
|
|
18
|
+
module ClassMethods
|
|
19
|
+
end
|
|
7
20
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
# Check that everything is there
|
|
12
|
-
base.send :validates_presence_of, :group_id, :area_id
|
|
13
|
-
# Check foreign keys
|
|
14
|
-
base.send :validates_associated, :group, :area
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
module ClassMethods
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
module InstanceMethods
|
|
21
|
+
module InstanceMethods
|
|
22
|
+
end
|
|
21
23
|
end
|
|
22
24
|
end
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
module Authentasaurus::Models
|
|
2
|
-
|
|
3
|
-
base
|
|
4
|
-
|
|
1
|
+
module Authentasaurus::Models
|
|
2
|
+
module Recovery
|
|
3
|
+
def self.included(base) # :nodoc:
|
|
4
|
+
base.send :extend, ClassMethods
|
|
5
|
+
base.send :include, InstanceMethods
|
|
6
|
+
|
|
7
|
+
base.send :require, "digest/sha1"
|
|
8
|
+
|
|
9
|
+
base.send :unloadable
|
|
10
|
+
|
|
11
|
+
base.send :belongs_to, :user
|
|
12
|
+
|
|
13
|
+
base.send :before_validation_on_create, :make_token!
|
|
14
|
+
base.send :before_save, :send_recovery
|
|
15
|
+
|
|
16
|
+
base.send :named_scope, :valid, lambda { { :conditions => ["updated_at <= ?", Rails.application.config.authentasaurus[:modules][:recoverable][:token_expires_after].days.from_now] } }
|
|
17
|
+
|
|
18
|
+
base.send :validates_uniqueness_of, :user_id
|
|
19
|
+
base.send :validates_presence_of, :email
|
|
20
|
+
base.send :validates_presence_of, :user_id, :message => :"recovery.user_id.blank"
|
|
21
|
+
base.send :validates_format_of, :email, :with => %r{[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}}
|
|
22
|
+
end
|
|
5
23
|
|
|
6
|
-
|
|
24
|
+
module ClassMethods
|
|
25
|
+
end
|
|
7
26
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
base.send :validates_uniqueness_of, :user_id
|
|
18
|
-
base.send :validates_presence_of, :email
|
|
19
|
-
base.send :validates_presence_of, :user_id, :message => :"recovery.user_id.blank"
|
|
20
|
-
base.send :validates_format_of, :email, :with => %r{[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}}
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
module ClassMethods
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
module InstanceMethods
|
|
27
|
-
def make_token!
|
|
28
|
-
self.token = Digest::SHA1.hexdigest "#{Time.now.to_i} #{rand} #{self.email}"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def send_recovery
|
|
32
|
-
AuthentasaurusEmailer.deliver_recovery_mail(self.user, self.token) if AUTHENTASAURUS[:modules][:recoverable][:send_email]
|
|
33
|
-
end
|
|
27
|
+
module InstanceMethods
|
|
28
|
+
def make_token!
|
|
29
|
+
self.token = Digest::SHA1.hexdigest "#{Time.now.to_i} #{rand} #{self.email}"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def send_recovery
|
|
33
|
+
AuthentasaurusEmailer.deliver_recovery_mail(self.user, self.token) if Rails.application.config.authentasaurus[:modules][:recoverable][:send_email]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
34
36
|
end
|
|
35
|
-
end
|
|
37
|
+
end
|
|
@@ -1,71 +1,78 @@
|
|
|
1
1
|
# This class represents a session model, a session authenticates a username and a password.
|
|
2
2
|
#
|
|
3
3
|
# A session behaves just like an ActiveRecord model
|
|
4
|
-
module Authentasaurus::Models
|
|
5
|
-
|
|
6
|
-
base
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# Takes a hash of attributes keys and values just like new and authenticates the information.
|
|
16
|
-
# Returns true or false
|
|
17
|
-
def create(*attrs)
|
|
18
|
-
attributes = attrs.extract_options!
|
|
19
|
-
attrs = attrs.flatten
|
|
20
|
-
self_obj = self.new attributes
|
|
21
|
-
self_obj.save(attrs)
|
|
22
|
-
return self_obj
|
|
4
|
+
module Authentasaurus::Models
|
|
5
|
+
module Session
|
|
6
|
+
def self.included(base) # :nodoc:
|
|
7
|
+
base.send :extend, ClassMethods
|
|
8
|
+
base.send :include, InstanceMethods
|
|
9
|
+
base.send :include, ActiveModel::Validations
|
|
10
|
+
base.send :include, ActiveModel::Conversion
|
|
11
|
+
|
|
12
|
+
base.send :attr_accessor, :username, :password, :remember
|
|
13
|
+
base.send :validates_presence_of, :username, :password
|
|
14
|
+
base.send :attr_reader, :user
|
|
23
15
|
end
|
|
24
16
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
else
|
|
40
|
-
self.remember = false
|
|
17
|
+
module ClassMethods
|
|
18
|
+
# Takes a hash of attributes keys and values just like new and authenticates the information.
|
|
19
|
+
# Returns true or false
|
|
20
|
+
def create(*attrs)
|
|
21
|
+
attributes = attrs.extract_options!
|
|
22
|
+
attrs = attrs.flatten
|
|
23
|
+
self_obj = self.new attributes
|
|
24
|
+
self_obj.save(attrs)
|
|
25
|
+
return self_obj
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Takes an id (usually from an ActiveController session) and returns a User object
|
|
29
|
+
def current_user(id, session_type = :user)
|
|
30
|
+
session_type.to_s.camelize.constantize.find id
|
|
41
31
|
end
|
|
42
32
|
end
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
module InstanceMethods
|
|
35
|
+
# Takes a hash of attributes keys and values just like ActiveRecord models
|
|
36
|
+
def initialize(attributes = nil)
|
|
37
|
+
if attributes
|
|
38
|
+
attributes.each do |key,value|
|
|
39
|
+
send(key.to_s + '=', value)
|
|
40
|
+
end
|
|
41
|
+
else
|
|
42
|
+
self.remember = false
|
|
43
|
+
end
|
|
51
44
|
end
|
|
52
45
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
46
|
+
# Authenticates the information saved in the attributes
|
|
47
|
+
# Returns true or false
|
|
48
|
+
def save(*session_types)
|
|
49
|
+
session_types = session_types.flatten
|
|
50
|
+
|
|
51
|
+
if session_types.empty?
|
|
52
|
+
session_types = [:user]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
ret = true
|
|
56
|
+
session_types.each do |type|
|
|
57
|
+
@user = type.to_s.camelize.constantize.authenticate(self.username.downcase, self.password, self.remember == "1")
|
|
58
|
+
if @user.nil?
|
|
59
|
+
self.errors.add_to_base I18n.t(:invalid_login, :scope => [:authentasaurus, :messages, :sessions])
|
|
60
|
+
ret &= false
|
|
61
|
+
else
|
|
62
|
+
ret = true
|
|
63
|
+
break
|
|
64
|
+
end
|
|
62
65
|
end
|
|
66
|
+
ret
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def new_record? #:nodoc:
|
|
70
|
+
true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def persisted? #:nodoc:
|
|
74
|
+
false
|
|
63
75
|
end
|
|
64
|
-
ret
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def new_record? #:nodoc:
|
|
68
|
-
true
|
|
69
76
|
end
|
|
70
77
|
end
|
|
71
78
|
end
|