Sha256: b47149afa87969fc40aa459868f31c1c61e722aee340fc0d83b908275036ba91

Contents?: true

Size: 483 Bytes

Versions: 1

Compression:

Stored size: 483 Bytes

Contents

module CurrentUser
	extend ActiveSupport::Concern

	included do
		helper_method :current_user
	end

	def set_current_user(user)
		session[:user_id] = user.id
		user.increment_login_stats!(request.remote_ip)
	end

	def current_user
		@current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
		@current_user
	end

	def require_user
		if !current_user
			redirect_to login_url
		end
	end
	
	def require_no_user
		if current_user
			redirect_to root_url
		end
	end	

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jt-rails-generator-user-1.0.6 lib/generators/jt/user/templates/controllers/concerns/current_user.rb