morpho 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0338ac8728b7b68d4573d522582176ef24120d8ee32b166a4b47a4cc2c31a80
4
- data.tar.gz: f1b00da0632ea3ec3f63c60cbdb01b378b404fdbb6c24696c10cfea8291a29d4
3
+ metadata.gz: a5e58a85aef299825d478036742e688fc13a9ddc8233387bd5e708fdf8fc3c59
4
+ data.tar.gz: 899df45d8f131d02d9899a9624abd22ff3eb4138a971954cca56d63f0ea919c4
5
5
  SHA512:
6
- metadata.gz: 11778c465a75f168c1a1a8db55ca70d3b9d70b8f61d0dd69743fcfccfc3e7c3951d9d29c287587ad7ee2e1cadb1d3059f990a0dd51f709e63c060feb9813abd4
7
- data.tar.gz: 1674597483b4ea9c1098dd92936796a394c790a2403e9702ae3225949862109cf8d54411540411fb3a0753940ace36a724dd1ce30a02080506f3a797705661ce
6
+ metadata.gz: ffc548ba4bf67699b99e377e6590dec5afc2e234f7c6bd20ea27d721cc08e489b5482eedc4b74c1404c9f5dcc79319c644cf9396f71e2069d213621116abba09
7
+ data.tar.gz: 99d6701412b6ccda6cae2c34812d0c67a739b7f70f113163380f2af766f57f1861dfa6facf6776107d010f0f303ffa016dddc2c2673689c4a4c5a9184c45ccef
@@ -6,31 +6,39 @@ module Morpho
6
6
  protected
7
7
 
8
8
  def render_bad_request
9
- error!({ message: I18n.t('morpho.api.messages.bad_request') }, 400)
9
+ error!({ message: I18n.t('morpho.api.messages.bad_request'), with: Morpho::Entities::Error }, 400)
10
10
  end
11
11
 
12
12
  def render_unauthorized
13
- error!({ message: I18n.t('morpho.api.messages.unauthorized') }, 401)
13
+ error!({ message: I18n.t('morpho.api.messages.unauthorized'), with: Morpho::Entities::Error }, 401)
14
+ end
15
+
16
+ def render_unauthorized_detailed(errors)
17
+ error!({ message: I18n.t('morpho.api.messages.unauthorized'), errors: errors, with: Morpho::Entities::Error }, 401)
14
18
  end
15
19
 
16
20
  def render_payment_required
17
- error!({ message: I18n.t('morpho.api.messages.payment_required') }, 402)
21
+ error!({ message: I18n.t('morpho.api.messages.payment_required'), with: Morpho::Entities::Error }, 402)
18
22
  end
19
23
 
20
24
  def render_forbidden
21
- error!({ message: I18n.t('morpho.api.messages.forbidden') }, 403)
25
+ error!({ message: I18n.t('morpho.api.messages.forbidden'), with: Morpho::Entities::Error }, 403)
22
26
  end
23
27
 
24
28
  def render_not_found
25
- error!({ message: I18n.t('morpho.api.messages.not_found') }, 404)
29
+ error!({ message: I18n.t('morpho.api.messages.not_found'), with: Morpho::Entities::Error }, 404)
26
30
  end
27
31
 
28
32
  def render_method_not_allowed
29
- error!({ message: I18n.t('morpho.api.messages.method_not_allowed') }, 405)
33
+ error!({ message: I18n.t('morpho.api.messages.method_not_allowed'), with: Morpho::Entities::Error }, 405)
34
+ end
35
+
36
+ def render_unprocessable_entity
37
+ error!({ message: I18n.t('morpho.api.messages.unprocessable_entity'), with: Morpho::Entities::Error }, 422)
30
38
  end
31
39
 
32
- def render_unprocessable_entity(errors)
33
- error!({ message: I18n.t('morpho.api.messages.unprocessable_entity'), errors: errors }, 422)
40
+ def render_unprocessable_entity_detailed(errors)
41
+ error!({ message: I18n.t('morpho.api.messages.unprocessable_entity'), errors: errors, with: Morpho::Entities::Error }, 422)
34
42
  end
35
43
 
36
44
  def render_no_content
@@ -22,19 +22,19 @@ module Morpho
22
22
  if user.valid_password?(user_params[:password])
23
23
  token = user_payload(user)
24
24
 
25
- present token, with: Morpho::Entities::AuthenticationToken
25
+ present token, with: Morpho::Entities::SignIn::AuthenticationToken
26
26
  else
27
27
  user.register_failed_login!
28
- render_unauthorized
28
+ render_unauthorized_detailed([I18n.t('morpho.api.messages.unauthorized_detailed.bad_credentials')])
29
29
  end
30
30
  else
31
- render_unauthorized
31
+ render_unauthorized_detailed([I18n.t('morpho.api.messages.unauthorized_detailed.locked')])
32
32
  end
33
33
  else
