4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/median/aleph/authentication.rb', line 4
def authenticate(username, password)
return false if username.blank? or password.blank?
username.gsub!(/\s/, '')
username.upcase!
auth_info = post_url(Median.config.aleph_x_service_base_url,
op: 'bor-auth',
bor_id: username,
verification: password,
library: Median.config.aleph_user_library
)
puts auth_info
user_info = get_url(
Median.config.aleph_x_service_base_url,
op: 'bor-info',
bor_id: username,
verification: password,
loans: 'N',
cash: 'B',
hold: 'N',
library: Median.config.aleph_user_library
)
unless auth_info.at_xpath('/bor-auth/error') or user_info.at_xpath('/bor-info/error')
options = {}
options[:ilsid] = auth_info.at_xpath('//z303-id').try(:content)
name = auth_info.at_xpath('//z303-name').try(:content)
options[:lastname], options[:firstname] = name.split(',').map(&:strip) if name.present?
options[:email] = auth_info.at_xpath('//z304-email-address').try(:content)
options[:role] = 'g' status = auth_info.at_xpath('//z305-bor-status').try(:content)
case status
when /PS/ then options[:role] = 's'
when /PA/ then options[:role] = 'a'
when /PE/ then options[:role] = 'e'
when /PZ/ then options[:role] = 'z'
end
expiry_date = auth_info.at_xpath('//z305-expiry-date').try(:content)
options[:expiry_date] = Date.strptime(expiry_date, '%d/%m/%Y') if expiry_date.present?
balance = user_info.at_xpath('//balance').try(:content).to_f
balance = balance * -1 if balance != 0 and user_info.at_xpath('//sign').try(:content).try(:strip).try(:downcase) == 'd'
options[:cash_balance] = balance
return options
end
false
end
|