cmpa_auth 1.0.4 → 1.0.5

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 CHANGED
@@ -1,3 +1,10 @@
1
+ == 1.0.5 released 2010-04-03
2
+
3
+ * Atualiza��o de layout. Agora as telas de autentica��o, sele��o de lota��es tempor�rias e de sistemas s�o independentes do projeto em uso.
4
+ * Trocado <tt>all</tt> por <tt>scoped</tt> em <tt>Pessoa#lotacoes_temporarias_ativas</tt>.
5
+ * Refatora��es no controller de <tt>sessions</tt>.
6
+ * Tela de login e sele��o de lota��es tempor�rias utilizam AJAX para agilizar a entrada no sistema.
7
+
1
8
  == 1.0.4 released 2009-12-16
2
9
 
3
10
  * Renomeado o before_filter de autentica��o <tt>check_authentication</tt> para <tt>cmpa_authenticate</tt>.
@@ -13,9 +20,7 @@
13
20
  == 1.0.2 released 2009-11-08
14
21
 
15
22
  * Documenta��o melhorada.
16
- * Atualiza��o do m�todo <tt>LotacaoTemporaria#method_missing</tt> para que ele
17
- defina os m�todos que n�o existirem e que comecem por <i>in_groups_of</i> ou
18
- <i>role_of</i>.
23
+ * Atualiza��o do m�todo <tt>LotacaoTemporaria#method_missing</tt> para que ele defina os m�todos que n�o existirem e que comecem por <i>in_groups_of</i> ou <i>role_of</i>.
19
24
 
20
25
  == 1.0.1 released 2009-11-05
21
26
 
@@ -11,38 +11,31 @@ class SessionsController < ApplicationController
11
11
  end
12
12
 
13
13
  def create
14
- user = CmpaAuth::Authentication.authenticate(params[:login], params[:password])
15
- if user
14
+ if user = CmpaAuth::Authentication.authenticate(params[:login], params[:password])
16
15
  session[:current_user_id] = user.id
17
- lotacoes_ativas = user.lotacoes_temporarias_ativas
18
- if lotacoes_ativas.size == 1
19
- session[:lotacao_temporaria_id] = lotacoes_ativas.first.id
20
- redirect_to root_url
21
- elsif lotacoes_ativas.many?
22
- redirect_to selecao_lotacao_temporaria_url(user.id)
16
+ @lotacoes_temporarias = current_user.lotacoes_temporarias_ativas
17
+ if @lotacoes_temporarias.size == 1
18
+ session[:lotacao_temporaria_id] = @lotacoes_temporarias.first.id
19
+ head :ok, :location => root_url
20
+ elsif @lotacoes_temporarias.many?
21
+ render :lotacoes_temporarias, :layout => false
23
22
  else
24
- flash.now[:error] = "Você não possui lotacões temporárias. Por favor, entre em contato com a Assessoria de Informática"
25
- render :new
23
+ render :text => "Você não possui lotacões temporárias. Por favor, entre em contato com a Assessoria de Informática", :status => :forbidden
26
24
  end
27
25
  else
28
- flash.now[:error] = "Usuário e/ou senha incorretos!"
29
- render :new
26
+ render :text => 'Usuário e/ou senha incorretos', :status => :forbidden
30
27
  end
31
28
  end
32
29
 
33
30
  def destroy
34
- reset_session
35
- flash[:notice] = "Logout efetuado!"
36
- redirect_to new_session_url
31
+ session[:current_user_id] = session[:lotacao_temporaria_id] = nil
32
+ flash[:notice] = "Logout efetuado"
33
+ redirect_to root_url
37
34
  end
38
35
 
39
- def selecao_lotacao_temporaria
40
- if params[:lotacao_selecionada]
41
- session[:lotacao_temporaria_id] = params[:pessoa_id]
42
- redirect_to root_url
43
- else
44
- user = Pessoa.find(params[:pessoa_id])
45
- @lotacoes_temporarias = user.lotacoes_temporarias_ativas
46
- end
36
+ def set_lotacao_temporaria
37
+ lotacao_temporaria = current_user.lotacoes_temporarias_ativas.find(params[:lotacao_temporaria_id])
38
+ session[:lotacao_temporaria_id] = lotacao_temporaria.id
39
+ redirect_to root_url
47
40
  end
48
41
  end
@@ -13,4 +13,12 @@ module SessionsHelper
13
13
 
14
14
  link_to sistema.nome.capitalize, "http://#{url_options[:host]}:#{url_options[:port]}#{url_options[:controller]}", options, html_options
15
15
  end
