devise-automaticlogout 0.1.0 → 1.0.2
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.
- checksums.yaml +5 -5
- data/README.md +100 -19
- data/app/controllers/automaticlogout_controller.rb +9 -0
- data/app/views/automatic_logout/_timer.html.erb +9 -4
- data/config/routes.rb +1 -2
- data/lib/assets/javascripts/automatic_logout.js +82 -86
- data/lib/assets/javascripts/automatic_logout/classic.js +4 -0
- data/lib/assets/javascripts/automatic_logout/jquery.js +4 -0
- data/lib/assets/javascripts/automatic_logout/turbolinks-classic.js +5 -0
- data/lib/assets/javascripts/automatic_logout/turbolinks.js +5 -0
- data/lib/devise/automaticlogout/controllers.rb +22 -26
- data/lib/devise/automaticlogout/engine.rb +4 -4
- data/lib/devise/automaticlogout/helpers.rb +3 -3
- data/lib/devise/automaticlogout/version.rb +1 -1
- metadata +25 -34
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: aca65c04b699ce7cb31abf9b49dab1febc2a4f482f625e287e9ae3f719c2d1aa
         | 
| 4 | 
            +
              data.tar.gz: cb44d36d8a3b55fbdd67bd08d0a08f8c8d5d5ba6da4cfbcdc0f6270030413dc7
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: dc5dfb45b4b13ffef4a0fab14e88c8b5c68890b494f09da2a739dac22c16a8625fd73472e72685edba97c6bf940680e72c60188de2faac834e433e705e60ead9
         | 
| 7 | 
            +
              data.tar.gz: 686250322f63cb25a803b2f004da123a1b5643efca8f1dbb6e794198b073d01487928012949af72c09ab17a84276d04bd5c22bfbf98479e1b38274f9413a678f
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,47 +1,128 @@ | |
| 1 1 | 
             
            # Devise Automatic Logout
         | 
| 2 | 
            +
             | 
| 2 3 | 
             
            By Thadeu Esteves Jr.
         | 
| 3 4 |  | 
| 4 | 
            -
             | 
| 5 | 
            +
            Provê um logout automático da sessão numa aplicação Rails utilizando Devise. É simples e fácil.
         | 
| 6 | 
            +
            Faz com que a sessão seja destruída após a conclusão do tempo estipulado. É de grande ajuda em sistemas que necessitam de sessão auto destrutiva, evitando de o usuário ficar logado por muito tempo de forma ociosa.
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## O que isso faz?
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            * Força o usuário a sair da sessão (logout)
         | 
| 11 | 
            +
            * Opção de mostrar um timer regressivo
         | 
| 12 | 
            +
            * Opção de dar um alerta na tela ao ser deslogado
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            ## Começando
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            Adicione ao seu Gemfile
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            ```ruby
         | 
| 19 | 
            +
            gem 'devise-automaticlogout', '~> 1.0.1'
         | 
| 20 | 
            +
            ```
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            Rode o `bundle install`
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            ## Configure o controller
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            No controller que você deseja aplicar o timer para o devise, use:
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ```ruby
         | 
| 29 | 
            +
            devise_automatic_logout
         | 
| 30 | 
            +
            ```
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            Por exemplo, para o comum ApplicationController, poderia ser
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            ```ruby
         | 
| 35 | 
            +
            class ApplicationController < ActionController::Base
         | 
| 36 | 
            +
              devise_automatic_logout
         | 
| 37 | 
            +
            end
         | 
| 38 | 
            +
            ```
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            Isso por si só, já prepara a aplicação para ler os dados do `Devise#timeout_in`, utilizando o scope padrão `user` e uma mensagem padrão de alerta.
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            Mas se você quiser, configurar um tempo diferente do timeout_in do devise? Fácil, use o seguinte:
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            ```ruby
         | 
| 45 | 
            +
            devise_automatic_logout time: 1.hour.to_i
         | 
| 46 | 
            +
            ```
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            Isso vai aplicar 1 hora para o logout automático. 
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            Mas e se você quiser colocar outra mensagem? Fácil, use o seguinte:
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            ```ruby
         | 
| 53 | 
            +
            devise_automatic_logout time: 1.hour.to_i, message: 'SUA MENSAGEM'
         | 
| 54 | 
            +
            ```
         | 
