Added ApplicationController#get_ident
authorNguyễn Thái Ngọc Duy <[email protected]>
Thu, 24 Aug 2006 10:30:19 +0000 (24 17:30 +0700)
committerNguyễn Thái Ngọc Duy <[email protected]>
Thu, 24 Aug 2006 10:30:19 +0000 (24 17:30 +0700)
app/controllers/application.rb

index 7aef99d..6ae4e2f 100644 (file)
@@ -20,6 +20,16 @@ class ApplicationController < ActionController::Base
       raise PermissionException, 'Only moderators can access this area' unless current_user.is_a?(User) and current_user.can_moderate?
     end
 
+    def get_ident
+      if current_user.nil? or current_user.is_guest?
+        ident = request.env['REMOTE_ADDR']
+        ident = 'Unknown' if ident.nil?
+      else
+        ident = current_user.username
+      end
+      ident
+    end
+
   private
 
     def can_read_board?
@@ -34,8 +44,7 @@ class ApplicationController < ActionController::Base
 
     def online_check
       if current_user.is_guest?
-        ident = request.env['REMOTE_ADDR']
-        ident = 'Unknown' if ident.nil?
+        ident = get_ident
         ticket = Online.find :first, :conditions => ['ident = ?', ident]
         if ticket.nil?
           ticket = Online.new
@@ -45,7 +54,7 @@ class ApplicationController < ActionController::Base
         ticket = Online.find :first, :conditions => ['user_id = ?',current_user.id]
         if ticket.nil?
           ticket = Online.new
-          ticket.ident = current_user.username
+          ticket.ident = get_ident
           ticket.user = current_user
         end
         ticket.idle = false