16
- end
16
+
17
+ def flash_message
18
+ if key = flash.keys.first
19
+ content_tag :div, :id => 'flash', :class => key do
20
+ flash[key] + link_to('Fechar &times;', '#', :id => 'close-flash')
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  &copy; Assessoria de Informática CMPA
2
2
  <% if logged_in? %>
3
3
  &nbsp;|
4
- <%= link_to "sair", session_url, :method => :delete %>
4
+ <%= link_to "Sair", session_url, :method => :delete %>
5
5
  <% end %>
@@ -0,0 +1,11 @@
1
+ <% if logged_in? %>
2
+ <% link_to session_path, :method => :delete do %>
3
+ <%= image_tag 'icons/16x16/door_out.png' %>
4
+ Sair
5
+ <% end %>
6
+ <% else %>
7
+ <% link_to new_session_path do %>
8
+ <%= image_tag 'icons/16x16/door_in.png' %>
9
+ Entrar
10
+ <% end %>
11
+ <% end %>
@@ -2,17 +2,10 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>PortalCMPA - Gerenciamento de Acesso</title>
5
- <%= stylesheet_link_tag 'application' %>
6
- <%= javascript_include_tag 'jquery' %>
7
-
8
- <script type="text/javascript">
9
- jQuery(function($) {
10
- $('#focus').focus();
11
- $('#menu > li:first-child a').addClass('selected');
12
- });
13
- </script>
5
+ <%= stylesheet_link_tag 'jqueryui', 'application' %>
6
+ <%= javascript_include_tag 'jquery', 'jqueryui' %>
14
7
  </head>
15
- <body>
8
+ <body id='cmpa-auth'>
16
9
  <% if logged_in? %>
17
10
  <div id='header'>
18
11
  <ul id='menu'>
@@ -23,17 +16,23 @@
23
16
  </div>
24
17
  </div>
25
18
  <% end %>
19
+ <%= flash_message %>
26
20
  <div id='container'>
27
21
  <div id='main'>
28
- <% flash.each_pair do |k, v| %>
29
- <%= content_tag :div, v, :class => "flash #{k}" %>
30
- <% end %>
31
-
32
22
  <%= yield %>
33
23
  </div>
34
24
  </div>
35
25
  <div id='footer'>
36
26
  <%= render 'application/footer' %>
37
27
  </div>
28
+
29
+ <script type='text/javascript'>
30
+ // Exibe e anima mensagens de flash.
31
+ $flash = $('#flash');
32
+ $flash.hide().fadeIn('slow').delay(10000).fadeOut('slow');
33
+ $('a#close-flash').click(function() {
34
+ $flash.stop().fadeOut('slow');
35
+ });
36
+ </script>
38
37
  </body>
39
- </html>
38
+ </html>
@@ -0,0 +1,8 @@
1
+ <div id='lotacoes'>
2
+ <h2>Olá <em><%= current_user.usuario %></em>, selecione um setor para operar o sistema</h2>
3
+ <ul>
4
+ <% @lotacoes_temporarias.each do |lt| %>
5
+ <li><%= link_to lt.setor.nome, set_lotacao_temporaria_path(lt.id) %></li>
6
+ <% end %>
7
+ </ul>
8
+ </div>
@@ -0,0 +1,67 @@
1
+ <% form_tag session_path, :class => 'login' do %>
2
+ <h2>Área restrita. Por favor, efetue login.</h2>
3
+ <p>
4
+ <%= label_tag :login, 'Usuário:' %>
5
+ <%= text_field_tag :login, params[:login], :size => 30, :class => 'focus' %>
6
+ </p>
7
+ <p>
8
+ <%= label_tag :password, 'Senha:' %>
9
+ <%= password_field_tag :password, params[:password], :size => 30 %>
10
+ </p>
11
+ <%= submit_tag 'Entrar' %>
12
+ <% end %>
13
+
14
+ <script type='text/javascript'>
15
+ jQuery(function($) {
16
+ $('form .focus').focus();
17
+
18
+ $dialog = $('<div>');
19
+ $dialog.dialog({
20
+ title: 'Seleção de Lotação Temporária',
21
+ autoOpen: false,
22
+ minHeight: 200,
23
+ minWidth: 300,
24
+ maxWidth: 800,
25
+ maxHeight: 500,
26
+ width: 600,
27
+ modal: true
28
+ });
29
+
30
+ var flash = $('<div id="flash" class="error">');
31
+
32
+ // Muda o texto do botão de submit e depois desabilita.
33
+ // Quando a chamada ajax for completada restaura o botão às suas condições originais.
34
+ var submitButtonVal = $('form.login :submit').val();
35
+ $('form.login')
36
+ .ajaxSend(function() { $(this).find(':submit').val('Aguarde...').attr('disabled', true); })
37
+ .ajaxComplete(function() { $(this).find(':submit').val(submitButtonVal).attr('disabled', false); });
38
+
39
+ $('form.login').submit(function() {
40
+ $.ajax({
41
+ url: '/session',
42
+ type: 'post',
43
+ data: $(this).serialize(),
44
+ success: function(data, status, request) {
45
+ var location = request.getResponseHeader('location');
46
+ if (location) {
47
+ window.location = location;
48
+ } else {
49
+ $dialog.html(data).dialog('open');
50
+ $('#flash').remove();
51
+ }
52
+ },
53
+ error: function(request) {
54
+ $('#flash').remove();
55
+ $('#container').prepend(flash.html(request.responseText)
56
+ .fadeIn('slow').delay(10000).fadeOut('slow')); // Anima a mensagem.
57
+ }
58
+ });
59
+ return false;
60
+ });
61
+
62
+ $('#lotacoes ul a').live('click', function() {
63
+ $dialog.dialog('close');
64
+ window.location = this.href;
65
+ });
66
+ });
67
+ </script>
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
2
 
