Sha256: ae968fbe30d5f078293c4d456a4a34bb90937d80a87af97b8e2d050da0dbfbdc

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# code:
# * George Moschovitis
#
# (c) 2004 Navel, all rights reserved.
# $Id: autologin.rb 124 2004-11-01 12:34:17Z gmosx $

require "n/utils/string"
require "n/server/filters"

require_part "users"

module N

# = AutoLoginFilter
#
# Automatically login a user with valid authentication cookie.
# Uses some n1 code at the moment.
#
class AutoLoginFilter < N::ServerFilter

	# Perform the actual work of auto logging in the user
	#
	def process(request)
		if request.is_top?
			# only try to autologin for top level requests
			# there is NO need for the older SKIP_AUTOLOGIN session flag.
			if (request.session.user.anonymous?) and 
					cookie = request.get_cookie($users_auth_cookie)
					
				username, password_crypted = cookie.split(",")
				
				if user = $og.load_by_name(username, N::User) and 
						password_crypted == user.password
					if request.session.login(request, user)
						# user logged in
					else
						# stale cookie, remove it
						request.del_cookie($users_auth_cookie)
					end
				else
					$log.warn "Unknown user or wrong password in auth-cookie: #{cookie} from IP: #{request.remote_addr}"
				end
			end
		end
	
		return @next_filter.process(request) if @next_filter
	end

end

end # module

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.3.0 lib/n/server/filters/autologin.rb