morpho 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/api/morpho/entities/user.rb +0 -1
- data/app/api/morpho/resources/activations.rb +9 -4
- data/app/api/morpho/resources/externals.rb +8 -2
- data/app/api/morpho/resources/passwords.rb +9 -4
- data/app/api/morpho/resources/tokens.rb +19 -5
- data/app/api/morpho/resources/unlocks.rb +10 -5
- data/app/api/morpho/resources/users.rb +8 -3
- data/app/concepts/morpho/contracts/user/deliver_email.rb +13 -0
- data/app/concepts/morpho/contracts/user/external_sign_in.rb +17 -0
- data/app/concepts/morpho/contracts/user/refresh_token.rb +13 -0
- data/app/concepts/morpho/contracts/user/resend_activation_email.rb +8 -0
- data/app/concepts/morpho/contracts/user/resend_unlock_email.rb +8 -0
- data/app/concepts/morpho/contracts/user/send_reset_password_email.rb +8 -0
- data/app/concepts/morpho/contracts/user/sign_in.rb +15 -0
- data/app/concepts/morpho/contracts/user/sign_up.rb +25 -0
- data/app/concepts/morpho/operations/base/create.rb +14 -0
- data/app/concepts/morpho/operations/base/delete.rb +16 -0
- data/app/concepts/morpho/operations/base/fetch.rb +106 -0
- data/app/concepts/morpho/operations/base/find.rb +55 -0
- data/app/concepts/morpho/operations/base/form.rb +84 -0
- data/app/concepts/morpho/operations/base/update.rb +19 -0
- data/app/concepts/morpho/operations/user/deliver_email.rb +38 -0
- data/app/concepts/morpho/operations/user/external_sign_in.rb +38 -0
- data/app/concepts/morpho/operations/user/generate_token.rb +33 -0
- data/app/concepts/morpho/operations/user/refresh_token.rb +41 -0
- data/app/concepts/morpho/operations/user/resend_activation_email.rb +31 -0
- data/app/concepts/morpho/operations/user/resend_unlock_email.rb +31 -0
- data/app/concepts/morpho/operations/user/send_reset_password_email.rb +30 -0
- data/app/concepts/morpho/operations/user/sign_in.rb +49 -0
- data/app/concepts/morpho/operations/user/sign_up.rb +8 -0
- data/app/models/morpho/user.rb +6 -2
- data/config/locales/morpho.en.yml +2 -0
- data/config/locales/morpho.es.yml +2 -0
- data/lib/generators/morpho/install/templates/app/api/morpho/api.rb +12 -2
- data/lib/generators/morpho/install/templates/config/initializers/morpho.rb +2 -1
- data/lib/morpho/configuration.rb +2 -0
- data/lib/morpho/engine.rb +1 -6
- data/lib/morpho/version.rb +1 -1
- metadata +26 -17
- data/app/concepts/morpho/user/contract/activate.rb +0 -8
- data/app/concepts/morpho/user/contract/external_sign_in.rb +0 -12
- data/app/concepts/morpho/user/contract/refresh_token.rb +0 -8
- data/app/concepts/morpho/user/contract/reset_password.rb +0 -8
- data/app/concepts/morpho/user/contract/sign_in.rb +0 -10
- data/app/concepts/morpho/user/contract/sign_up.rb +0 -22
- data/app/concepts/morpho/user/contract/unlock.rb +0 -8
- data/app/concepts/morpho/user/operation/activate.rb +0 -42
- data/app/concepts/morpho/user/operation/external_sign_in.rb +0 -70
- data/app/concepts/morpho/user/operation/refresh_token.rb +0 -37
- data/app/concepts/morpho/user/operation/reset_password.rb +0 -40
- data/app/concepts/morpho/user/operation/sign_in.rb +0 -73
- data/app/concepts/morpho/user/operation/sign_up.rb +0 -32
- data/app/concepts/morpho/user/operation/unlock.rb +0 -42
data/app/models/morpho/user.rb
CHANGED
@@ -18,6 +18,11 @@ module Morpho
|
|
18
18
|
!self.login_locked?
|
19
19
|
end
|
20
20
|
|
21
|
+
def setup_activation!
|
22
|
+
self.setup_activation
|
23
|
+
self.save
|
24
|
+
end
|
25
|
+
|
21
26
|
def register_last_login_activity!(ip_address)
|
22
27
|
self.set_last_login_at(Time.now)
|
23
28
|
self.set_last_ip_address(ip_address)
|
@@ -28,8 +33,7 @@ module Morpho
|
|
28
33
|
end
|
29
34
|
|
30
35
|
def resend_activation_needed_email!
|
31
|
-
self.setup_activation
|
32
|
-
self.reload
|
36
|
+
self.setup_activation!
|
33
37
|
self.send_activation_needed_email!
|
34
38
|
end
|
35
39
|
|
@@ -149,6 +149,8 @@ en:
|
|
149
149
|
bad_credentials: 'User email and/or password is incorrect'
|
150
150
|
refresh_token:
|
151
151
|
invalid: 'Invalid token'
|
152
|
+
account_not_confirmed: 'User account has not been confirmed'
|
153
|
+
account_locked: 'User account has been locked'
|
152
154
|
unlock:
|
153
155
|
email_not_exists: 'Email address does not belongs to a registered account'
|
154
156
|
account_not_locked: 'User account has not been locked'
|
@@ -149,6 +149,8 @@ es:
|
|
149
149
|
bad_credentials: 'Correo electrónico y/o contraseña es incorrecto(a)'
|
150
150
|
refresh_token:
|
151
151
|
invalid: 'El token es inválido'
|
152
|
+
account_not_confirmed: 'Cuenta de usuario no ha sido confirmada'
|
153
|
+
account_locked: 'Cuenta de usuario ha sido bloqueada'
|
152
154
|
unlock:
|
153
155
|
email_not_exists: 'Correo electrónico no pertenece a un usuario registrado'
|
154
156
|
account_not_locked: 'Cuenta de usuario no ha sido bloqueada'
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module Morpho
|
2
2
|
class API < ::Grape::API
|
3
3
|
format :json
|
4
|
-
|
4
|
+
|
5
|
+
error_formatter :json, Morpho::Formatters::StandardError
|
6
|
+
|
7
|
+
rescue_from Morpho::Exceptions::StandardError do |e|
|
8
|
+
message = Morpho::Entities::Error.represent(e)
|
9
|
+
error!(message, e.status)
|
10
|
+
end
|
5
11
|
|
6
12
|
mount Morpho::Resources::Users
|
7
13
|
mount Morpho::Resources::Externals
|
@@ -10,6 +16,8 @@ module Morpho
|
|
10
16
|
mount Morpho::Resources::Unlocks
|
11
17
|
mount Morpho::Resources::Activations
|
12
18
|
|
19
|
+
mount Morpho::Resources::Hello
|
20
|
+
|
13
21
|
add_swagger_documentation({
|
14
22
|
info: {
|
15
23
|
title: Morpho.config.api.title,
|
@@ -19,7 +27,9 @@ module Morpho
|
|
19
27
|
})
|
20
28
|
|
21
29
|
route :any, '*path' do
|
22
|
-
|
30
|
+
raise Morpho::Exceptions::StandardError.new(
|
31
|
+
status: 404
|
32
|
+
)
|
23
33
|
end
|
24
34
|
end
|
25
35
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
Morpho.configure do |config|
|
2
|
-
config.host = ENV.fetch('HOST', 'localhost
|
2
|
+
config.host = ENV.fetch('HOST', 'localhost')
|
3
|
+
config.port = ENV.fetch('PORT', 3000)
|
3
4
|
config.protocol = ENV.fetch('PROTOCOL', 'http')
|
4
5
|
config.mailer.from = ENV.fetch('MAILER_FROM', 'no-reply@example.com')
|
5
6
|
config.mailer.address = ENV.fetch('MAILER_ADDRESS', 'smtp.mailtrap.io')
|
data/lib/morpho/configuration.rb
CHANGED
@@ -6,6 +6,7 @@ require 'morpho/configurations/auth'
|
|
6
6
|
module Morpho
|
7
7
|
class Configuration
|
8
8
|
attr_accessor :host
|
9
|
+
attr_accessor :port
|
9
10
|
attr_accessor :protocol
|
10
11
|
|
11
12
|
attr_accessor :mailer
|
@@ -15,6 +16,7 @@ module Morpho
|
|
15
16
|
|
16
17
|
def initialize
|
17
18
|
self.host = ''
|
19
|
+
self.port = ''
|
18
20
|
self.protocol = ''
|
19
21
|
|
20
22
|
self.mailer = Morpho::Configurations::Mailer.new
|
data/lib/morpho/engine.rb
CHANGED
@@ -7,12 +7,6 @@ module Morpho
|
|
7
7
|
config.autoload_paths << File.expand_path('app/api', __dir__)
|
8
8
|
end
|
9
9
|
|
10
|
-
initializer 'morpho.migrations', before: :load_config_initializers do |app|
|
11
|
-
config.paths['db/migrate'].expanded.each do |expanded_path|
|
12
|
-
app.config.paths['db/migrate'] << expanded_path
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
10
|
initializer 'morpho.configurations', after: :load_config_initializers do |app|
|
17
11
|
mailer = ActionMailer::Base
|
18
12
|
mailer.delivery_method = Morpho.config.mailer.delivery_method
|
@@ -24,6 +18,7 @@ module Morpho
|
|
24
18
|
|
25
19
|
mailer.default_url_options = {
|
26
20
|
host: Morpho.config.host,
|
21
|
+
port: Morpho.config.port,
|
27
22
|
protocol: Morpho.config.protocol
|
28
23
|
}
|
29
24
|
|
data/lib/morpho/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morpho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hugo Gilmar Erazo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -312,20 +312,29 @@ files:
|
|
312
312
|
- app/assets/images/morpho/morpho.svg
|
313
313
|
- app/assets/javascripts/morpho/application.js
|
314
314
|
- app/assets/stylesheets/morpho/application.css
|
315
|
-
- app/concepts/morpho/user/
|
316
|
-
- app/concepts/morpho/user/
|
317
|
-
- app/concepts/morpho/user/
|
318
|
-
- app/concepts/morpho/user/
|
319
|
-
- app/concepts/morpho/user/
|
320
|
-
- app/concepts/morpho/user/
|
321
|
-
- app/concepts/morpho/user/
|
322
|
-
- app/concepts/morpho/user/
|
323
|
-
- app/concepts/morpho/
|
324
|
-
- app/concepts/morpho/
|
325
|
-
- app/concepts/morpho/
|
326
|
-
- app/concepts/morpho/
|
327
|
-
- app/concepts/morpho/
|
328
|
-
- app/concepts/morpho/
|
315
|
+
- app/concepts/morpho/contracts/user/deliver_email.rb
|
316
|
+
- app/concepts/morpho/contracts/user/external_sign_in.rb
|
317
|
+
- app/concepts/morpho/contracts/user/refresh_token.rb
|
318
|
+
- app/concepts/morpho/contracts/user/resend_activation_email.rb
|
319
|
+
- app/concepts/morpho/contracts/user/resend_unlock_email.rb
|
320
|
+
- app/concepts/morpho/contracts/user/send_reset_password_email.rb
|
321
|
+
- app/concepts/morpho/contracts/user/sign_in.rb
|
322
|
+
- app/concepts/morpho/contracts/user/sign_up.rb
|
323
|
+
- app/concepts/morpho/operations/base/create.rb
|
324
|
+
- app/concepts/morpho/operations/base/delete.rb
|
325
|
+
- app/concepts/morpho/operations/base/fetch.rb
|
326
|
+
- app/concepts/morpho/operations/base/find.rb
|
327
|
+
- app/concepts/morpho/operations/base/form.rb
|
328
|
+
- app/concepts/morpho/operations/base/update.rb
|
329
|
+
- app/concepts/morpho/operations/user/deliver_email.rb
|
330
|
+
- app/concepts/morpho/operations/user/external_sign_in.rb
|
331
|
+
- app/concepts/morpho/operations/user/generate_token.rb
|
332
|
+
- app/concepts/morpho/operations/user/refresh_token.rb
|
333
|
+
- app/concepts/morpho/operations/user/resend_activation_email.rb
|
334
|
+
- app/concepts/morpho/operations/user/resend_unlock_email.rb
|
335
|
+
- app/concepts/morpho/operations/user/send_reset_password_email.rb
|
336
|
+
- app/concepts/morpho/operations/user/sign_in.rb
|
337
|
+
- app/concepts/morpho/operations/user/sign_up.rb
|
329
338
|
- app/controllers/morpho/activations_controller.rb
|
330
339
|
- app/controllers/morpho/application_controller.rb
|
331
340
|
- app/controllers/morpho/home_controller.rb
|
@@ -424,7 +433,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
424
433
|
version: '0'
|
425
434
|
requirements: []
|
426
435
|
rubyforge_project:
|
427
|
-
rubygems_version: 2.7.
|
436
|
+
rubygems_version: 2.7.8
|
428
437
|
signing_key:
|
429
438
|
specification_version: 4
|
430
439
|
summary: Morpho Core.
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Morpho
|
2
|
-
class User::Contract::ExternalSignIn < Reform::Form
|
3
|
-
include Reform::Form::ActiveRecord
|
4
|
-
|
5
|
-
property :email
|
6
|
-
property :provider
|
7
|
-
property :uid
|
8
|
-
validates :email, presence: true, email_format: true
|
9
|
-
validates :provider, presence: true
|
10
|
-
validates :uid, presence: true
|
11
|
-
end
|
12
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'reform/form/validation/unique_validator'
|
2
|
-
|
3
|
-
module Morpho
|
4
|
-
class User::Contract::SignUp < Reform::Form
|
5
|
-
include Reform::Form::ActiveRecord
|
6
|
-
|
7
|
-
property :email
|
8
|
-
property :password
|
9
|
-
property :password_confirmation, virtual: true
|
10
|
-
validates :email, presence: true, unique: true, email_format: true
|
11
|
-
validates :password,
|
12
|
-
presence: true,
|
13
|
-
confirmation: true,
|
14
|
-
length: { minimum: Morpho.config.auth.password_minimum_length },
|
15
|
-
# rubocop:disable Style/HashSyntax
|
16
|
-
:'morpho/validators/contain_number' => true,
|
17
|
-
:'morpho/validators/contain_uppercase' => true,
|
18
|
-
:'morpho/validators/contain_symbol' => true
|
19
|
-
# rubocop:enable Style/HashSyntax
|
20
|
-
validates :password_confirmation, presence: true
|
21
|
-
end
|
22
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Morpho
|
2
|
-
class User::Operation::Activate < Trailblazer::Operation
|
3
|
-
pass :validate!
|
4
|
-
pass :find!
|
5
|
-
pass :check!
|
6
|
-
pass :activation_email!
|
7
|
-
|
8
|
-
def validate!(options, **)
|
9
|
-
options['contract'] = Morpho::User::Contract::Activate.new(OpenStruct.new)
|
10
|
-
|
11
|
-
unless options['contract'].validate(options['data'])
|
12
|
-
raise Morpho::Exceptions::StandardError.new(
|
13
|
-
errors: options['contract'].errors
|
14
|
-
)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def find!(options, **)
|
19
|
-
options['model'] = Morpho::User.find_by(email: options['data']['email'])
|
20
|
-
|
21
|
-
if options['model'].nil?
|
22
|
-
raise Morpho::Exceptions::StandardError.new(
|
23
|
-
message: I18n.t('morpho.api.messages.activate.email_not_exists'),
|
24
|
-
status: 404
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def check!(options, **)
|
30
|
-
if options['model'].active?
|
31
|
-
raise Morpho::Exceptions::StandardError.new(
|
32
|
-
message: I18n.t('morpho.api.messages.activate.account_already_confirmed'),
|
33
|
-
status: 405
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def activation_email!(options, **)
|
39
|
-
options['model'].resend_activation_needed_email!
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module Morpho
|
2
|
-
class User::Operation::ExternalSignIn < Trailblazer::Operation
|
3
|
-
pass :validate!
|
4
|
-
pass :find_authentication!
|
5
|
-
pass :find_user!
|
6
|
-
pass :sign_in!
|
7
|
-
pass :register!
|
8
|
-
pass :sign_up!
|
9
|
-
pass :generate_refresh_token!
|
10
|
-
pass :register_last_login_activity!
|
11
|
-
pass :authentication_token!
|
12
|
-
|
13
|
-
def validate!(options, **)
|
14
|
-
options['contract'] = Morpho::User::Contract::ExternalSignIn.new(OpenStruct.new)
|
15
|
-
|
16
|
-
unless options['contract'].validate(options['data'])
|
17
|
-
raise Morpho::Exceptions::StandardError.new(
|
18
|
-
errors: options['contract'].errors
|
19
|
-
)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def find_authentication!(options, **)
|
24
|
-
options['authentication.model'] = Morpho::Authentication.find_by(
|
25
|
-
uid: options['data']['uid'],
|
26
|
-
provider: options['data']['provider']
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
def find_user!(options, **)
|
31
|
-
options['user.model'] = Morpho::User.find_by(email: options['data']['email'])
|
32
|
-
end
|
33
|
-
|
34
|
-
def sign_in!(options, **)
|
35
|
-
if options['authentication.model']
|
36
|
-
options['user.model'] = options['authentication.model'].user
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def register!(options, **)
|
41
|
-
if options['user.model'] && options['authentication.model'].nil?
|
42
|
-
provider = options['data']['provider'].downcase
|
43
|
-
|
44
|
-
options['user.model'].add_provider_to_user(provider, options['data']['uid'])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def sign_up!(options, **)
|
49
|
-
if options['user.model'].nil? && options['authentication.model'].nil?
|
50
|
-
provider = options['data']['provider'].downcase
|
51
|
-
|
52
|
-
options['user.model'] = Morpho::User.create_from_provider(provider, options['data']['uid'], {
|
53
|
-
email: options['data']['email']
|
54
|
-
})
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def generate_refresh_token!(options, **)
|
59
|
-
options['user.model'].generate_refresh_token!
|
60
|
-
end
|
61
|
-
|
62
|
-
def register_last_login_activity!(options, **)
|
63
|
-
options['user.model'].register_last_login_activity!(options['ip'])
|
64
|
-
end
|
65
|
-
|
66
|
-
def authentication_token!(options, **)
|
67
|
-
options['token'] = ::Morpho::JWT::Payload.new(options['user.model'])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Morpho
|
2
|
-
class User::Operation::RefreshToken < Trailblazer::Operation
|
3
|
-
pass :validate!
|
4
|
-
pass :find!
|
5
|
-
pass :generate_refresh_token!
|
6
|
-
pass :authentication_token!
|
7
|
-
|
8
|
-
def validate!(options, **)
|
9
|
-
options['contract'] = Morpho::User::Contract::RefreshToken.new(OpenStruct.new)
|
10
|
-
|
11
|
-
unless options['contract'].validate(options['data'])
|
12
|
-
raise Morpho::Exceptions::StandardError.new(
|
13
|
-
errors: options['contract'].errors
|
14
|
-
)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def find!(options, **)
|
19
|
-
options['model'] = Morpho::User.find_by(refresh_token: options['data']['refresh_token'])
|
20
|
-
|
21
|
-
if options['model'].nil?
|
22
|
-
raise Morpho::Exceptions::StandardError.new(
|
23
|
-
message: I18n.t('morpho.api.messages.refresh_token.invalid'),
|
24
|
-
status: 404
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def generate_refresh_token!(options, **)
|
30
|
-
options['model'].generate_refresh_token!
|
31
|
-
end
|
32
|
-
|
33
|
-
def authentication_token!(options, **)
|
34
|
-
options['token'] = ::Morpho::JWT::Payload.new(options['model'])
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|