Permalink
Browse files

import of plugin

  • Loading branch information...
1 parent f0a0abf commit 729381f397549761cdb3c9cd0955f8996262e189 Scott Miller committed Jan 20, 2009
View
@@ -0,0 +1,20 @@
+Copyright (c) 2009 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the login_logger plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the login_logger plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'LoginLogger'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -0,0 +1,8 @@
+Description:
+ Explain the generator
+
+Example:
+ ./script/generate login_logger Thing
+
+ This will create:
+ what/will/it/create
@@ -0,0 +1,12 @@
+class LoginLoggerMigrationGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.migration_template 'migration.rb', 'db/migrate'
+ end
+ end
+
+ def file_name
+ "login_logger_migration"
+ end
+
+end
@@ -0,0 +1,18 @@
+class LoginLoggerMigration < ActiveRecord::Migration
+ def self.up
+ create_table :login_logs do |t|
+ t.integer :user_id
+ t.string :login
+ t.string :ip_address
+ t.datetime :created_at
+ t.boolean :failed, :default => true
+ end
+
+ add_index :login_logs, :user_id
+
+ end
+
+ def self.down
+ drop_table :login_logs
+ end
+end
View
@@ -0,0 +1,2 @@
+# Include hook code here
+require File.join(File.dirname(__FILE__), "lib", "login_logger")
View
@@ -0,0 +1 @@
+# Install hook code here
View
@@ -0,0 +1,16 @@
+class LoginLog < ActiveRecord::Base
+ belongs_to :user
+
+
+
+ #User last logged in
+ def self.previous
+ LoginLog.find(:last, :order => 'created_at ASC')
+ end
+
+ #User first logged in
+ def self.first
+ LoginLog.find(:first, :order => 'created_at ASC')
+ end
+
+end
View
@@ -0,0 +1,20 @@
+# LoginLogger
+
+
+module LoginLogger
+
+ def log_login
+ unless current_user.blank?
+ LoginLog.create(:user_id => current_user.id,
+ :login => current_user.login,
+ :ip_address => request.remote_ip,
+ :failed => false
+ )
+ else
+ LoginLog.create(:login => params[:login],
+ :ip_address => request.remote_ip)
+ end
+ end
+
+
+end
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :login_logger do
+# # Task goes here
+# end
@@ -0,0 +1,8 @@
+require 'test/unit'
+
+class LoginLoggerTest < Test::Unit::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
View
@@ -0,0 +1 @@
+# Uninstall hook code here

0 comments on commit 729381f

Please sign in to comment.