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/moob/pec.rb', line 24
def authenticate
@session.handle_cookies nil
login = @session.get 'login.html'
raise ResponseError.new login unless login.status == 200
auth = @session.post 'data/login', "user=#{@username}&password=#{@password}"
raise ResponseError.new auth unless auth.status == 200
auth.body =~ /<authResult>([^<]+)<\/authResult>/
raise 'Cannot find auth result' unless $&
raise "Auth failed with: \"#{auth.body}\"" unless $1 == "0"
auth.body =~ /<forwardUrl>([^<]+)<\/forwardUrl>/
raise 'Cannot find the authenticated index url after auth' unless $&
@indexurl = $1
Moob.inform "Requesting indexurl of #{@indexurl}"
@authhash = @indexurl.split('?')[1]
@index = @session.get @indexurl
@index.body =~ /var CSRF_TOKEN_2_VALUE = "([0-9a-f]+)";/
raise ResponseError.new @index unless @index.status == 200
@st2 = $1
@session.['ST2'] = @st2
return self
end
|