ixtlan 0.4.0.pre2 → 0.4.0.pre3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/gwt_ixtlan_datamapper_rspec_scaffold_generator.rb +1 -1
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Fields.java +13 -0
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Model.java +11 -14
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/ModelFactory.java +2 -7
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Screen.java +14 -7
- data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/TestGwt.java +12 -10
- data/generators/ixtlan_datamapper_model/templates/migration.rb +22 -0
- data/generators/ixtlan_datamapper_model/templates/model.rb +2 -2
- data/generators/ixtlan_datamapper_rspec_model/ixtlan_datamapper_rspec_model_generator.rb +2 -0
- data/generators/ixtlan_datamapper_rspec_model/templates/model_spec.rb +8 -5
- data/generators/ixtlan_datamapper_rspec_scaffold/ixtlan_datamapper_rspec_scaffold_generator.rb +2 -0
- data/generators/ixtlan_datamapper_rspec_scaffold/templates/controller_spec.rb +13 -7
- data/lib/dm-serializer/to_xml.rb +2 -2
- data/lib/ixtlan/controllers/authentications_controller.rb +1 -1
- data/lib/ixtlan/controllers/locales_controller.rb +1 -0
- data/lib/ixtlan/controllers/users_controller.rb +5 -3
- data/lib/ixtlan/models/authentication.rb +1 -3
- data/lib/ixtlan/models/i18n_text.rb +4 -4
- data/lib/ixtlan/models/user.rb +2 -0
- data/lib/ixtlan/models/word.rb +3 -1
- data/lib/ixtlan/modified_by.rb +1 -1
- data/lib/ixtlan/optimistic_persistence.rb +2 -5
- data/lib/ixtlan/rails/migrations.rb +30 -25
- data/lib/ixtlan/rails/unrestful_authentication.rb +1 -1
- data/lib/ixtlan/session.rb +2 -2
- data/lib/ixtlan/simple_client.rb +126 -0
- data/lib/ixtlan/user_logger.rb +0 -1
- data/lib/ixtlan/version.rb +1 -1
- data/lib/models.rb +1 -0
- metadata +267 -219
- data/History.txt +0 -49
- data/MIT-LICENSE +0 -20
- data/Manifest.txt +0 -103
- data/README.txt +0 -86
- data/Rakefile +0 -55
- data/ixtlan_rails_templates.rb +0 -537
- data/whitespace.rb +0 -31
data/lib/ixtlan/session.rb
CHANGED
@@ -8,12 +8,12 @@ module Ixtlan
|
|
8
8
|
@user = d.delete(:user)
|
9
9
|
@flash = d.delete(:flash)
|
10
10
|
@expires_at = d.delete(:expires_at)
|
11
|
-
attribute_set(:
|
11
|
+
attribute_set(:raw_data, ::Base64.encode64(Marshal.dump(d)))
|
12
12
|
end
|
13
13
|
|
14
14
|
def data
|
15
15
|
# user string for flash entry to allow the rails falsh to work properly !
|
16
|
-
Marshal.load(::Base64.decode64(attribute_get(:
|
16
|
+
Marshal.load(::Base64.decode64(attribute_get(:raw_data))).merge({:user => @user, "flash" => @flash, :expires_at => @expires_at})
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
module Ixtlan
|
3
|
+
class NoAuthenticationError < StandardError; end
|
4
|
+
|
5
|
+
# restful XML client using HTTP (no HTTPS support !!)
|
6
|
+
class SimpleClient
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@host = options[:host]
|
10
|
+
@port = (options[:port] || 80).to_i # defaults to 80
|
11
|
+
@username = options[:username]
|
12
|
+
@password = options[:password]
|
13
|
+
end
|
14
|
+
|
15
|
+
# restful get for the given path (like '/users.xml' or '/users/1.xml').
|
16
|
+
# which retrieves the data
|
17
|
+
# usually there is no payload - maybe a query if the service accepts it
|
18
|
+
def get(path, payload = nil)
|
19
|
+
req = Net::HTTP::Get.new(path)
|
20
|
+
action(req, payload)
|
21
|
+
end
|
22
|
+
|
23
|
+
# restful post for the given path (like '/users.xml').
|
24
|
+
# which creates a new resource or new resources (if the underlying
|
25
|
+
# service provides bulk creation)
|
26
|
+
def post(path, payload)
|
27
|
+
req = Net::HTTP::Post.new(path)
|
28
|
+
action(req, payload)
|
29
|
+
end
|
30
|
+
|
31
|
+
# restful put for the given path (like '/users/1.xml').
|
32
|
+
# which updates a given resource or many resources (if the underlying
|
33
|
+
# service provides bulk updates - path like '/users.xml')
|
34
|
+
def put(path, payload)
|
35
|
+
req = Net::HTTP::Put.new(path)
|
36
|
+
action(req, payload)
|
37
|
+
end
|
38
|
+
|
39
|
+
# restful delete for the given path (like '/users/1.xml').
|
40
|
+
# delete a single resource (with no payload) or many resources
|
41
|
+
# (if the underlying service provides bulk updates - path like '/users.xml')
|
42
|
+
def delete(path, payload = nil)
|
43
|
+
req = Net::HTTP::Delete.new(path)
|
44
|
+
action(req, payload)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def action(req, payload)
|
50
|
+
_action(req, payload)
|
51
|
+
rescue NoAuthentiacionError
|
52
|
+
# can happen after the session got an idle timeout
|
53
|
+
# give it one other trial
|
54
|
+
_action(req, payload)
|
55
|
+
end
|
56
|
+
|
57
|
+
def _action(req, payload)
|
58
|
+
# authenticate if needed
|
59
|
+
unless(@cookie && @token)
|
60
|
+
authenticate
|
61
|
+
end
|
62
|
+
|
63
|
+
# setup request with session tracking
|
64
|
+
req.content_length = payload.to_s.size
|
65
|
+
req.body = payload.to_s
|
66
|
+
req['Content-Type'] = 'application/xml'
|
67
|
+
req['Authentication-Token'] = @token
|
68
|
+
req['Cookie'] = @cookie
|
69
|
+
|
70
|
+
http = Net::HTTP.new(@host, @port)
|
71
|
+
http.read_timeout = 999
|
72
|
+
|
73
|
+
result = nil
|
74
|
+
response = http.start do |h|
|
75
|
+
h.request(req) do |response|
|
76
|
+
if response.kind_of?(Net::HTTPSuccess)
|
77
|
+
# in case there is a new token keep it for the next request
|
78
|
+
@token = response['Authentication-Token'] || @token
|
79
|
+
# read result
|
80
|
+
result = response.read_body
|
81
|
+
elsif response.kind_of?(Net::HTTPUnauthorized)
|
82
|
+
# clear session tracking data
|
83
|
+
@token = nil
|
84
|
+
@cookie = nil
|
85
|
+
# this exception indicates authentication problem and
|
86
|
+
# can trigger retry
|
87
|
+
raise NoAuthenticationError.new
|
88
|
+
else
|
89
|
+
# TODO maybe better error handling
|
90
|
+
raise "http error: #{response.inspect}\n\t#{response.body}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
result
|
95
|
+
end
|
96
|
+
|
97
|
+
def authenticate
|
98
|
+
# setup request with authencitation.xml
|
99
|
+
req = Net::HTTP::Post.new("/authentication.xml")
|
100
|
+
req['Content-Type'] = 'application/xml'
|
101
|
+
|
102
|
+
# the login payload
|
103
|
+
req.body = "<authentication><login>#{@username}</login><password>#{@password}</password></authentication>"
|
104
|
+
req.content_length = req.body.size
|
105
|
+
|
106
|
+
http = Net::HTTP.new(@host, @port)
|
107
|
+
http.read_timeout = 999
|
108
|
+
|
109
|
+
response = http.start do |h|
|
110
|
+
h.request(req) do |response|
|
111
|
+
if response.kind_of?(Net::HTTPSuccess)
|
112
|
+
# read body to close connection - be nice client
|
113
|
+
response.read_body
|
114
|
+
# keep session tracking info for further request
|
115
|
+
@token = response['Authentication-Token']
|
116
|
+
# take only the session_id part of the cookie
|
117
|
+
@cookie = response['Set-Cookie'].sub(/;.*/, '')
|
118
|
+
else
|
119
|
+
# TODO maybe better error handling
|
120
|
+
raise "http error: #{response.inspect}\n\t#{response.body}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/lib/ixtlan/user_logger.rb
CHANGED
data/lib/ixtlan/version.rb
CHANGED
data/lib/models.rb
CHANGED
@@ -6,6 +6,7 @@ require 'ixtlan/models'
|
|
6
6
|
load 'ixtlan/models/authentication.rb'
|
7
7
|
load 'ixtlan/models/user.rb'
|
8
8
|
load 'ixtlan/models/group_locale_user.rb'
|
9
|
+
load 'ixtlan/models/domain_group_user.rb'
|
9
10
|
load 'ixtlan/models/group.rb'
|
10
11
|
load 'ixtlan/models/group_user.rb'
|
11
12
|
load 'ixtlan/models/locale.rb'
|