authgen 0.0.1
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/History.txt +4 -0
- data/Manifest.txt +38 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +52 -0
- data/Rakefile +18 -0
- data/bin/auth +17 -0
- data/lib/authgen.rb +8 -0
- data/rails_generators/auth/USAGE +5 -0
- data/rails_generators/auth/auth_generator.rb +62 -0
- data/rails_generators/auth/templates/authorization_rules.rb +21 -0
- data/rails_generators/auth/templates/controllers/application_controller.rb +47 -0
- data/rails_generators/auth/templates/controllers/user_sessions_controller.rb +22 -0
- data/rails_generators/auth/templates/controllers/users_controller.rb +37 -0
- data/rails_generators/auth/templates/helpers/application_helper.rb +3 -0
- data/rails_generators/auth/templates/helpers/user_sessions_helper.rb +2 -0
- data/rails_generators/auth/templates/helpers/users_helper.rb +2 -0
- data/rails_generators/auth/templates/migrations/20100322142300_create_users.rb +28 -0
- data/rails_generators/auth/templates/migrations/20100322161150_create_roles.rb +14 -0
- data/rails_generators/auth/templates/migrations/20100322161209_create_user_roles.rb +14 -0
- data/rails_generators/auth/templates/models/role.rb +7 -0
- data/rails_generators/auth/templates/models/user.rb +9 -0
- data/rails_generators/auth/templates/models/user_role.rb +4 -0
- data/rails_generators/auth/templates/models/user_session.rb +5 -0
- data/rails_generators/auth/templates/seeds.rb +8 -0
- data/rails_generators/auth/templates/template.rb +41 -0
- data/rails_generators/auth/templates/views/layouts/users.html.erb +16 -0
- data/rails_generators/auth/templates/views/user_sessions/new.html.erb +15 -0
- data/rails_generators/auth/templates/views/users/_form.html.erb +15 -0
- data/rails_generators/auth/templates/views/users/edit.html.erb +5 -0
- data/rails_generators/auth/templates/views/users/new.html.erb +3 -0
- data/rails_generators/auth/templates/views/users/show.html.erb +37 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_auth_generator.rb +46 -0
- data/test/test_authgen.rb +11 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_helper.rb +3 -0
- metadata +195 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
bin/auth
|
7
|
+
lib/authgen.rb
|
8
|
+
rails_generators/auth/USAGE
|
9
|
+
rails_generators/auth/auth_generator.rb
|
10
|
+
rails_generators/auth/templates/authorization_rules.rb
|
11
|
+
rails_generators/auth/templates/controllers/application_controller.rb
|
12
|
+
rails_generators/auth/templates/controllers/user_sessions_controller.rb
|
13
|
+
rails_generators/auth/templates/controllers/users_controller.rb
|
14
|
+
rails_generators/auth/templates/helpers/application_helper.rb
|
15
|
+
rails_generators/auth/templates/helpers/user_sessions_helper.rb
|
16
|
+
rails_generators/auth/templates/helpers/users_helper.rb
|
17
|
+
rails_generators/auth/templates/migrations/20100322142300_create_users.rb
|
18
|
+
rails_generators/auth/templates/migrations/20100322161150_create_roles.rb
|
19
|
+
rails_generators/auth/templates/migrations/20100322161209_create_user_roles.rb
|
20
|
+
rails_generators/auth/templates/models/role.rb
|
21
|
+
rails_generators/auth/templates/models/user.rb
|
22
|
+
rails_generators/auth/templates/models/user_role.rb
|
23
|
+
rails_generators/auth/templates/models/user_session.rb
|
24
|
+
rails_generators/auth/templates/seeds.rb
|
25
|
+
rails_generators/auth/templates/template.rb
|
26
|
+
rails_generators/auth/templates/views/layouts/users.html.erb
|
27
|
+
rails_generators/auth/templates/views/user_sessions/new.html.erb
|
28
|
+
rails_generators/auth/templates/views/users/_form.html.erb
|
29
|
+
rails_generators/auth/templates/views/users/edit.html.erb
|
30
|
+
rails_generators/auth/templates/views/users/new.html.erb
|
31
|
+
rails_generators/auth/templates/views/users/show.html.erb
|
32
|
+
script/console
|
33
|
+
script/destroy
|
34
|
+
script/generate
|
35
|
+
test/test_auth_generator.rb
|
36
|
+
test/test_authgen.rb
|
37
|
+
test/test_generator_helper.rb
|
38
|
+
test/test_helper.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= authgen
|
2
|
+
|
3
|
+
* http://github.com/sinisterchipmunk/authgen
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This generator can add powerful authentication and authorization to
|
8
|
+
a clean Rails application with a single command.
|
9
|
+
|
10
|
+
Configures a Rails application for use with the authlogic and
|
11
|
+
declarative_authorization gems, and generates all code (migrations,
|
12
|
+
models, controller methods, routes, roles, seeds, etc.) required.
|
13
|
+
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
|
17
|
+
script/generate auth
|
18
|
+
|
19
|
+
== REQUIREMENTS:
|
20
|
+
|
21
|
+
* a Rails application (2.3.5+)
|
22
|
+
* authlogic (2.1.3+)
|
23
|
+
* declarative_authorization (0.4.1+)
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
* sudo gem install authgen
|
28
|
+
|
29
|
+
== LICENSE:
|
30
|
+
|
31
|
+
(The MIT License)
|
32
|
+
|
33
|
+
Copyright (c) 2010 FIXME Colin MacKenzie IV
|
34
|
+
|
35
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
36
|
+
a copy of this software and associated documentation files (the
|
37
|
+
'Software'), to deal in the Software without restriction, including
|
38
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
39
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
40
|
+
permit persons to whom the Software is furnished to do so, subject to
|
41
|
+
the following conditions:
|
42
|
+
|
43
|
+
The above copyright notice and this permission notice shall be
|
44
|
+
included in all copies or substantial portions of the Software.
|
45
|
+
|
46
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
47
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
48
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
49
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
50
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
51
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
52
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/authgen'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
|
9
|
+
$hoe = Hoe.spec 'authgen' do
|
10
|
+
self.developer 'Colin MacKenzie IV', 'sinisterchipmunk@gmail.com'
|
11
|
+
self.extra_deps = [['declarative_authorization','>= 0.4.1'],
|
12
|
+
['authlogic','>= 2.1.3'],
|
13
|
+
['rails', '>=2.3.5']]
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'newgem/tasks'
|
18
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
data/bin/auth
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rubigen'
|
5
|
+
|
6
|
+
if %w(-v --version).include? ARGV.first
|
7
|
+
require 'auth/version'
|
8
|
+
puts "#{File.basename($0)} #{Auth::VERSION}"
|
9
|
+
exit(0)
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rubigen/scripts/generate'
|
13
|
+
source = RubiGen::PathSource.new(:application,
|
14
|
+
File.join(File.dirname(__FILE__), "../app_generators"))
|
15
|
+
RubiGen::Base.reset_sources
|
16
|
+
RubiGen::Base.append_sources source
|
17
|
+
RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'auth')
|
data/lib/authgen.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
class AuthGenerator < Rails::Generator::Base
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
BASEDIRS.each { |dir| m.directory dir }
|
5
|
+
|
6
|
+
# seeds
|
7
|
+
m.file "seeds.rb", "db/seeds/auth.rb"
|
8
|
+
# controllers
|
9
|
+
m.file "controllers/users_controller.rb", "app/controllers/users_controller.rb"
|
10
|
+
m.file "controllers/user_sessions_controller.rb", "app/controllers/user_sessions_controller.rb"
|
11
|
+
# helpers
|
12
|
+
m.file "helpers/users_helper.rb", "app/helpers/users_helper.rb"
|
13
|
+
m.file "helpers/user_sessions_helper.rb", "app/helpers/user_sessions_helper.rb"
|
14
|
+
# models
|
15
|
+
m.file "models/role.rb", "app/models/role.rb"
|
16
|
+
m.file "models/user.rb", "app/models/user.rb"
|
17
|
+
m.file "models/user_role.rb", "app/models/user_role.rb"
|
18
|
+
m.file "models/user_session.rb", "app/models/user_session.rb"
|
19
|
+
# views
|
20
|
+
m.file "views/layouts/users.html.erb", "app/views/layouts/users.html.erb"
|
21
|
+
m.file "views/users/_form.html.erb", "app/views/users/_form.html.erb"
|
22
|
+
m.file "views/users/edit.html.erb", "app/views/users/edit.html.erb"
|
23
|
+
m.file "views/users/new.html.erb", "app/views/users/new.html.erb"
|
24
|
+
m.file "views/users/show.html.erb", "app/views/users/show.html.erb"
|
25
|
+
m.file "views/user_sessions/new.html.erb", "app/views/user_sessions/new.html.erb"
|
26
|
+
# migrations
|
27
|
+
m.file "migrations/20100322142300_create_users.rb", "db/migrate/20100322142300_create_users.rb"
|
28
|
+
m.file "migrations/20100322161150_create_roles.rb", "db/migrate/20100322161150_create_roles.rb"
|
29
|
+
m.file "migrations/20100322161209_create_user_roles.rb", "db/migrate/20100322161209_create_user_roles.rb"
|
30
|
+
# authorization rules
|
31
|
+
m.file "authorization_rules.rb", "config/authorization_rules.rb"
|
32
|
+
# temp files, to be removed during cleanup
|
33
|
+
m.file "controllers/application_controller.rb", "tmp/.application_controller_methods.rb"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def after_generate
|
38
|
+
fi = File.join(File.dirname(__FILE__), 'templates/template.rb')
|
39
|
+
system("rake", "rails:template", "LOCATION=#{fi}")
|
40
|
+
system("rm", "tmp/.application_controller_methods.rb")
|
41
|
+
end
|
42
|
+
|
43
|
+
BASEDIRS = %w(
|
44
|
+
app/controllers
|
45
|
+
app/helpers
|
46
|
+
app/models
|
47
|
+
app/views/users
|
48
|
+
app/views/user_sessions
|
49
|
+
db/migrate
|
50
|
+
db/seeds
|
51
|
+
config
|
52
|
+
)
|
53
|
+
|
54
|
+
protected
|
55
|
+
def banner
|
56
|
+
<<-EOS
|
57
|
+
Creates a ...
|
58
|
+
|
59
|
+
USAGE: #{$0} #{spec.name} name
|
60
|
+
EOS
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
authorization do
|
2
|
+
role :guest do
|
3
|
+
has_permission_on :users, :to => [:view, :manage] do
|
4
|
+
if_attribute :user => is { user }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
role :admin do
|
9
|
+
includes :guest
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
privileges do
|
14
|
+
privilege :view do
|
15
|
+
includes :index, :show
|
16
|
+
end
|
17
|
+
|
18
|
+
privilege :manage do
|
19
|
+
includes :new, :create, :edit, :update, :destroy
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
before_filter { |c| Authorization.current_user = c.current_user }
|
2
|
+
filter_parameter_logging :password, :password_confirmation
|
3
|
+
helper_method :current_user_session, :current_user
|
4
|
+
hide_action :current_user_session, :current_user, :require_user, :require_no_user, :store_location,
|
5
|
+
:redirect_back_or_default
|
6
|
+
|
7
|
+
def current_user_session
|
8
|
+
return @current_user_session if defined?(@current_user_session)
|
9
|
+
@current_user_session = UserSession.find
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_user
|
13
|
+
return @current_user if defined?(@current_user)
|
14
|
+
reload_current_user!
|
15
|
+
end
|
16
|
+
|
17
|
+
def reload_current_user!
|
18
|
+
@current_user = current_user_session && current_user_session.user
|
19
|
+
end
|
20
|
+
|
21
|
+
def require_user
|
22
|
+
unless current_user
|
23
|
+
store_location
|
24
|
+
flash[:notice] = "You must be logged in to access this page."
|
25
|
+
redirect_to new_user_session_url
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def require_no_user
|
31
|
+
if current_user
|
32
|
+
store_location
|
33
|
+
flash[:notice] = "You must be logged out to access this page."
|
34
|
+
redirect_to account_url
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def store_location
|
40
|
+
session[:return_to] = request.request_uri
|
41
|
+
end
|
42
|
+
|
43
|
+
def redirect_back_or_default(default)
|
44
|
+
redirect_to(session[:return_to] || default)
|
45
|
+
session[:return_to] = nil
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class UserSessionsController < ApplicationController
|
2
|
+
layout 'users'
|
3
|
+
|
4
|
+
def new
|
5
|
+
@user_session = UserSession.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
@user_session = UserSession.new(params[:user_session])
|
10
|
+
if @user_session.save
|
11
|
+
@current_user_session = @user_session
|
12
|
+
redirect_back_or_default account_path
|
13
|
+
else
|
14
|
+
render :action => :new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy
|
19
|
+
current_user_session.destroy
|
20
|
+
redirect_to new_user_session_url
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
before_filter :require_no_user, :only => [:new, :create]
|
3
|
+
before_filter :require_user, :only => [:show, :edit, :update]
|
4
|
+
filter_access_to :all, :attribute_check => false
|
5
|
+
|
6
|
+
def new
|
7
|
+
@user = User.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
@user = User.new(params[:user])
|
12
|
+
if @user.save
|
13
|
+
flash[:notice] = "Account registered!"
|
14
|
+
redirect_back_or_default account_url
|
15
|
+
else
|
16
|
+
render :action => :new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
@user = @current_user
|
22
|
+
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
@user = @current_user
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
@user = @current_user # makes our views "cleaner" and more consistent
|
30
|
+
if @user.update_attributes(params[:user])
|
31
|
+
flash[:notice] = "Account updated!"
|
32
|
+
redirect_to account_url
|
33
|
+
else
|
34
|
+
render :action => :edit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :users do |t|
|
4
|
+
t.string :login, :null => false # optional, you can use email instead, or both
|
5
|
+
t.string :email, :null => false # optional, you can use login instead, or both
|
6
|
+
t.string :crypted_password, :null => false # optional, see below
|
7
|
+
t.string :password_salt, :null => false # optional, but highly recommended
|
8
|
+
t.string :persistence_token, :null => false # required
|
9
|
+
t.string :single_access_token, :null => false # optional, see Authlogic::Session::Params
|
10
|
+
t.string :perishable_token, :null => false # optional, see Authlogic::Session::Perishability
|
11
|
+
|
12
|
+
# Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.
|
13
|
+
t.integer :login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
|
14
|
+
t.integer :failed_login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
|
15
|
+
t.datetime :last_request_at # optional, see Authlogic::Session::MagicColumns
|
16
|
+
t.datetime :current_login_at # optional, see Authlogic::Session::MagicColumns
|
17
|
+
t.datetime :last_login_at # optional, see Authlogic::Session::MagicColumns
|
18
|
+
t.string :current_login_ip # optional, see Authlogic::Session::MagicColumns
|
19
|
+
t.string :last_login_ip # optional, see Authlogic::Session::MagicColumns
|
20
|
+
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.down
|
26
|
+
drop_table :users
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Major.create(:name => 'Daley', :city => cities.first)
|
8
|
+
Role.create([:name => 'admin', :caption => 'Administrator'])
|
@@ -0,0 +1,41 @@
|
|
1
|
+
def read_tempfile(path)
|
2
|
+
File.read(File.join(File.dirname(__FILE__), "tmp", ".#{path}"))
|
3
|
+
end
|
4
|
+
|
5
|
+
# gem dependencies: authlogic and declarative_authorization
|
6
|
+
gem 'authlogic'
|
7
|
+
gem 'declarative_authorization'
|
8
|
+
|
9
|
+
# Add methods and configuration to ActionController
|
10
|
+
lines = File.read(File.join(RAILS_ROOT, "app/controllers/application_controller.rb")).to_a
|
11
|
+
File.open(File.join(RAILS_ROOT, "app/controllers/application_controller.rb"), "w") do |fi|
|
12
|
+
lines.each do |line|
|
13
|
+
fi.puts line
|
14
|
+
if line[/class(\s+)ApplicationController/]
|
15
|
+
fi.puts read_tempfile("application_controller_methods.rb")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# routes: /users, /account, /user_session, /login, /logout
|
21
|
+
route 'map.resource :user_session'
|
22
|
+
route 'map.resource :account, :controller => "users"'
|
23
|
+
route 'map.resources :users'
|
24
|
+
route 'map.login "login", :controller => "user_sessions", :action => "new"'
|
25
|
+
route 'map.logout "logout", :controller => "user_sessions", :action => "destroy"'
|
26
|
+
route 'map.register "register", :controller => "users", :action => "new"'
|
27
|
+
|
28
|
+
# run migrations
|
29
|
+
if yes?("Run migrations?")
|
30
|
+
rake "db:migrate"
|
31
|
+
|
32
|
+
# seeds: add roles to DB
|
33
|
+
File.open(File.join(RAILS_ROOT, "db/seeds.rb"), "a") do |f|
|
34
|
+
f.puts "require File.join(File.dirname(__FILE__), '/seeds/auth')"
|
35
|
+
end
|
36
|
+
|
37
|
+
# seed the DB
|
38
|
+
if yes?("Seed the database?")
|
39
|
+
rake "db:seed"
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
|
7
|
+
<title>Access Restricted</title>
|
8
|
+
<%=javascript_include_tag :defaults%>
|
9
|
+
</head>
|
10
|
+
|
11
|
+
<body>
|
12
|
+
<%if flash[:notice]%><p style="color: green;"><%=flash[:notice]%></p><%end%>
|
13
|
+
<%if flash[:error]%><p style="color: red;"><%=flash[:error]%></p><%end%>
|
14
|
+
<%=yield%>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%form_for @user_session, :url => user_session_path do |f|%>
|
2
|
+
<%=f.error_messages%>
|
3
|
+
<p>
|
4
|
+
<%=f.label :login%>
|
5
|
+
<%=f.text_field :login%>
|
6
|
+
</p>
|
7
|
+
<p>
|
8
|
+
<%=f.label :password%>
|
9
|
+
<%=f.password_field :password%>
|
10
|
+
</p>
|
11
|
+
<p>
|
12
|
+
<%= f.check_box :remember_me %><%= f.label :remember_me %>
|
13
|
+
</p>
|
14
|
+
<%=f.submit "Login"%>
|
15
|
+
<%end%>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%form_for @user, :url => account_path do |form|%>
|
2
|
+
<%=form.error_messages%>
|
3
|
+
<%=form.label :login%><br/>
|
4
|
+
<%=form.text_field :login%><br/>
|
5
|
+
<br/>
|
6
|
+
<%=form.label :email%><br/>
|
7
|
+
<%=form.text_field :email%><br/>
|
8
|
+
<br/>
|
9
|
+
<%=form.label :password, form.object.new_record? ? nil : "Change password"%><br/>
|
10
|
+
<%=form.password_field :password%><br/>
|
11
|
+
<br/>
|
12
|
+
<%=form.label :password_confirmation%><br/>
|
13
|
+
<%=form.password_field :password_confirmation%><br/>
|
14
|
+
<%=form.submit "Register"%>
|
15
|
+
<%end%>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<p>
|
2
|
+
<b>Login:</b>
|
3
|
+
<%=h @user.login %>
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<b>Login count:</b>
|
8
|
+
<%=h @user.login_count %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Last request at:</b>
|
13
|
+
<%=h @user.last_request_at %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<b>Last login at:</b>
|
18
|
+
<%=h @user.last_login_at %>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<b>Current login at:</b>
|
23
|
+
<%=h @user.current_login_at %>
|
24
|
+
</p>
|
25
|
+
|
26
|
+
<p>
|
27
|
+
<b>Last login ip:</b>
|
28
|
+
<%=h @user.last_login_ip %>
|
29
|
+
</p>
|
30
|
+
|
31
|
+
<p>
|
32
|
+
<b>Current login ip:</b>
|
33
|
+
<%=h @user.current_login_ip %>
|
34
|
+
</p>
|
35
|
+
|
36
|
+
|
37
|
+
<%= link_to 'Edit', edit_account_path %>
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/authgen.rb'}"
|
9
|
+
puts "Loading authgen gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")
|
2
|
+
|
3
|
+
require 'rails_generator'
|
4
|
+
|
5
|
+
class TestAuthGenerator < Test::Unit::TestCase
|
6
|
+
include RubiGen::GeneratorTestHelper
|
7
|
+
|
8
|
+
def setup
|
9
|
+
bare_setup
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
bare_teardown
|
14
|
+
end
|
15
|
+
|
16
|
+
# Some generator-related assertions:
|
17
|
+
# assert_generated_file(name, &block) # block passed the file contents
|
18
|
+
# assert_directory_exists(name)
|
19
|
+
# assert_generated_class(name, &block)
|
20
|
+
# assert_generated_module(name, &block)
|
21
|
+
# assert_generated_test_for(name, &block)
|
22
|
+
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
|
23
|
+
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
|
24
|
+
#
|
25
|
+
# Other helper methods are:
|
26
|
+
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
27
|
+
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
28
|
+
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
29
|
+
|
30
|
+
def test_generator_without_options
|
31
|
+
name = "myapp"
|
32
|
+
run_generator('auth', [name], sources)
|
33
|
+
assert_directory_exists "some/directory"
|
34
|
+
assert_generated_file "some_file"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def sources
|
39
|
+
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
43
|
+
def generator_path
|
44
|
+
"rails_generators"
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
begin
|
2
|
+
require File.dirname(__FILE__) + '/test_helper'
|
3
|
+
rescue LoadError
|
4
|
+
require 'test/unit'
|
5
|
+
end
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
# Must set before requiring generator libs.
|
9
|
+
TMP_ROOT = File.dirname(__FILE__) + "/tmp" unless defined?(TMP_ROOT)
|
10
|
+
PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
|
11
|
+
app_root = File.join(TMP_ROOT, PROJECT_NAME)
|
12
|
+
if defined?(APP_ROOT)
|
13
|
+
APP_ROOT.replace(app_root)
|
14
|
+
else
|
15
|
+
APP_ROOT = app_root
|
16
|
+
end
|
17
|
+
if defined?(RAILS_ROOT)
|
18
|
+
RAILS_ROOT.replace(app_root)
|
19
|
+
else
|
20
|
+
RAILS_ROOT = app_root
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
require 'rubigen'
|
25
|
+
rescue LoadError
|
26
|
+
require 'rubygems'
|
27
|
+
require 'rubigen'
|
28
|
+
end
|
29
|
+
require 'rubigen/helpers/generator_test_helper'
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: authgen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Colin MacKenzie IV
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-22 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: declarative_authorization
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 4
|
30
|
+
- 1
|
31
|
+
version: 0.4.1
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: authlogic
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 1
|
44
|
+
- 3
|
45
|
+
version: 2.1.3
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rails
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 2
|
57
|
+
- 3
|
58
|
+
- 5
|
59
|
+
version: 2.3.5
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rubyforge
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 2
|
71
|
+
- 0
|
72
|
+
- 3
|
73
|
+
version: 2.0.3
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: gemcutter
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
- 5
|
86
|
+
- 0
|
87
|
+
version: 0.5.0
|
88
|
+
type: :development
|
89
|
+
version_requirements: *id005
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: hoe
|
92
|
+
prerelease: false
|
93
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 2
|
99
|
+
- 5
|
100
|
+
- 0
|
101
|
+
version: 2.5.0
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id006
|
104
|
+
description: |-
|
105
|
+
This generator can add powerful authentication and authorization to
|
106
|
+
a clean Rails application with a single command.
|
107
|
+
|
108
|
+
Configures a Rails application for use with the authlogic and
|
109
|
+
declarative_authorization gems, and generates all code (migrations,
|
110
|
+
models, controller methods, routes, roles, seeds, etc.) required.
|
111
|
+
email:
|
112
|
+
- sinisterchipmunk@gmail.com
|
113
|
+
executables:
|
114
|
+
- auth
|
115
|
+
extensions: []
|
116
|
+
|
117
|
+
extra_rdoc_files:
|
118
|
+
- History.txt
|
119
|
+
- Manifest.txt
|
120
|
+
- PostInstall.txt
|
121
|
+
files:
|
122
|
+
- History.txt
|
123
|
+
- Manifest.txt
|
124
|
+
- PostInstall.txt
|
125
|
+
- README.rdoc
|
126
|
+
- Rakefile
|
127
|
+
- bin/auth
|
128
|
+
- lib/authgen.rb
|
129
|
+
- rails_generators/auth/USAGE
|
130
|
+
- rails_generators/auth/auth_generator.rb
|
131
|
+
- rails_generators/auth/templates/authorization_rules.rb
|
132
|
+
- rails_generators/auth/templates/controllers/application_controller.rb
|
133
|
+
- rails_generators/auth/templates/controllers/user_sessions_controller.rb
|
134
|
+
- rails_generators/auth/templates/controllers/users_controller.rb
|
135
|
+
- rails_generators/auth/templates/helpers/application_helper.rb
|
136
|
+
- rails_generators/auth/templates/helpers/user_sessions_helper.rb
|
137
|
+
- rails_generators/auth/templates/helpers/users_helper.rb
|
138
|
+
- rails_generators/auth/templates/migrations/20100322142300_create_users.rb
|
139
|
+
- rails_generators/auth/templates/migrations/20100322161150_create_roles.rb
|
140
|
+
- rails_generators/auth/templates/migrations/20100322161209_create_user_roles.rb
|
141
|
+
- rails_generators/auth/templates/models/role.rb
|
142
|
+
- rails_generators/auth/templates/models/user.rb
|
143
|
+
- rails_generators/auth/templates/models/user_role.rb
|
144
|
+
- rails_generators/auth/templates/models/user_session.rb
|
145
|
+
- rails_generators/auth/templates/seeds.rb
|
146
|
+
- rails_generators/auth/templates/template.rb
|
147
|
+
- rails_generators/auth/templates/views/layouts/users.html.erb
|
148
|
+
- rails_generators/auth/templates/views/user_sessions/new.html.erb
|
149
|
+
- rails_generators/auth/templates/views/users/_form.html.erb
|
150
|
+
- rails_generators/auth/templates/views/users/edit.html.erb
|
151
|
+
- rails_generators/auth/templates/views/users/new.html.erb
|
152
|
+
- rails_generators/auth/templates/views/users/show.html.erb
|
153
|
+
- script/console
|
154
|
+
- script/destroy
|
155
|
+
- script/generate
|
156
|
+
- test/test_auth_generator.rb
|
157
|
+
- test/test_authgen.rb
|
158
|
+
- test/test_generator_helper.rb
|
159
|
+
- test/test_helper.rb
|
160
|
+
has_rdoc: true
|
161
|
+
homepage: http://github.com/sinisterchipmunk/authgen
|
162
|
+
licenses: []
|
163
|
+
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options:
|
166
|
+
- --main
|
167
|
+
- README.rdoc
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
segments:
|
175
|
+
- 0
|
176
|
+
version: "0"
|
177
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
segments:
|
182
|
+
- 0
|
183
|
+
version: "0"
|
184
|
+
requirements: []
|
185
|
+
|
186
|
+
rubyforge_project: authgen
|
187
|
+
rubygems_version: 1.3.6
|
188
|
+
signing_key:
|
189
|
+
specification_version: 3
|
190
|
+
summary: This generator can add powerful authentication and authorization to a clean Rails application with a single command
|
191
|
+
test_files:
|
192
|
+
- test/test_authgen.rb
|
193
|
+
- test/test_helper.rb
|
194
|
+
- test/test_auth_generator.rb
|
195
|
+
- test/test_generator_helper.rb
|