Sha256: 355e93b0b5a460ef8634573f9c459e8bbe241724bef22209eb75a011cb3bb496

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 167 2004-11-23 14:03:10Z gmosx $

require "glue/string"
require "nitro/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
					Logger.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.8.0 lib/nitro/server/filters/autologin.rb