devise_traceable 0.0.3 → 0.0.4
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.
@@ -3,17 +3,8 @@
|
|
3
3
|
# and on authentication. Retrieving the user from session (:fetch) does
|
4
4
|
# not trigger it.
|
5
5
|
|
6
|
-
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
7
|
-
puts "Shenouda AfterSETUser" + record
|
8
|
-
if record.respond_to?(:insert_login!) #&& warden.authenticated?(options[:scope])
|
9
|
-
puts "WardenRequest" + warden.request
|
10
|
-
record.insert_login!(warden.request)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
6
|
Warden::Manager.before_logout do |record, warden, opts|
|
15
|
-
|
16
|
-
|
17
|
-
record.update_logout!(warden.request)
|
7
|
+
if record.respond_to?(:trace!)
|
8
|
+
record.trace!
|
18
9
|
end
|
19
|
-
end
|
10
|
+
end
|
@@ -7,22 +7,12 @@ module Devise
|
|
7
7
|
# * resource_id
|
8
8
|
# * sign_in_at
|
9
9
|
# * sign_out_at
|
10
|
-
# * time
|
11
10
|
#
|
12
11
|
|
13
12
|
module Traceable
|
14
|
-
def
|
13
|
+
def trace!
|
15
14
|
new_current = Time.now
|
16
|
-
self.sign_in_at
|
17
|
-
save(:validate => false)
|
18
|
-
end
|
19
|
-
|
20
|
-
def update_logout!(request)
|
21
|
-
new_current = Time.now
|
22
|
-
self.sign_out_at = new_current
|
23
|
-
time = self.sign_out_at - self.sign_in_at
|
24
|
-
self.time = time
|
25
|
-
save(:validate => false)
|
15
|
+
"#{self.class}Tracing".constantize.create(:sign_in_at => self.current_sign_in_at, :sign_out_at => new_current, :"#{self.class.primary_key}" => self.id)
|
26
16
|
end
|
27
17
|
end
|
28
18
|
end
|
@@ -25,7 +25,33 @@ class DeviseTraceableGenerator < Rails::Generators::NamedBase
|
|
25
25
|
class_option :orm
|
26
26
|
class_option :migration, :type => :boolean, :default => orm_has_migration?
|
27
27
|
|
28
|
+
def invoke_orm_model
|
29
|
+
if model_exists?
|
30
|
+
say "* Model already exists."
|
31
|
+
elsif options[:orm].present?
|
32
|
+
invoke "model", ["#{name}Tracing"], :migration => false, :orm => options[:orm]
|
33
|
+
|
34
|
+
unless model_exists?
|
35
|
+
abort "Tried to invoke the model generator for '#{options[:orm]}' but could not find it.\n" <<
|
36
|
+
"Please create your model by hand before calling `rails g devise_traceable #{name}`."
|
37
|
+
end
|
38
|
+
else
|
39
|
+
abort "Cannot create a devise model because config.generators.orm is blank.\n" <<
|
40
|
+
"Please create your model by hand or configure your generators orm before calling `rails g devise_traceable #{name}`."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
28
44
|
def create_migration_file
|
29
|
-
migration_template 'migration.rb', "db/migrate/devise_create_#{name.
|
45
|
+
migration_template 'migration.rb', "db/migrate/devise_create_#{name.downcase}_tracings.rb"
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def model_exists?
|
51
|
+
File.exists?(File.join(destination_root, model_path))
|
52
|
+
end
|
53
|
+
|
54
|
+
def model_path
|
55
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
30
56
|
end
|
31
57
|
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
class DeviseCreate<%= table_name.camelize %>
|
1
|
+
class DeviseCreate<%= table_name.camelize.singularize %>Tracings < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
create_table :<%= table_name %>
|
3
|
+
create_table :<%= table_name.singularize %>_tracings do |t|
|
4
4
|
t.integer :<%= table_name.classify.foreign_key %>
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
t.datetime :sign_in_at
|
6
|
+
t.datetime :sign_out_at
|
7
|
+
#Any additional fields here
|
8
8
|
|
9
|
-
|
9
|
+
t.timestamps
|
10
10
|
end
|
11
11
|
|
12
|
-
add_index :<%= table_name %>
|
12
|
+
add_index :<%= table_name.singularize %>_tracings, :<%= table_name.classify.foreign_key %>
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.down
|
16
|
-
|
16
|
+
drop_table :<%= table_name.singularize %>_tracings
|
17
17
|
end
|
18
18
|
end
|