3
3
  map.resource :session, :path_names => { :new => 'entrar' }
4
- map.selecao_lotacao_temporaria '/session/selecao_lotacao_temporaria/:pessoa_id', :controller => 'sessions', :action => 'selecao_lotacao_temporaria'
4
+ map.set_lotacao_temporaria '/session/set_lotacao_temporaria/:lotacao_temporaria_id', :controller => 'sessions', :action => 'set_lotacao_temporaria'
5
5
  end
@@ -9,7 +9,7 @@ module CmpaAuth
9
9
  set_table_name :pessoas
10
10
 
11
11
  def lotacoes_temporarias_ativas
12
- ::LotacaoTemporaria.all(:conditions => {:fim => nil, :pessoa_id => id})
12
+ ::LotacaoTemporaria.scoped(:conditions => {:fim => nil, :pessoa_id => id})
13
13
  end
14
14
 
15
15
  def senha=(pass)
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
4
+ version: 1.0.5
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-12-16 00:00:00 -02:00
12
+ date: 2010-04-04 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -43,13 +43,13 @@ files:
43
43
  - lib/cmpa_auth.rb
44
44
  - app/controllers/sessions_controller.rb
45
45
  - app/helpers/sessions_helper.rb
46
- - app/views/application/_footer.html.erb
47
- - app/views/application/_login.html.erb
48
- - app/views/layouts/sessions.html.erb
49
- - app/views/rescues/403.html.erb
50
- - app/views/sessions/index.html.erb
51
- - app/views/sessions/new.html.erb
52
- - app/views/sessions/selecao_lotacao_temporaria.html.erb
46
+ - app/views/application/_footer.erb
47
+ - app/views/application/_login.erb
48
+ - app/views/layouts/sessions.erb
49
+ - app/views/rescues/403.erb
50
+ - app/views/sessions/index.erb
51
+ - app/views/sessions/lotacoes_temporarias.erb
52
+ - app/views/sessions/new.erb
53
53
  - config/routes.rb
54
54
  - public/images/sistemas/administrativo.png
55
55
  - public/images/sistemas/agenda.png
@@ -1,10 +0,0 @@
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 %>
@@ -1,18 +0,0 @@
1
- <div class='form' style='width:40em'>
2
- <h3>Área restrita. Por favor, efetue login.</h3>
3
- <% form_tag session_path, :id => 'login' do %>
4
- <p>
5
- <%= label_tag :login, 'Usuário:' %>
6
- <%= text_field_tag :login, params[:login], :size => 20, :id => 'focus' %>
7
- </p>
8
-
9
- <p>
10
- <%= label_tag :password, 'Senha:' %>
11
- <%= password_field_tag :password, params[:password], :size => 20 %>
12
- </p>
13
-
14
- <ul>
15
- <li><%= submit_tag 'Entrar' %></li>
16
- </ul>
17
- <% end %>
18
- </div>
@@ -1,6 +0,0 @@
1
- <h2 class='title'>Olá <%= current_user.usuario %>, selecione o setor pelo qual você deseja operar o sistema</h2>
2
- <ul class='list'>
3
- <% @lotacoes_temporarias.each do |lt| %>
4
- <li><%= link_to lt.setor.nome, selecao_lotacao_temporaria_path(lt.id, :lotacao_selecionada => :sim) %></li>
5
- <% end %>
6
- </ul>
File without changes
File without changes