Sha256: 8296f8ef2b0af3ce974210bedd2203abfbe5fc776df0251a41751e3052c976a2

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

# = AutoLogin filter
#
# code:: gmosx
#
# (c) 2004 Navel, all rights reserved.
# $Id: autologin.rb 79 2004-10-18 16:38:19Z gmosx $

require "n/utils/string"
require "n/server/filter"

require_part "users"

module N; module App

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

	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 = $db.get_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; end # module

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.1.2 lib/n/app/filters/autologin.rb