noosfero | 2 new commits pushed to repository

Bráulio Bhavamitra gitlab at gitlab.com
Sun Feb 22 20:08:55 BRT 2015


Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/becf0ab79eea67a227398ae1ef36f0680ad82d60">becf0ab7</a> by Braulio Bhavamitra
Register last login date

(ActionItem3139)

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/aca1246073ec1b1d5c1a2e13a1ae58b8c742d145">aca12460</a> by Bráulio Bhavamitra
Merge branch 'ai3139' into 'master'

Register last login date

See merge request !465

- - - - -


Changes:

=====================================
app/models/user.rb
=====================================
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -114,6 +114,10 @@ class User < ActiveRecord::Base
     u && u.authenticated?(password) ? u : nil
   end
 
+  def register_login
+    self.update_attribute :last_login_at, Time.now
+  end
+
   # Activates the user in the database.
   def activate
     return false unless self.person

=====================================
db/migrate/20140519113821_add_last_login_at_to_user.rb
=====================================
--- /dev/null
+++ b/db/migrate/20140519113821_add_last_login_at_to_user.rb
@@ -0,0 +1,9 @@
+class AddLastLoginAtToUser < ActiveRecord::Migration
+  def self.up
+    add_column :users, :last_login_at, :datetime
+  end
+
+  def self.down
+    remove_column :users, :last_login_at
+  end
+end

=====================================
lib/authenticated_system.rb
=====================================
--- a/lib/authenticated_system.rb
+++ b/lib/authenticated_system.rb
@@ -5,22 +5,23 @@ module AuthenticatedSystem
     def logged_in?
       current_user != nil
     end
-    
+
     # Accesses the current user from the session.
     def current_user
       @current_user ||= (session[:user] && User.find_by_id(session[:user])) || nil
     end
-    
+
     # Store the given user in the session.
     def current_user=(new_user)
       if new_user.nil?
         session.delete(:user)
       else
         session[:user] = new_user.id
+        new_user.register_login
       end
       @current_user = new_user
     end
-    
+
     # Check if the user is authorized.
     #
     # Override this method in your controllers if you want to restrict access
@@ -62,7 +63,7 @@ module AuthenticatedSystem
         access_denied
       end
     end
-    
+
     # Redirect as appropriate when an access request fails.
     #
     # The default action is to redirect to the login screen.
@@ -88,15 +89,15 @@ module AuthenticatedSystem
         end
       end
       false
-    end  
-    
+    end
+
     # Store the URI of the current request in the session.
     #
     # We can return to this location by calling #redirect_back_or_default.
     def store_location(location = request.url)
       session[:return_to] = location
     end
-    
+
     # Redirect to the URI stored by the most recent store_location call or
     # to the passed default.
     def redirect_back_or_default(default)
@@ -106,7 +107,7 @@ module AuthenticatedSystem
         redirect_to(default)
       end
     end
-    
+
     # Inclusion hook to make #current_user and #logged_in?
     # available as ActionView helper methods.
     def self.included(base)
@@ -132,6 +133,6 @@ module AuthenticatedSystem
     def get_auth_data
       auth_key  = @@http_auth_headers.detect { |h| request.env.has_key?(h) }
       auth_data = request.env[auth_key].to_s.split unless auth_key.blank?
-      return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil] 
+      return auth_data && auth_data[0] == 'Basic' ? Base64.decode64(auth_data[1]).split(':')[0..1] : [nil, nil]
     end
 end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150222/29490961/attachment.html>


More information about the Noosfero-dev mailing list