cmpa_auth 1.0.2 → 1.0.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/CHANGELOG.rdoc +7 -1
- data/README.rdoc +18 -14
- data/app/views/application/_footer.html.erb +5 -0
- data/app/views/application/_login.html.erb +10 -0
- data/app/views/layouts/sessions.html.erb +7 -16
- data/lib/cmpa_auth/authentication.rb +3 -2
- data/lib/cmpa_auth/extensions.rb +1 -1
- data/lib/cmpa_auth/rails_helpers.rb +44 -10
- data/lib/cmpa_auth.rb +1 -1
- data/public/images/sistemas/contratos.png +0 -0
- metadata +6 -4
- data/config/config.yml +0 -7
- /data/app/views/{errors/error_403.html.erb → rescues/403.html.erb} +0 -0
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 1.0.3 released 2009-11-08
|
2
|
+
|
3
|
+
* Adicionado suporte a customiza��o do filtro de autentica��o com o m�todo <tt>cmpa_authenticate</tt>.
|
4
|
+
* Adicionada a pasta <tt>app/views/application</tt> com os arquivos de cabe�alho e login para serem utilizados em no layout padr�o.
|
5
|
+
* Removido o arquivo config/config.yml (por quest�es de seguran�a, principalmente).
|
6
|
+
|
1
7
|
== 1.0.2 released 2009-11-08
|
2
8
|
|
3
9
|
* Documenta��o melhorada.
|
@@ -8,7 +14,7 @@
|
|
8
14
|
== 1.0.1 released 2009-11-05
|
9
15
|
|
10
16
|
* Melhorias na documenta��o e cria��o do README.
|
11
|
-
* Remo��o dos m�todos <tt>CmpaAuth::Authentication.in_group?</tt> e <tt>CmpaAuth::Authentication.in_groups?</tt
|
17
|
+
* Remo��o dos m�todos <tt>CmpaAuth::Authentication.in_group?</tt> e <tt>CmpaAuth::Authentication.in_groups?</tt>.
|
12
18
|
|
13
19
|
== 1.0.0 released 2009-09-10
|
14
20
|
|
data/README.rdoc
CHANGED
@@ -31,14 +31,7 @@ Quando a aplica
|
|
31
31
|
No arquivo <i>config/environment.rb</i> adicione a seguinte linha de c�digo no
|
32
32
|
bloco de inicializa��o:
|
33
33
|
|
34
|
-
config.gem 'cmpa_auth'
|
35
|
-
|
36
|
-
Observe que o Rails avisar� caso a gem cmpa_auth n�o esteja instalada,
|
37
|
-
entretanto n�o ser� capaz de instal�-la. No momento voc� deve copiar a �ltima
|
38
|
-
vers�o da gem dispon�vel em <i>\\\\cmpa-s01\info\desenvolvimento\gems</i> para o
|
39
|
-
seu computador e rodar o comando abaixo.
|
40
|
-
|
41
|
-
$ sudo gem install --local path/to/gem/cmpa_auth-x.x.x.gem
|
34
|
+
config.gem 'cmpa_auth', :source => 'http://gemcutter.org'
|
42
35
|
|
43
36
|
|
44
37
|
=== Models
|
@@ -99,11 +92,11 @@ chamada repetidas vezes... Por exemplo, no <tt>ApplicationController</tt>.
|
|
99
92
|
private
|
100
93
|
|
101
94
|
def redator?
|
102
|
-
current_lotacao.
|
95
|
+
current_lotacao.role_of_super_and_redator?
|
103
96
|
end
|
104
97
|
|
105
98
|
def fotografo?
|
106
|
-
current_lotacao.
|
99
|
+
current_lotacao.role_of_super_and_fotografo?
|
107
100
|
end
|
108
101
|
|
109
102
|
Ent�o na view podemos perguntar:
|
@@ -122,10 +115,21 @@ Para realizar logout e supondo que o usu
|
|
122
115
|
oferecer o seguinte link na view:
|
123
116
|
|
124
117
|
= link_to 'sair', session_path, :method => :delete
|
125
|
-
|
126
|
-
O login � feito automaticamente caso o usu�rio n�o esteja logado. Isso � feito
|
127
|
-
atrav�s do before filter <tt>check_authentication</tt> que por sua vez utiliza o
|
128
|
-
helper <tt>logged_in?</tt>.
|
129
118
|
|
130
119
|
|
120
|
+
=== Login
|
121
|
+
|
122
|
+
A tela de login � exibida automaticamente caso o usu�rio n�o esteja logado, a
|
123
|
+
n�o ser que voc� queira que certas actions de um determinado controller n�o
|
124
|
+
rodem o <tt>before_filter</tt>. Isso � feito chamando o m�todo
|
125
|
+
<tt>check_authentication</tt>. Por exemplo:
|
126
|
+
|
127
|
+
class PostController < ApplicationController
|
128
|
+
check_authentication :except => :index
|
129
|
+
end
|
130
|
+
|
131
|
+
class NewsController < ApplicationController
|
132
|
+
check_authentication :only => [:new, :create, :edit, :update]
|
133
|
+
end
|
134
|
+
|
131
135
|
Copyright (c) 2009 CMPA - Assessoria de Inform�tica
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% if logged_in? %>
|
2
|
+
<p>
|
3
|
+
<strong><%= current_user.usuario %></strong>
|
4
|
+
|
|
5
|
+
<%= link_to "sair", session_url, :method => :delete, :class => 'icon icon-door-out' %>
|
6
|
+
</p>
|
7
|
+
<em><%= current_lotacao.setor.nome %></em>
|
8
|
+
<% else %>
|
9
|
+
<%= link_to 'Login', new_session_url, :class => 'icon icon-door-in' %>
|
10
|
+
<% end %>
|
@@ -19,30 +19,21 @@
|
|
19
19
|
<li><%= link_to 'Gerenciamento de Acesso' %></li>
|
20
20
|
</ul>
|
21
21
|
<div class='login'>
|
22
|
-
|
23
|
-
<strong><%= current_user.usuario %></strong> |
|
24
|
-
<%= link_to "sair", session_url, :method => :delete, :class => 'icon icon-door-out' %>
|
25
|
-
</p>
|
26
|
-
<em><%= current_lotacao.setor.nome %></em>
|
22
|
+
<%= render 'application/login' %>
|
27
23
|
</div>
|
28
24
|
</div>
|
29
25
|
<% end %>
|
30
26
|
<div id='container'>
|
31
27
|
<div id='main'>
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
<% end %>
|
36
|
-
</div>
|
28
|
+
<% flash.each_pair do |k, v| %>
|
29
|
+
<%= content_tag :div, v, :class => "flash #{k}" %>
|
30
|
+
<% end %>
|
37
31
|
|
38
32
|
<%= yield %>
|
39
33
|
</div>
|
40
34
|
</div>
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
<%= link_to "sair", session_url, :method => :delete %>
|
45
|
-
</div>
|
46
|
-
<% end %>
|
35
|
+
<div id='footer'>
|
36
|
+
<%= render 'application/footer' %>
|
37
|
+
</div>
|
47
38
|
</body>
|
48
39
|
</html>
|
@@ -4,7 +4,7 @@ module CmpaAuth
|
|
4
4
|
CLASS_NAMES = %w( Pessoa Estagiario Funcionario GrupoAcesso LotacaoTemporaria Setor Sistema )
|
5
5
|
|
6
6
|
#
|
7
|
-
# Realiza a
|
7
|
+
# Realiza a autenticação e retorna uma pessoa (usuário) caso o login e senha
|
8
8
|
# estejam corretos.
|
9
9
|
#
|
10
10
|
def self.authenticate(login, password)
|
@@ -13,12 +13,13 @@ module CmpaAuth
|
|
13
13
|
end
|
14
14
|
|
15
15
|
#
|
16
|
-
# Retorna uma lista de sistemas
|
16
|
+
# Retorna uma lista de sistemas disponíveis para a lotação temporária em questão.
|
17
17
|
#
|
18
18
|
def self.allowed_systems(lotacao_temporaria_id)
|
19
19
|
lotacao_temporaria = ::LotacaoTemporaria.find(lotacao_temporaria_id)
|
20
20
|
lotacao_temporaria.grupos_acesso.inject([]) do |sistemas, grupo|
|
21
21
|
sistemas += grupo.sistemas.select { |s| !sistemas.include?(s) && s.status == 'ativo' }
|
22
|
+
sistemas
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
data/lib/cmpa_auth/extensions.rb
CHANGED
@@ -17,7 +17,7 @@ module CmpaAuth
|
|
17
17
|
if implemented_klasses.include? klass
|
18
18
|
klass.constantize.send(:include, module_const)
|
19
19
|
|
20
|
-
# O modelo n�o foi definido na aplica��o, ent�o deve-se cri�-lo dinamicamente
|
20
|
+
# O modelo n�o foi definido na aplica��o, ent�o deve-se cri�-lo dinamicamente.
|
21
21
|
else
|
22
22
|
# Descobre qual a superclasse do modelo. Funcion�rio e Estagi�rio tem como superclasse a classe Pessoa.
|
23
23
|
superclass = %w[Estagiario Funcionario].include?(klass) ? ::Pessoa : ActiveRecord::Base
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module CmpaAuth
|
2
2
|
|
3
3
|
#
|
4
|
-
# Implementa a
|
5
|
-
# Todo o controle
|
6
|
-
#
|
4
|
+
# Implementa a autenticação através de um before_filter.
|
5
|
+
# Todo o controle é realizado através de dois ids armazenados na
|
6
|
+
# sessão: current_user_id e lotacao_temporaria_id.
|
7
7
|
#
|
8
|
-
# O
|
9
|
-
# se o
|
8
|
+
# O módulo também oferece suporte a algumas facilidades, como perguntar
|
9
|
+
# se o usuário está logado.
|
10
10
|
#
|
11
11
|
module RailsHelpers
|
12
12
|
def self.included(receiver) #:nodoc:
|
@@ -19,10 +19,44 @@ module CmpaAuth
|
|
19
19
|
|
20
20
|
#
|
21
21
|
# Renderiza uma mensagem de erro HTML to tipo 403 (proibido) nos casos
|
22
|
-
# em que a
|
22
|
+
# em que a exceção CmpaAuth::AccessDenied for disparada.
|
23
23
|
#
|
24
24
|
def render_403
|
25
|
-
render :template => "
|
25
|
+
render :template => "rescues/403", :status => 403, :layout => false
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Permite sobrescrever o comportamento do filtro de autenticação padrão.
|
30
|
+
#
|
31
|
+
# === Exemplos
|
32
|
+
#
|
33
|
+
# class PostController < ApplicationController
|
34
|
+
# check_authentication :except => :index
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# class NewsController < ApplicationController
|
38
|
+
# check_authentication :only => [:new, :create, :edit, :update]
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
def self.cmpa_authenticate(options = {})
|
42
|
+
options.to_options!
|
43
|
+
this_controller_name = controller_name
|
44
|
+
actions = Array(options[:only] || options[:except]).map(&:to_s)
|
45
|
+
|
46
|
+
self.class_eval do
|
47
|
+
if options[:only]
|
48
|
+
define_method :check_authentication do
|
49
|
+
redirect_to new_session_url if !logged_in? && controller_name == this_controller_name && actions.include?(action_name)
|
50
|
+
end
|
51
|
+
elsif options[:except]
|
52
|
+
define_method :check_authentication do
|
53
|
+
redirect_to new_session_url if !logged_in? && controller_name == this_controller_name && !actions.include?(action_name)
|
54
|
+
end
|
55
|
+
else
|
56
|
+
# Como o método check_authentication não foi sobrescrito a sua
|
57
|
+
# implementação padrão será chamada.
|
58
|
+
end
|
59
|
+
end
|
26
60
|
end
|
27
61
|
|
28
62
|
private
|
@@ -32,21 +66,21 @@ module CmpaAuth
|
|
32
66
|
end
|
33
67
|
|
34
68
|
#
|
35
|
-
# Retorna o
|
69
|
+
# Retorna o usuário logado na sessão.
|
36
70
|
#
|
37
71
|
def current_user
|
38
72
|
@current_user ||= ::Pessoa.find_by_id(session[:current_user_id])
|
39
73
|
end
|
40
74
|
|
41
75
|
#
|
42
|
-
# Retorna a
|
76
|
+
# Retorna a lotação temporária atual (aquela que o usuário escolheu ao
|
43
77
|
# logar no sistema).
|
44
78
|
#
|
45
79
|
def current_lotacao
|
46
80
|
@current_lotacao ||= ::LotacaoTemporaria.find_by_id(session[:lotacao_temporaria_id])
|
47
81
|
end
|
48
82
|
|
49
|
-
# Verifica se o
|
83
|
+
# Verifica se o usuário está logado.
|
50
84
|
def logged_in?
|
51
85
|
current_user && current_lotacao
|
52
86
|
end
|
data/lib/cmpa_auth.rb
CHANGED
@@ -16,7 +16,7 @@ require 'cmpa_auth/rails_helpers'
|
|
16
16
|
require 'cmpa_auth/extensions'
|
17
17
|
|
18
18
|
# Copia as imagens dos sistemas para a pasta public/images/sistemas da aplicação.
|
19
|
-
images_src = File.
|
19
|
+
images_src = "#{File.dirname(__FILE__)}/../public/images/sistemas/*"
|
20
20
|
images_dst = "#{Rails.public_path}/images/sistemas/"
|
21
21
|
FileUtils.mkdir_p images_dst
|
22
22
|
FileUtils.cp_r Dir.glob(images_src), images_dst
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmpa_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "CMPA Assessoria de Inform\xC3\xA1tica"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11
|
12
|
+
date: 2009-12-11 00:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -43,17 +43,19 @@ files:
|
|
43
43
|
- lib/cmpa_auth.rb
|
44
44
|
- app/controllers/sessions_controller.rb
|
45
45
|
- app/helpers/sessions_helper.rb
|
46
|
-
- app/views/
|
46
|
+
- app/views/application/_footer.html.erb
|
47
|
+
- app/views/application/_login.html.erb
|
47
48
|
- app/views/layouts/sessions.html.erb
|
49
|
+
- app/views/rescues/403.html.erb
|
48
50
|
- app/views/sessions/index.html.erb
|
49
51
|
- app/views/sessions/new.html.erb
|
50
52
|
- app/views/sessions/selecao_lotacao_temporaria.html.erb
|
51
|
-
- config/config.yml
|
52
53
|
- config/routes.rb
|
53
54
|
- public/images/sistemas/administrativo.png
|
54
55
|
- public/images/sistemas/agenda.png
|
55
56
|
- public/images/sistemas/aviso.png
|
56
57
|
- public/images/sistemas/central_transportes.png
|
58
|
+
- public/images/sistemas/contratos.png
|
57
59
|
- public/images/sistemas/controle_acesso.png
|
58
60
|
- public/images/sistemas/convenios.png
|
59
61
|
- public/images/sistemas/cotas.png
|
data/config/config.yml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
development:
|
2
|
-
session_key: _camarapoa
|
3
|
-
secret: 6d3fb2a0cd7a049e27f77c8ca73fd590552776e47de47e3c7a44638bd4ab8add7140c11edd892a4d9d019d643a068c88d1a30c72b544b453ccdd8774a17ac589112081c779f51834a567314b95a0cdda01fe977b16440b721f6fde71ce0130b70c5bf90d1066bdef4e5ec08dca457522b0b399cf4567603b377efb28f701fc78
|
4
|
-
|
5
|
-
production:
|
6
|
-
session_key: _camarapoa
|
7
|
-
secret: 6d3fb2a0cd7a049e27f77c8ca73fd590552776e47de47e3c7a44638bd4ab8add7140c11edd892a4d9d019d643a068c88d1a30c72b544b453ccdd8774a17ac589112081c779f51834a567314b95a0cdda01fe977b16440b721f6fde71ce0130b70c5bf90d1066bdef4e5ec08dca457522b0b399cf4567603b377efb28f701fc78
|
File without changes
|