| 5 55 |  | 
| 6 | 
            -
             | 
| 7 | 
            -
            * show for they the regressive time
         | 
| 56 | 
            +
            Mas e se você quiser fazer, com que seja utilizado outro tipo de mapping do devise? Fácil, use o seguinte:
         | 
| 8 57 |  | 
| 9 | 
            -
             | 
| 58 | 
            +
            ```ruby
         | 
| 59 | 
            +
            devise_automatic_logout scope: 'member'
         | 
| 60 | 
            +
            ```
         | 
| 10 61 |  | 
| 11 | 
            -
             | 
| 62 | 
            +
            É possível também utilizar todos de uma vez só, por exemplo
         | 
| 12 63 |  | 
| 13 64 | 
             
            ```ruby
         | 
| 14 | 
            -
             | 
| 65 | 
            +
            devise_automatic_logout time: 15.minutes.to_i, message: 'Sua sessão expirou! Faça login novamente.', scope: 'member'
         | 
| 15 66 | 
             
            ```
         | 
| 16 67 |  | 
| 17 | 
            -
             | 
| 68 | 
            +
            __OBS: Quando o `time` não é passado, o timeout_in do devise será aplicado, se configurado, é claro!__
         | 
| 18 69 |  | 
| 19 | 
            -
            ##  | 
| 70 | 
            +
            ## Configurando Timeoutable
         | 
| 20 71 |  | 
| 21 | 
            -
             | 
| 72 | 
            +
            Veja na documentação do próprio devise como fazer isso.
         | 
| 22 73 |  | 
| 23 | 
            -
             | 