34
- render_unauthorized
34
+ render_unauthorized_detailed([I18n.t('morpho.api.messages.unauthorized_detailed.unconfirmed')])
35
35
  end
36
36
  else
37
- render_unauthorized
37
+ render_unauthorized_detailed([I18n.t('morpho.api.messages.unauthorized_detailed.unexistent')])
38
38
  end
39
39
  end
40
40
 
@@ -11,7 +11,7 @@ module Morpho
11
11
  if user.save
12
12
  present user, with: Morpho::Entities::User
13
13
  else
14
- render_unprocessable_entity(user.errors)
14
+ render_unprocessable_entity_detailed(user.errors)
15
15
  end
16
16
  end
17
17
  end
@@ -0,0 +1,10 @@
1
+ module Morpho
2
+ module Entities
3
+ module SignIn
4
+ class AuthenticationToken < ::Morpho::Entities::Base
5
+ expose :token, documentation: { type: 'string', desc: 'User authentication token', required: true }
6
+ expose :expires_at, documentation: { type: 'string', desc: 'Authentication token expiration date in millis', required: true }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Morpho
2
+ module Entities
3
+ module SignIn
4
+ class Success < ::Morpho::Entities::Base
5
+ expose :data, using: ::Morpho::Entities::SignIn::AuthenticationToken
6
+ end
7
+ end
8
+ end
9
+ end
@@ -5,13 +5,16 @@ module Morpho
5
5
 
6
6
  namespace :tokens do
7
7
  desc 'Request user authentication token' do
8
- success Morpho::Entities::AuthenticationToken
8
+ success Morpho::Entities::SignIn::Success
9
+ failure [
10
+ [ 401, I18n.t('morpho.api.messages.unauthorized'), Morpho::Entities::Error ]
11
+ ]
9
12
  end
10
13
  params do
11
- requires :user, type: Morpho::Entities::UserSignIn
14
+ requires :data, type: Morpho::Entities::UserSignIn
12
15
  end
13
16
  post do
14
- login(params[:user])
17
+ login(params[:data])
15
18
  end
16
19
  end
17
20
  end
@@ -137,6 +137,11 @@ en:
137
137
  not_found: 'Not found'
138
138
  method_not_allowed: 'Method not allowed'
139
139
  unprocessable_entity: 'Unprocessable entity'
140
+ unauthorized_detailed:
141
+ unexistent: 'Email address does not belongs to a registered account'
142
+ bad_credentials: 'User email and/or password is incorrect'
143
+ unconfirmed: 'User account has not been confirmed'
144
+ locked: 'User account has been locked'
140
145
  simple_form:
141
146
  'yes': 'Yes'
142
147
  'no': 'No'
@@ -137,6 +137,11 @@ es:
137
137
  not_found: 'No encontrado'
138
138
  method_not_allowed: 'Método no permitido'
139
139
  unprocessable_entity: 'Entidad no procesable'
140
+ unauthorized_detailed:
141
+ unexistent: 'Correo electrónico no pertenece a un usuario registrado'
142
+ bad_credentials: 'Correo electrónico y/o contraseña es incorrecto(a)'
143
+ unconfirmed: 'Cuenta de usuario no ha sido confirmada'
144
+ locked: 'Cuenta de usuario ha sido bloqueada'
140
145
  simple_form:
141
146
  'yes': 'Si'
142
147
  'no': 'No'
@@ -150,4 +155,4 @@ es:
150
155
  email: 'Correo electrónico'
151
156
  password: 'Contraseña'
152
157
  password_confirmation: 'Confirmar la contraseña'
153
- remember_me: 'Recuérdame'
158
+ remember_me: 'Recuérdame'
@@ -1,3 +1,3 @@
1
1
  module Morpho
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morpho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hugo Gilmar Erazo
@@ -250,9 +250,10 @@ files:
250
250
  - app/api/concerns/morpho/grape/user_password_reset.rb
251
251
  - app/api/concerns/morpho/grape/user_registration.rb
252
252
  - app/api/concerns/morpho/grape/user_unlock.rb
253
- - app/api/morpho/entities/authentication_token.rb
254
253
  - app/api/morpho/entities/base.rb
255
254
  - app/api/morpho/entities/error.rb
255
+ - app/api/morpho/entities/sign_in/authentication_token.rb
256
+ - app/api/morpho/entities/sign_in/success.rb
256
257
  - app/api/morpho/entities/user.rb
257
258
  - app/api/morpho/entities/user_sign_in.rb
258
259
  - app/api/morpho/entities/user_sign_up.rb
@@ -1,8 +0,0 @@
1
- module Morpho
2
- module Entities
3
- class AuthenticationToken < ::Morpho::Entities::Base
4
- expose :token, documentation: { type: 'string', desc: 'User authentication token', required: true }
5
- expose :expires_at, documentation: { type: 'string', desc: 'Authentication token expiration date in millis', required: true }
6
- end
7
- end
8
- end