I'm trying to make a stripped-down user sessions system, and tried to model it to be similar to authlogic.
class UserSession
attr_accessor :username
def initialize(params={})
@username = params[:username]
end
def new_record?
true
end
def self.find
return nil if session[:username].nil?
UserSession.new session[:username]
end
def save
session[:username] = username
session[:username] == username
end
def user
User.find :first, :conditions => { :username => username }
end
def destroy
session[:username] = nil
end
end
I know there's no passwords or anything, but let's put that aside for the moment. My problem is that apparently it is not easy to and bad form to access the session from a model. Which leads me to wonder, how exactly am I supposed to abstract creating user sessions as a model, if I can't access the session?