| 74 | 
            +
            [Configurar o tempo](https://github.com/plataformatec/devise#configuring-models)
         | 
| 24 75 |  | 
| 25 | 
            -
            [ | 
| 76 | 
            +
            [Mais informações sobre Timeoutable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable)
         | 
| 26 77 |  | 
| 27 | 
            -
             | 
| 78 | 
            +
            ## Configurando o timer regressivo (OBRIGATÓRIO)
         | 
| 28 79 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 80 | 
            +
            Esse helper deve ser usado em qualquer view, ele é importante, pois tudo será baseado nele
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            ```ruby
         | 
| 83 | 
            +
            <%= regressive_timer visible: true, alert: true %>
         | 
| 84 | 
            +
            ```
         | 
| 85 | 
            +
             | 
| 86 | 
            +
            * visible: mostra um timer regressivo
         | 
| 87 | 
            +
            * alert: lança um `window.alert` se ativado, ao final do timer
         | 
| 88 | 
            +
             | 
| 89 | 
            +
            ## Configurando Javascript
         | 
| 90 | 
            +
             | 
| 91 | 
            +
            Adicione no seu application.js, o seguinte:
         | 
| 31 92 |  | 
| 32 93 | 
             
            ```javascript
         | 
| 33 94 | 
             
            //= require automatic_logout
         | 
| 34 95 | 
             
            ```
         | 
| 35 | 
            -
            ### Configure View (OPTIONAL)
         | 
| 36 96 |  | 
| 37 | 
            -
             | 
| 97 | 
            +
            Se você usa vanilla js, adicionar também o seguinte:
         | 
| 38 98 |  | 
| 39 | 
            -
            ``` | 
| 40 | 
            -
             | 
| 99 | 
            +
            ```javascript
         | 
| 100 | 
            +
            //= require automatic_logout/classic
         | 
| 101 | 
            +
            ```
         | 
| 102 | 
            +
             | 
| 103 | 
            +
            Se você usa jQuery, use:
         | 
| 104 | 
            +
             | 
| 105 | 
            +
            ```javascript
         | 
| 106 | 
            +
            //= require automatic_logout/jquery
         | 
| 107 | 
            +
            ```
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            Se você usa Turbolinks mais atual, use:
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            ```javascript
         | 
| 112 | 
            +
            //= require automatic_logout/turbolinks
         | 
| 41 113 | 
             
            ```
         | 
| 42 114 |  | 
| 43 | 
            -
             | 
| 115 | 
            +
            Se você usa Turbolinks mais antigo, use:
         | 
| 44 116 |  | 
| 117 | 
            +
            ```javascript
         | 
| 118 | 
            +
            //= require automatic_logout/turbolinks-classic
         | 
| 119 | 
            +
            ```
         | 
| 120 | 
            +
             | 
| 121 | 
            +
            Se preferir, use manualmente em algum momento desejado
         | 
| 122 | 
            +
             | 
| 123 | 
            +
            ```javascript
         | 
| 124 | 
            +
            AutomaticLogout.load();
         | 
| 125 | 
            +
            ```
         | 
| 45 126 |  | 
| 46 127 | 
             
            ## Contributing
         | 
| 47 128 |  | 
| @@ -1,4 +1,9 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
               | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 1 | 
            +
            <% unless request.env["devise.skip_timeout"] %>
         | 
| 2 | 
            +
              <span class="regressive-timer"
         | 
| 3 | 
            +
                style="<%= "display: #{visible ? 'block' : 'none'}" %>"
         | 
| 4 | 
            +
                data-visible="<%= visible %>"
         | 
| 5 | 
            +
                data-alert="<%= alert.presence || false %>"
         | 
| 6 | 
            +
                data-seconds="<%= session[:devise_autl_seconds] %>"
         | 
| 7 | 
            +
                data-message="<%= session[:devise_autl_message] %>">
         | 
| 8 | 
            +
              </span>
         | 
| 9 | 
            +
            <% end %>
         | 
    
        data/config/routes.rb
    CHANGED
    
    
| @@ -2,72 +2,105 @@ | |
| 2 2 | 
             
             * Module AutomaticLogout for JS Files
         | 
| 3 3 | 
             
             * @type {[type]}
         | 
| 4 4 | 
             
             */
         | 
| 5 | 
            -
             | 
| 5 | 
            +
            window.AutomaticLogout = {};
         | 
| 6 6 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
               | 
| 9 | 
            -
              var $regressiveTimer = $('.regressive-timer');
         | 
| 7 | 
            +
            AutomaticLogout.load = function () {
         | 
| 8 | 
            +
              var $regressiveTimer = document.querySelectorAll(".regressive-timer")[0];
         | 
| 10 9 |  | 
| 11 | 
            -
              ($regressiveTimer. | 
| 12 | 
            -
             | 
| 13 | 
            -
                 | 
| 14 | 
            -
             | 
| 15 | 
            -
            } | 
| 10 | 
            +
              if (!!$regressiveTimer && $regressiveTimer.dataset.seconds != "") {
         | 
| 11 | 
            +
                console.log("[AutomaticLogout] regressiveTimer started");
         | 
| 12 | 
            +
                AutomaticLogout.regressiveTimer();
         | 
| 13 | 
            +
              }
         | 
| 14 | 
            +
            };
         | 
| 16 15 |  | 
| 17 16 | 
             
            /**
         | 
| 18 17 | 
             
             * Send request for destroy session current_user
         | 
| 19 18 | 
             
             * @return {[type]} [description]
         | 
| 20 19 | 
             
             */
         | 
| 21 | 
            -
            AutomaticLogout.destroySession = function(){
         | 
| 22 | 
            -
               | 
| 23 | 
            -
             | 
| 20 | 
            +
            AutomaticLogout.destroySession = function (message) {
         | 
| 21 | 
            +
              var xhr = new XMLHttpRequest();
         | 
| 22 | 
            +
              xhr.open("GET", "/automatic_logout/destroy", true);
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              xhr.onload = function () {
         | 
| 25 | 
            +
                if (xhr.status == 200) {
         | 
| 26 | 
            +
                  var $wrapper = document.querySelectorAll(".regressive-timer")[0];
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  if ($wrapper && eval($wrapper.dataset.alert) && message) {
         | 
| 29 | 
            +
                    window.alert(message);
         | 
| 30 | 
            +
                  }
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  return (window.location.href = "/");
         | 
| 33 | 
            +
                }
         | 
| 34 | 
            +
              };
         | 
| 35 | 
            +
              xhr.send();
         | 
| 36 | 
            +
            };
         | 
| 24 37 |  | 
| 25 38 | 
             
            /**
         | 
| 26 39 | 
             
             * Method regressive time based in session auto expired at.
         | 
| 27 40 | 
             
             * @param  {[type]} date_session [description]
         | 
| 28 41 | 
             
             * @return {[type]}              [description]
         | 
| 29 42 | 
             
             */
         | 
| 30 | 
            -
            AutomaticLogout.regressiveTimer = function(){ | 
| 43 | 
            +
            AutomaticLogout.regressiveTimer = function () {
         | 
| 44 | 
            +
              /**
         | 
| 45 | 
            +
               * Define o que vai ser impresso no DOM.
         | 
| 46 | 
            +
               * @param {DOM Object} container
         | 
| 47 | 
            +
               * @param {Boolean} visible
         | 
| 48 | 
            +
               * @param {String} textContent
         | 
| 49 | 
            +
               */
         | 
| 50 | 
            +
              var visibleTimer = function (container, visible, textContent) {
         | 
| 51 | 
            +
                if (!visible) visible = "false";
         | 
| 52 | 
            +
                if (!textContent) textContent = "00:00:00";
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                if (visible == "true") {
         | 
| 55 | 
            +
                  return (container.textContent = textContent);
         | 
| 56 | 
            +
                }
         | 
| 57 | 
            +
              };
         | 
| 58 | 
            +
             | 
| 31 59 | 
             
              /**
         | 
| 32 60 | 
             
               * Variables used
         | 
| 33 61 | 
             
               * @param  {[type]} '.regressive-timer' [description]
         | 
| 34 62 | 
             
               * @return {[type]}                     [description]
         | 
| 35 63 | 
             
               */
         | 
| 36 | 
            -
              var  | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 64 | 
            +
              var $regressiveTimer = document.querySelector(".regressive-timer"),
         | 
| 65 | 
            +
                data_message = String($regressiveTimer.dataset.message),
         | 
| 66 | 
            +
                data_seconds = Number($regressiveTimer.dataset.seconds),
         | 
| 67 | 
            +
                current_time = new Date().getTime();
         | 
| 68 | 
            +
             | 
| 69 | 
            +
              visibleTimer($regressiveTimer, $regressiveTimer.dataset.visible);
         | 
| 39 70 |  | 
| 40 71 | 
             
              var time_expired = new Date();
         | 
| 41 72 | 
             
              time_expired.setSeconds(time_expired.getSeconds() + data_seconds);
         | 
| 42 73 |  | 
| 43 | 
            -
              if (data_seconds != 0 && data_seconds !=  | 
| 44 | 
            -
                var timerDecrement = setInterval(function(){
         | 
| 45 | 
            -
                  
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                    clearInterval(timerDecrement); 
         | 
| 48 | 
            -
             | 
| 74 | 
            +
              if (data_seconds != 0 && data_seconds != "") {
         | 
| 75 | 
            +
                var timerDecrement = setInterval(function () {
         | 
| 76 | 
            +
                  if (data_seconds == 0) {
         | 
| 77 | 
            +
                    clearInterval(timerDecrement);
         | 
| 49 78 | 
             
                    // limpa a sessão após o ok
         | 
| 50 | 
            -
                     | 
| 51 | 
            -
             | 
| 52 | 
            -
                    };
         | 
| 53 | 
            -
                  }else{
         | 
| 79 | 
            +
                    AutomaticLogout.destroySession(data_message);
         | 
| 80 | 
            +
                  } else {
         | 
| 54 81 | 
             
                    //tempo descrecente
         | 
| 55 82 | 
             
                    time_expired.setSeconds(time_expired.getSeconds() - 1);
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                    var 
         | 
| 58 | 
            -
                       | 
| 59 | 
            -
                       | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 83 | 
            +
             | 
| 84 | 
            +
                    var seconds_integer = (time_expired.getTime() - current_time) / 1000,
         | 
| 85 | 
            +
                      date_format = AutomaticLogout.parseDate(seconds_integer),
         | 
| 86 | 
            +
                      output_date_format =
         | 
| 87 | 
            +
                        date_format.hours +
         | 
| 88 | 
            +
                        ":" +
         | 
| 89 | 
            +
                        date_format.minutes +
         | 
| 90 | 
            +
                        ":" +
         | 
| 91 | 
            +
                        date_format.seconds;
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                    visibleTimer(
         | 
| 94 | 
            +
                      $regressiveTimer,
         | 
| 95 | 
            +
                      $regressiveTimer.dataset.visible,
         | 
| 96 | 
            +
                      output_date_format
         | 
| 97 | 
            +
                    );
         | 
| 65 98 | 
             
                  }
         | 
| 66 | 
            -
             | 
| 99 | 
            +
             | 
| 67 100 | 
             
                  data_seconds -= 1;
         | 
| 68 | 
            -
                }, 1000)
         | 
| 101 | 
            +
                }, 1000);
         | 
| 69 102 | 
             
              }
         | 
| 70 | 
            -
            }
         | 
| 103 | 
            +
            };
         | 
| 71 104 |  | 
| 72 105 | 
             
            /**
         | 
| 73 106 | 
             
             * Parse Date
         | 
| @@ -79,12 +112,8 @@ AutomaticLogout.regressiveTimer = function(){; | |
| 79 112 | 
             
             *   seconds: seconds
         | 
| 80 113 | 
             
             * }
         | 
| 81 114 | 
             
             */
         | 
| 82 | 
            -
            AutomaticLogout.parseDate = function(seconds_float){
         | 
| 83 | 
            -
             | 
| 84 | 
            -
              var days,
         | 
| 85 | 
            -
                  hours,
         | 
| 86 | 
            -
                  minutes,
         | 
| 87 | 
            -
                  seconds;
         | 
| 115 | 
            +
            AutomaticLogout.parseDate = function (seconds_float) {
         | 
| 116 | 
            +
              var days, hours, minutes, seconds;
         | 
| 88 117 |  | 
| 89 118 | 
             
              days = parseInt(seconds_float / 86400);
         | 
| 90 119 | 
             
              seconds_float = seconds_float % 86400;
         | 
| @@ -95,57 +124,24 @@ AutomaticLogout.parseDate = function(seconds_float){ | |
| 95 124 | 
             
              minutes = parseInt(seconds_float / 60);
         | 
| 96 125 | 
             
              seconds = parseInt(seconds_float % 60);
         | 
| 97 126 |  | 
| 98 | 
            -
              if(hours < 10){
         | 
| 99 | 
            -
                hours = "0"+hours;
         | 
| 127 | 
            +
              if (hours < 10) {
         | 
| 128 | 
            +
                hours = "0" + hours;
         | 
| 100 129 | 
             
                hours = hours.substr(0, 2);
         | 
| 101 130 | 
             
              }
         | 
| 102 131 |  | 
| 103 | 
            -
              if(minutes < 10){
         | 
| 104 | 
            -
                minutes = "0"+minutes;
         | 
| 132 | 
            +
              if (minutes < 10) {
         | 
| 133 | 
            +
                minutes = "0" + minutes;
         | 
| 105 134 | 
             
                minutes = minutes.substr(0, 2);
         | 
| 106 135 | 
             
              }
         | 
| 107 136 |  | 
| 108 | 
            -
              if(seconds <=9){
         | 
| 109 | 
            -
                seconds = "0"+seconds;
         | 
| 137 | 
            +
              if (seconds <= 9) {
         | 
| 138 | 
            +
                seconds = "0" + seconds;
         | 
| 110 139 | 
             
              }
         | 
| 111 140 |  | 
| 112 141 | 
             
              return {
         | 
| 113 142 | 
             
                days: days,
         | 
| 114 143 | 
             
                hours: hours,
         | 
| 115 144 | 
             
                minutes: minutes,
         | 
| 116 | 
            -
                seconds: seconds
         | 
| 117 | 
            -
              }
         | 
| 118 | 
            -
            }
         | 
| 119 | 
            -
             | 
| 120 | 
            -
            /**
         | 
| 121 | 
            -
             * Method for request ajax, check value e logout
         | 
| 122 | 
            -
             * @return {[type]} [description]
         | 
| 123 | 
            -
             */
         | 
| 124 | 
            -
            AutomaticLogout.ajaxSessionTimeout = function(){
         | 
| 125 | 
            -
              setTimeout(function () {
         | 
| 126 | 
            -
               //TODO: Change to ES6/7 fetch() feature 
         | 
| 127 | 
            -
                $.ajax({
         | 
| 128 | 
            -
                  url: '/devise/automatic_logout/status',
         | 
| 129 | 
            -
                  success: function(data) {
         | 
| 130 | 
            -
                    if (data.seconds !== "null" && data.live === true){
         | 
| 131 | 
            -
                      
         | 
| 132 | 
            -
                      var data_message = data.message, data_seconds = data.seconds;
         | 
| 133 | 
            -
             | 
| 134 | 
            -
                      if (data_seconds != 0 && data_seconds != ''){
         | 
| 135 | 
            -
                        var timerDecrement = setInterval(function(){    
         | 
| 136 | 
            -
                          if (data_seconds == 0) { 
         | 
| 137 | 
            -
                            clearInterval(timerDecrement); 
         | 
| 138 | 
            -
                            // limpa a sessão após o ok do alertify
         | 
| 139 | 
            -
                            if (confirm(data_message)) {
         | 
| 140 | 
            -
                              AutomaticLogout.destroySession();
         | 
| 141 | 
            -
                            }
         | 
| 142 | 
            -
                          }
         | 
| 143 | 
            -
                          
         | 
| 144 | 
            -
                          data_seconds -= 1;
         | 
| 145 | 
            -
                        }, 1000)
         | 
| 146 | 
            -
                      }
         | 
| 147 | 
            -
                    }
         | 
| 148 | 
            -
                  }
         | 
| 149 | 
            -
                });
         | 
| 150 | 
            -
              }, 1000); //1s
         | 
| 151 | 
            -
            };
         | 
| 145 | 
            +
                seconds: seconds,
         | 
| 146 | 
            +
              };
         | 
| 147 | 
            +
            };
         | 
| @@ -1,35 +1,31 @@ | |
| 1 1 | 
             
            module Devise
         | 
| 2 | 
            -
              module  | 
| 2 | 
            +
              module Automaticlogout
         | 
| 3 3 | 
             
                module Controllers
         | 
| 4 4 | 
             
                  extend ActiveSupport::Concern
         | 
| 5 5 |  | 
| 6 | 
            -
                   | 
| 7 | 
            -
                    ::ApplicationController.before_action do |c|
         | 
| 8 | 
            -
                      if current_user.present?
         | 
| 9 | 
            -
                        key_classify = Devise.mappings.keys.first
         | 
| 10 | 
            -
                        resource_name = Devise.mappings[key_classify].class_name.to_s
         | 
| 11 | 
            -
                        # get instance for class using devise
         | 
| 12 | 
            -
                        c.session[:seconds] = resource_name.classify.constantize.timeout_in.seconds.to_i
         | 
| 13 | 
            -
                        # I18n.t devise.automaticlogout.message
         | 
| 14 | 
            -
                        c.session[:message] = I18n.t 'devise.automaticlogout.message' || 'Session expired!'
         | 
| 15 | 
            -
                      end
         | 
| 16 | 
            -
                    end
         | 
| 6 | 
            +
                  DEFAULT_MESSAGE = 'Session expired! You will be redirect.'.freeze
         | 
| 17 7 |  | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
                       | 
| 21 | 
            -
                         | 
| 22 | 
            -
                        message | 
| 23 | 
            -
                         | 
| 24 | 
            -
                      }, status: :ok
         | 
| 25 | 
            -
                    end
         | 
| 8 | 
            +
                  module ClassMethods
         | 
| 9 | 
            +
                    def devise_automatic_logout(options = {})
         | 
| 10 | 
            +
                      prepend_before_action do |c|
         | 
| 11 | 
            +
                        time = options.fetch(:time, nil)
         | 
| 12 | 
            +
                        message = options.fetch(:message, DEFAULT_MESSAGE)
         | 
| 13 | 
            +
                        scope = options.fetch(:scope, 'user')
         | 
| 26 14 |  | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 15 | 
            +
                        seconds = if time&.positive?
         | 
| 16 | 
            +
                                    time
         | 
| 17 | 
            +
                                  else
         | 
| 18 | 
            +
                                    mapping = Devise.mappings[scope.to_sym]
         | 
| 19 | 
            +
                                    return unless mapping
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                                    mapping.to.timeout_in.seconds.to_i
         | 
| 22 | 
            +
                                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                        if seconds
         | 
| 25 | 
            +
                          c.session[:devise_autl_message] = message
         | 
| 26 | 
            +
                          c.session[:devise_autl_seconds] = seconds
         | 
| 27 | 
            +
                        end
         | 
| 28 | 
            +
                      end
         | 
| 33 29 | 
             
                    end
         | 
| 34 30 | 
             
                  end
         | 
| 35 31 | 
             
                end
         | 
| @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            module Devise
         | 
| 2 | 
            -
              module  | 
| 2 | 
            +
              module Automaticlogout
         | 
| 3 3 | 
             
                class Engine < ::Rails::Engine
         | 
| 4 | 
            -
                   | 
| 4 | 
            +
                  engine_name 'devise_automaticlogout'
         | 
| 5 5 |  | 
| 6 6 | 
             
                  ActiveSupport.on_load :action_controller do
         | 
| 7 | 
            -
                    include Devise:: | 
| 7 | 
            +
                    include Devise::Automaticlogout::Controllers
         | 
| 8 8 | 
             
                  end
         | 
| 9 9 |  | 
| 10 10 | 
             
                  ActiveSupport.on_load :action_view do
         | 
| 11 | 
            -
                    include Devise:: | 
| 11 | 
            +
                    include Devise::Automaticlogout::Helpers
         | 
| 12 12 | 
             
                  end
         | 
| 13 13 | 
             
                end
         | 
| 14 14 | 
             
              end
         | 
| @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            module Devise
         | 
| 2 | 
            -
              module  | 
| 2 | 
            +
              module Automaticlogout
         | 
| 3 3 | 
             
                module Helpers
         | 
| 4 | 
            -
                  def regressive_timer
         | 
| 5 | 
            -
                    render 'automatic_logout/timer'
         | 
| 4 | 
            +
                  def regressive_timer(visible: false, alert: false)
         | 
| 5 | 
            +
                    render 'automatic_logout/timer', visible: visible, alert: alert
         | 
| 6 6 | 
             
                  end
         | 
| 7 7 | 
             
                end
         | 
| 8 8 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,83 +1,69 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: devise-automaticlogout
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 1.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Thadeu Esteves Jr
         | 
| 8 | 
            -
            autorequire: | 
| 8 | 
            +
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2020-10-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - " | 
| 17 | 
            +
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: ' | 
| 19 | 
            +
                    version: '5'
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - " | 
| 24 | 
            +
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: ' | 
| 26 | 
            +
                    version: '5'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: devise
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - - " | 
| 31 | 
            +
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: ' | 
| 34 | 
            -
              type: :runtime
         | 
| 35 | 
            -
              prerelease: false
         | 
| 36 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            -
                requirements:
         | 
| 38 | 
            -
                - - ">="
         | 
| 39 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: '0'
         | 
| 41 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            -
              name: jquery-rails
         | 
| 43 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            -
                requirements:
         | 
| 45 | 
            -
                - - ">="
         | 
| 46 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: '0'
         | 
| 33 | 
            +
                    version: '4'
         | 
| 48 34 | 
             
              type: :runtime
         | 
| 49 35 | 
             
              prerelease: false
         | 
| 50 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 37 | 
             
                requirements:
         | 
| 52 | 
            -
                - - " | 
| 38 | 
            +
                - - "~>"
         | 
| 53 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: ' | 
| 40 | 
            +
                    version: '4'
         | 
| 55 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 42 | 
             
              name: rubocop
         | 
| 57 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 44 | 
             
                requirements:
         | 
| 59 | 
            -
                - - " | 
| 45 | 
            +
                - - "~>"
         | 
| 60 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 47 | 
             
                    version: '0'
         | 
| 62 48 | 
             
              type: :development
         | 
| 63 49 | 
             
              prerelease: false
         | 
| 64 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 51 | 
             
                requirements:
         | 
| 66 | 
            -
                - - " | 
| 52 | 
            +
                - - "~>"
         | 
| 67 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 54 | 
             
                    version: '0'
         | 
| 69 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 56 | 
             
              name: sqlite3
         | 
| 71 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 58 | 
             
                requirements:
         | 
| 73 | 
            -
                - - " | 
| 59 | 
            +
                - - "~>"
         | 
| 74 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 61 | 
             
                    version: '0'
         | 
| 76 62 | 
             
              type: :development
         | 
| 77 63 | 
             
              prerelease: false
         | 
| 78 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 65 | 
             
                requirements:
         | 
| 80 | 
            -
                - - " | 
| 66 | 
            +
                - - "~>"
         | 
| 81 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 68 | 
             
                    version: '0'
         | 
| 83 69 | 
             
            description: Provides automatic session timeout in a Rails Devise application.
         | 
| @@ -90,19 +76,24 @@ files: | |
| 90 76 | 
             
            - MIT-LICENSE
         | 
| 91 77 | 
             
            - README.md
         | 
| 92 78 | 
             
            - Rakefile
         | 
| 79 | 
            +
            - app/controllers/automaticlogout_controller.rb
         | 
| 93 80 | 
             
            - app/views/automatic_logout/_timer.html.erb
         | 
| 94 81 | 
             
            - config/routes.rb
         | 
| 95 82 | 
             
            - lib/assets/javascripts/automatic_logout.js
         | 
| 83 | 
            +
            - lib/assets/javascripts/automatic_logout/classic.js
         | 
| 84 | 
            +
            - lib/assets/javascripts/automatic_logout/jquery.js
         | 
| 85 | 
            +
            - lib/assets/javascripts/automatic_logout/turbolinks-classic.js
         | 
| 86 | 
            +
            - lib/assets/javascripts/automatic_logout/turbolinks.js
         | 
| 96 87 | 
             
            - lib/devise/automaticlogout.rb
         | 
| 97 88 | 
             
            - lib/devise/automaticlogout/controllers.rb
         | 
| 98 89 | 
             
            - lib/devise/automaticlogout/engine.rb
         | 
| 99 90 | 
             
            - lib/devise/automaticlogout/helpers.rb
         | 
| 100 91 | 
             
            - lib/devise/automaticlogout/version.rb
         | 
| 101 | 
            -
            homepage: https://github.com/ | 
| 92 | 
            +
            homepage: https://github.com/thadeu/devise-automaticlogout
         | 
| 102 93 | 
             
            licenses:
         | 
| 103 94 | 
             
            - MIT
         | 
| 104 95 | 
             
            metadata: {}
         | 
| 105 | 
            -
            post_install_message: | 
| 96 | 
            +
            post_install_message:
         | 
| 106 97 | 
             
            rdoc_options: []
         | 
| 107 98 | 
             
            require_paths:
         | 
| 108 99 | 
             
            - lib
         | 
| @@ -117,9 +108,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 117 108 | 
             
                - !ruby/object:Gem::Version
         | 
| 118 109 | 
             
                  version: '0'
         | 
| 119 110 | 
             
            requirements: []
         | 
| 120 | 
            -
            rubyforge_project: | 
| 121 | 
            -
            rubygems_version: 2. | 
| 122 | 
            -
            signing_key: | 
| 111 | 
            +
            rubyforge_project:
         | 
| 112 | 
            +
            rubygems_version: 2.7.6
         | 
| 113 | 
            +
            signing_key:
         | 
| 123 114 | 
             
            specification_version: 4
         | 
| 124 115 | 
             
            summary: Provides automatic session timeout in a Rails Devise application.
         | 
| 125 116 | 
             
            test_files: []
         |