Class: IpcAuthpipe::Handler::Pre

Inherits:
Base
  • Object
show all
Defined in:
lib/ipcauthpipe/handler/pre.rb

Overview

AUTH command handler performs actual authentication of user’s data. It gets authentication type and parameters from the input stream and responds with FAIL on failure or user data on success

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#process

Class Method Details

.process(request) ⇒ Object



8
9
10
11
12
# File 'lib/ipcauthpipe/handler/pre.rb', line 8

def self.process(request)
  Log.debug "Processing request [#{request}] in AUTH handler"
  handler = Pre.new
  handler.user_details handler.split_request(request)
end

Instance Method Details

#split_request(request) ⇒ Object

Splits request into service and username parts, raises ArgumentError if request string is invalid

Raises:

  • (ArgumentError)


16
17
18
19
# File 'lib/ipcauthpipe/handler/pre.rb', line 16

def split_request(request)
  raise ArgumentError, "Invalid PRE request #{request.inspect}" unless /^\. (\w+) (\w+)$/.match( request )
  { :service => $~[1], :username => $~[2] }
end

#user_details(request) ⇒ Object

Finds member by his username and dumps his details, returns FAIL if not member were found



22
23
24
25
26
27
# File 'lib/ipcauthpipe/handler/pre.rb', line 22

def user_details(request)
  member = Member.find_by_name(request[:username])
  member.create_homedir unless member.nil? # make sure the homedir exists

  member.nil? ? "FAIL\n" : member.to_authpipe
end