Skip to content

Commit

Permalink
give users a serialized user settings
Browse files Browse the repository at this point in the history
actually make the last_seen_at get updated
log the current ip of each user
TODO: only update ip/last_seen_at minimally
  • Loading branch information
sudara committed Mar 17, 2008
1 parent ba24cff commit 13eb00a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
1 change: 0 additions & 1 deletion app/controllers/assets_controller.rb
Expand Up @@ -28,7 +28,6 @@ def index
# GET /assets/1.xml
def show
respond_to do |format|
format.rss
format.html do
@page_title = "#{@asset.title} by #{@user.name} on alonetone"
@assets = [@asset]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -18,7 +18,7 @@ def index
respond_to do |format|
format.html do
@user_count = User.count
@active = User.count(:all, :conditions => "assets_count > 0")
@active = User.count(:all, :conditions => "assets_count > 0", :include => :pic)
end
format.xml do
@users = User.search(params[:q], :limit => 25)
Expand Down
16 changes: 10 additions & 6 deletions app/models/user.rb
Expand Up @@ -26,6 +26,9 @@
require 'digest/sha1'
class User < ActiveRecord::Base

# has a bunch of prefs
serialize :settings

# Can create music
has_many :assets, :dependent => :destroy, :order => 'created_at DESC'
has_many :playlists, :dependent => :destroy, :order => 'playlists.created_at DESC'
Expand All @@ -47,8 +50,9 @@ class User < ActiveRecord::Base
# Virtual attribute for the unencrypted password
attr_accessor :password

# These attributes can be changed by a user
attr_accessible :login, :email, :password, :password_confirmation, :website, :bio, :display_name, :itunes
# These attributes can be changed via mass assignment
attr_accessible :login, :email, :password, :password_confirmation, :website, :myspace,
:bio, :display_name, :itunes, :settings, :city, :state

# Validations
validates_presence_of :email
Expand Down Expand Up @@ -140,11 +144,11 @@ def avatar(size = nil)

def self.paginate_by_params(params)
if params[:all]
self.paginate_all_by_activation_code(nil, :per_page => 24, :order => "created_at DESC", :page => params[:page])
self.paginate_all_by_activation_code(nil, :per_page => 24, :include => :pic, :order => "users.created_at DESC", :page => params[:page])
elsif params[:playlists]
self.paginate(:all, :conditions => 'users.playlists_count > 0', :per_page => 24, :order => "users.playlists_count DESC", :page => params[:page])
self.paginate(:all, :conditions => 'users.playlists_count > 0', :per_page => 24, :include => :pic, :order => "users.playlists_count DESC", :page => params[:page])
else
self.paginate(:all, :conditions => 'users.assets_count > 0', :per_page => 24, :order => "users.assets_count DESC", :page => params[:page])
self.paginate(:all, :conditions => 'users.assets_count > 0', :per_page => 24, :include => :pic, :order => "users.assets_count DESC", :page => params[:page])
end
end

Expand Down Expand Up @@ -189,7 +193,7 @@ def self.build_search_conditions(query)

def to_xml(options = {})
options[:except] ||= []
options[:except] << :email << :token << :token_expires_at << :crypted_password << :identity_url << :fb_user_id << :activation_code << :admin
options[:except] << :email << :token << :token_expires_at << :crypted_password << :identity_url << :fb_user_id << :activation_code << :admin << :salt
super
end

Expand Down
9 changes: 9 additions & 0 deletions db/migrate/044_change_settings_from_string_to_text.rb
@@ -0,0 +1,9 @@
class ChangeSettingsFromStringToText < ActiveRecord::Migration
def self.up
remove_column :users, :settings
add_column :users, :settings, :text
end

def self.down
end
end
6 changes: 3 additions & 3 deletions lib/authenticated_system.rb
Expand Up @@ -14,9 +14,9 @@ module AuthenticatedSystem
# This is now also used to show which users are online... not at accurate as the
# session based approach, but less code and less overhead.
def update_last_seen_at
return unless logged_in? || session[:sudo]
User.update_all ['last_seen_at = ? AND ip = ?', Time.now.utc, request.env['REMOTE_HOST']], ['id = ?', current_user.id]
current_user.last_seen_at = Time.now.utc
return unless logged_in?
current_user.update_attribute(:last_seen_at,Time.now.utc)
current_user.update_attribute(:ip, request.remote_ip)
end

def login_required
Expand Down

0 comments on commit 13eb00a

Please sign in to comment.