ende 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c55828e653402799f49ba9f2a6871858db65cac
4
- data.tar.gz: 95e66a157139ba4b826546a436e36b1d53061ed0
3
+ metadata.gz: 4c265e340f519fb57b7a5884fe4a8f0b27f2ea45
4
+ data.tar.gz: 1893946a96f8999fe5447620ab9834145542992f
5
5
  SHA512:
6
- metadata.gz: e1634ba748d012ec0ab7fa30d28049e42b34d7ece94dada646c72ce8c0239c97db5934f63aeff155d177a931deba14b047860a9bd5a8a5a47a6e4d31e1b329e4
7
- data.tar.gz: 0fce80e25a4365288c5f7721187f116c34fb3ef12b3616d66f7f6c64ca70c3ad14c214ca533e35f01ea94f2cabaff6dd231a81a3f46032845bb7c16559b9c00c
6
+ metadata.gz: 3b3f2b584afc45b31c50cc771cfdcb5b7bd2381ddc3c7038fe8e9fd20522a71fda0607f8b7cd8b82122049d60c93ae48893c743fbd44c0960871d46dcc928de7
7
+ data.tar.gz: 58074b994df5664e0c19939a1166eb35fcc36682e8031d187c5b8375642c3168c3240af17256f1c45b12443b6a569839c46fca4ce18e431ae0ac146540909a54
@@ -12,6 +12,7 @@ define 'aura/extensions/devise', () ->
12
12
  # model, or the configured one
13
13
  session =
14
14
  build: (user = {}) ->
15
+
15
16
  if core.models.user
16
17
 
17
18
  user_session = core.models.user
@@ -29,7 +30,7 @@ define 'aura/extensions/devise', () ->
29
30
  email : user.email
30
31
  password: user.password
31
32
 
32
- user_session.route = '/users/sessions'
33
+ user_session.route = "/#{user_session.resource}s/sessions"
33
34
 
34
35
  user_session
35
36
 
@@ -101,6 +102,9 @@ define 'aura/extensions/devise', () ->
101
102
 
102
103
  destroy: ->
103
104
  # TODO update the csrf token with the new one!
105
+ # TODO better resource deletion control, create interface to
106
+ # make delete requests
107
+ session.instance.id = 0
104
108
  session.instance.destroy()
105
109
  .done ->
106
110
  sandbox.current_user = null
@@ -114,16 +118,22 @@ define 'aura/extensions/devise', () ->
114
118
  # new_user_password GET /users/password/new(.:format) devise/passwords#new
115
119
  # edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
116
120
  # PATCH /users/password(.:format) devise/passwords#update
117
- # PUT /users/password(.:format) devise/passwords#updaet
121
+ # PUT /users/password(.:format) devise/passwords#update
122
+ # Command handlers
118
123
  password =
124
+ model: null
119
125
  build: (user = {}) ->
120
126
 
121
- core.models.password
127
+ # TODO change to user model
128
+ password.model
122
129
  email: user.email
130
+
123
131
  password: user.password
132
+ password_confirmation: user.password_confirmation
133
+
134
+ reset_password_token: user.reset_password_token
124
135
 
125
136
  create: (user) ->
126
- event_name = @event
127
137
  user_password = password.build user
128
138
  password.instance = user_password
129
139
 
@@ -135,17 +145,61 @@ define 'aura/extensions/devise', () ->
135
145
  # TODO detect model event emission need based on
136
146
  # subscriptions to resource events
137
147
  mediator.emit 'password.created', @
148
+ mediator.emit 'user.password_created' , user
138
149
 
139
- switch(event_name)
140
- when 'user.create_password'
141
- mediator.emit 'user.password_created' , user
142
- when 'user.recover_password'
143
- mediator.emit 'user.password_recovered', user
144
- else
145
- console.warn "devise password created: no corresponding confirmation event found for #{event_name}"
146
150
  .fail ->
147
151
  # TODO improve event naming
148
- mediator.emit 'user.unauthorized', @
152
+ # TODO treat other failure cases
153
+ # TODO auto publish events
154
+ switch xhr.status
155
+ when 401
156
+ mediator.emit 'password.creation_unauthorized', @
157
+ when 422
158
+ mediator.emit 'password.creation_unprocessable', @
159
+ else
160
+ # TODO move session.restoring check outside this method
161
+ mediator.emit 'session.creation_failed', @
162
+
163
+
164
+ update: (user) ->
165
+ user_password = password.build(user)
166
+ update = {}
167
+ param = user_password.resource.param_name || user_password.resource.toString()
168
+ password.instance = user_password
169
+
170
+ update[param] = user_password.json()
171
+ update.reset_password_token = user.reset_password_token
172
+
173
+ password.model
174
+ .put.call(user_password)
175
+ .done ->
176
+ # TODO add models event emission to the models extension
177
+ # TODO detect model event emission need based on
178
+ # subscriptions to resource events
179
+ mediator.emit 'password.updated', @
180
+ mediator.emit 'user.password_updated', user
181
+
182
+ session.restore()
183
+
184
+ .fail (xhr) ->
185
+ # TODO actually implement automatic put restful support on indemma
186
+ # Calling manualy the put request, so forward the failure to
187
+ # the default handler
188
+ xhr.fail @failed
189
+
190
+ # TODO improve event naming
191
+ # TODO treat other failure cases
192
+ # TODO insert indemma hook for autopublishing this events
193
+ switch xhr.status
194
+ when 401
195
+ mediator.emit 'password.update_unauthorized' , @
196
+ when 422
197
+ mediator.emit 'password.update_unprocessable', @
198
+ else
199
+ # TODO move session.restoring check outside this method
200
+ mediator.emit 'password.update_failed' , @
201
+
202
+
149
203
 
150
204
  domain =
151
205
  action_unauthorized: ->
@@ -169,16 +223,13 @@ define 'aura/extensions/devise', () ->
169
223
 
170
224
 
171
225
 
172
-
173
-
174
226
  # Extension definition
175
227
  name: 'devise'
176
- version: '0.3.0'
228
+ version: '1.0.0'
177
229
  initialize: (application) ->
230
+ {core, sandbox} = application
231
+ {mediator} = core
178
232
 
179
- core = application.core
180
- sandbox = application.sandbox
181
- mediator = core.mediator
182
233
  # TODO add ajax control into an extension and stop using jquery directly
183
234
  jQuery(document).ajaxError (event, xhr) ->
184
235
  if xhr.status == 401
@@ -212,7 +263,7 @@ define 'aura/extensions/devise', () ->
212
263
  # email : user.email
213
264
  # password: user.password
214
265
 
215
- model.call
266
+ password.model = model.call
216
267
  resource:
217
268
  scope : 'users'
218
269
  name : 'password'
@@ -221,13 +272,18 @@ define 'aura/extensions/devise', () ->
221
272
 
222
273
  email: String
223
274
 
275
+ password: String
276
+ password_confirmation: String
277
+
224
278
  define_handlers: ->
225
279
  # TODO get json with features info from devise
226
280
  # gem and only use apropriated listeners
281
+ mediator.on 'user.restore_session' , session.restore
227
282
  mediator.on 'user.sign_in' , session.create
228
283
  mediator.on 'user.sign_out', session.destroy
229
- mediator.on 'user.create_password' , password.create
230
- mediator.on 'user.recover_password', password.create
284
+
285
+ mediator.on 'user.create_password', password.create
286
+ mediator.on 'user.update_password', password.update
231
287
 
232
288
  mediator.on 'action.unauthorized', domain.action_unauthorized
233
289
 
data/lib/ende/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ende
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ende
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heitor Salazar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-31 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler