morpho 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/api/concerns/morpho/grape/http_responses.rb +41 -0
- data/app/api/concerns/morpho/grape/jwt_authentication.rb +77 -0
- data/app/api/concerns/morpho/grape/user_activation.rb +13 -0
- data/app/api/concerns/morpho/grape/user_password_reset.rb +13 -0
- data/app/api/concerns/morpho/grape/user_registration.rb +19 -0
- data/app/api/concerns/morpho/grape/user_unlock.rb +13 -0
- data/app/api/morpho/api.rb +24 -0
- data/app/api/morpho/entities/authentication_token.rb +8 -0
- data/app/api/morpho/entities/user.rb +7 -0
- data/app/api/morpho/entities/user_sign_in.rb +8 -0
- data/app/api/morpho/entities/user_sign_up.rb +9 -0
- data/app/api/morpho/resources/activations.rb +29 -0
- data/app/api/morpho/resources/passwords.rb +25 -0
- data/app/api/morpho/resources/tokens.rb +19 -0
- data/app/api/morpho/resources/unlocks.rb +29 -0
- data/app/api/morpho/resources/users.rb +19 -0
- data/app/assets/images/morpho/morpho.png +0 -0
- data/app/assets/images/morpho/morpho.svg +89 -0
- data/app/assets/stylesheets/morpho/application.css +74 -1
- data/app/controllers/morpho/activations_controller.rb +44 -0
- data/app/controllers/morpho/application_controller.rb +9 -0
- data/app/controllers/morpho/home_controller.rb +6 -0
- data/app/controllers/morpho/passwords_controller.rb +56 -0
- data/app/controllers/morpho/sessions_controller.rb +24 -0
- data/app/controllers/morpho/unlocks_controller.rb +44 -0
- data/app/controllers/morpho/users_controller.rb +25 -0
- data/app/mailers/morpho/application_mailer.rb +0 -1
- data/app/mailers/morpho/user_mailer.rb +31 -0
- data/app/models/morpho/authentication.rb +5 -0
- data/app/models/morpho/user.rb +60 -0
- data/app/views/layouts/morpho/application.html.erb +6 -4
- data/app/views/layouts/morpho/mailer.html.erb +13 -0
- data/app/views/layouts/morpho/mailer.text.erb +1 -0
- data/app/views/morpho/activations/new.html.erb +16 -0
- data/app/views/morpho/home/index.html.erb +4 -0
- data/app/views/morpho/passwords/edit.html.erb +18 -0
- data/app/views/morpho/passwords/new.html.erb +16 -0
- data/app/views/morpho/sessions/new.html.erb +23 -0
- data/app/views/morpho/unlocks/new.html.erb +16 -0
- data/app/views/morpho/user_mailer/activation_needed_email.html.erb +7 -0
- data/app/views/morpho/user_mailer/activation_needed_email.text.erb +7 -0
- data/app/views/morpho/user_mailer/activation_success_email.html.erb +7 -0
- data/app/views/morpho/user_mailer/activation_success_email.text.erb +7 -0
- data/app/views/morpho/user_mailer/reset_password_email.html.erb +7 -0
- data/app/views/morpho/user_mailer/reset_password_email.text.erb +7 -0
- data/app/views/morpho/user_mailer/unlock_token_email.html.erb +7 -0
- data/app/views/morpho/user_mailer/unlock_token_email.text.erb +7 -0
- data/app/views/morpho/users/new.html.erb +20 -0
- data/config/initializers/flash_rails_messages_skeleton.rb +22 -0
- data/config/initializers/simple_form.rb +182 -0
- data/config/initializers/sorcery.rb +513 -0
- data/config/locales/morpho.en.yml +93 -0
- data/config/routes.rb +25 -0
- data/db/migrate/20180919162009_sorcery_core.rb +13 -0
- data/db/migrate/20180919162055_sorcery_remember_me.rb +8 -0
- data/db/migrate/20180919162056_sorcery_reset_password.rb +10 -0
- data/db/migrate/20180919162057_sorcery_user_activation.rb +9 -0
- data/db/migrate/20180919162058_sorcery_brute_force_protection.rb +9 -0
- data/db/migrate/20180919162059_sorcery_activity_logging.rb +10 -0
- data/db/migrate/20180919162100_sorcery_external.rb +12 -0
- data/lib/generators/morpho/install/install_generator.rb +7 -0
- data/lib/generators/morpho/install/templates/config/initializers/morpho.rb +17 -0
- data/lib/generators/morpho/install/templates/public/favicon-16x16.png +0 -0
- data/lib/generators/morpho/install/templates/public/favicon-32x32.png +0 -0
- data/lib/generators/morpho/install/templates/public/favicon.ico +0 -0
- data/lib/morpho.rb +15 -2
- data/lib/morpho/configuration.rb +24 -0
- data/lib/morpho/configurations/api.rb +31 -0
- data/lib/morpho/configurations/auth.rb +11 -0
- data/lib/morpho/configurations/jwt.rb +17 -0
- data/lib/morpho/configurations/mailer.rb +23 -0
- data/lib/morpho/engine.rb +33 -0
- data/lib/morpho/loader.rb +11 -0
- data/lib/morpho/version.rb +1 -1
- data/lib/tasks/morpho_tasks.rake +1 -1
- data/lib/templates/erb/scaffold/_form.html.erb +15 -0
- metadata +223 -2
@@ -0,0 +1,93 @@
|
|
1
|
+
en:
|
2
|
+
morpho:
|
3
|
+
labels:
|
4
|
+
sessions:
|
5
|
+
sign_in: 'Sign in'
|
6
|
+
sign_up: 'Sign up with a new user account'
|
7
|
+
password_reset: 'Reset my account password'
|
8
|
+
unlock: 'Unlock my account'
|
9
|
+
users:
|
10
|
+
sign_up: 'Sign up'
|
11
|
+
sign_in: 'Sign in with an existent user account'
|
12
|
+
activation: 'Activate my account'
|
13
|
+
passwords:
|
14
|
+
send_instructions: 'Send reset password instructions'
|
15
|
+
sign_in: 'Sign in with an existent user account'
|
16
|
+
sign_up: 'Sign up with a new user account'
|
17
|
+
change_password: 'Change my password'
|
18
|
+
activations:
|
19
|
+
send_instructions: 'Send activation instructions'
|
20
|
+
sign_in: 'Sign in with an existent user account'
|
21
|
+
sign_up: 'Sign up with a new user account'
|
22
|
+
unlocks:
|
23
|
+
send_instructions: 'Send unlock instructions'
|
24
|
+
sign_in: 'Sign in with an existent user account'
|
25
|
+
sign_up: 'Sign up with a new user account'
|
26
|
+
messages:
|
27
|
+
unauthenticated: 'You need to sign in first'
|
28
|
+
sessions:
|
29
|
+
create:
|
30
|
+
success: 'Sign in successfully'
|
31
|
+
failure: 'Sign in failed, please check the information provided'
|
32
|
+
destroy:
|
33
|
+
success: 'You sign out successfully'
|
34
|
+
users:
|
35
|
+
create:
|
36
|
+
success: 'Sign up successfully, you will receive al email with account activation instructions'
|
37
|
+
failure: 'Sign up failed, please review the errors below'
|
38
|
+
passwords:
|
39
|
+
create:
|
40
|
+
success: 'You will receive password reset instructions on your email inbox'
|
41
|
+
failure: 'No user acount found with that email'
|
42
|
+
edit:
|
43
|
+
success: 'Enter your new password on the fields below'
|
44
|
+
failure: 'Password reset failed, request a new activation token'
|
45
|
+
update:
|
46
|
+
success: 'Password successfully changed, sign in to continue'
|
47
|
+
failure: 'Password change failed, please review the errors below'
|
48
|
+
activations:
|
49
|
+
create:
|
50
|
+
success: 'You will receive user account activation instructions on your email inbox'
|
51
|
+
failure: 'No user account found with that email or user account is active already'
|
52
|
+
activate:
|
53
|
+
success: 'Activation successfully, sign in to continue'
|
54
|
+
failure: 'Activation failed, request a new activation token'
|
55
|
+
unlocks:
|
56
|
+
create:
|
57
|
+
success: 'You will receive user account unlock instructions on your email inbox'
|
58
|
+
failure: 'No user account found with that email or user account is unlocked already'
|
59
|
+
unlock:
|
60
|
+
success: 'Unlock successfully, sign in to continue'
|
61
|
+
failure: 'Unlock failed, request a new unlock token'
|
62
|
+
mailer:
|
63
|
+
activation_needed:
|
64
|
+
subject: 'You have successfully signed up'
|
65
|
+
activation_success:
|
66
|
+
subject: 'Your account is now activated'
|
67
|
+
reset_password:
|
68
|
+
subject: 'You have requested to reset your password'
|
69
|
+
unlock_token:
|
70
|
+
subject: 'Your account has been locked'
|
71
|
+
api:
|
72
|
+
messages:
|
73
|
+
bad_request: 'Bad request'
|
74
|
+
unauthorized: 'Unauthorized'
|
75
|
+
payment_required: 'Payment required'
|
76
|
+
forbidden: 'Forbidden'
|
77
|
+
not_found: 'Not found'
|
78
|
+
method_not_allowed: 'Method not allowed'
|
79
|
+
unprocessable_entity: 'Unprocessable entity'
|
80
|
+
simple_form:
|
81
|
+
'yes': 'Yes'
|
82
|
+
'no': 'No'
|
83
|
+
required:
|
84
|
+
text: 'required'
|
85
|
+
mark: '*'
|
86
|
+
error_notification:
|
87
|
+
default_message: 'Please review the problems below:'
|
88
|
+
labels:
|
89
|
+
defaults:
|
90
|
+
email: 'Email'
|
91
|
+
password: 'Password'
|
92
|
+
password_confirmation: 'Confirm your password'
|
93
|
+
remember_me: 'Remember me'
|
data/config/routes.rb
CHANGED
@@ -1,2 +1,27 @@
|
|
1
1
|
Morpho::Engine.routes.draw do
|
2
|
+
get 'sign_in', to: 'sessions#new'
|
3
|
+
post 'sign_in', to: 'sessions#create'
|
4
|
+
delete 'sign_out', to: 'sessions#destroy'
|
5
|
+
|
6
|
+
get 'sign_up', to: 'users#new'
|
7
|
+
post 'sign_up', to: 'users#create'
|
8
|
+
get 'account', to: 'users#edit'
|
9
|
+
put 'account', to: 'users#update'
|
10
|
+
|
11
|
+
get 'new_activation', to: 'activations#new'
|
12
|
+
post 'send_activation', to: 'activations#create'
|
13
|
+
get 'activate/:token', to: 'activations#show', as: :activate
|
14
|
+
|
15
|
+
get 'new_reset_password', to: 'passwords#new'
|
16
|
+
post 'send_reset_password', to: 'passwords#create'
|
17
|
+
get 'new_password/:token', to: 'passwords#edit', as: :new_password
|
18
|
+
put 'change_password/:token', to: 'passwords#update', as: :change_password
|
19
|
+
|
20
|
+
get 'new_unlock', to: 'unlocks#new'
|
21
|
+
post 'send_unlock', to: 'unlocks#create'
|
22
|
+
get 'unlock/:token', to: 'unlocks#show', as: :unlock
|
23
|
+
|
24
|
+
mount Morpho::API => '/api', as: :api
|
25
|
+
|
26
|
+
root to: 'home#index'
|
2
27
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class SorceryCore < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :morpho_users do |t|
|
4
|
+
t.string :email, :null => false
|
5
|
+
t.string :crypted_password
|
6
|
+
t.string :salt
|
7
|
+
|
8
|
+
t.timestamps :null => false
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :morpho_users, :email, unique: true
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class SorceryRememberMe < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
add_column :morpho_users, :remember_me_token, :string, :default => nil
|
4
|
+
add_column :morpho_users, :remember_me_token_expires_at, :datetime, :default => nil
|
5
|
+
|
6
|
+
add_index :morpho_users, :remember_me_token
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class SorceryResetPassword < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
add_column :morpho_users, :reset_password_token, :string, :default => nil
|
4
|
+
add_column :morpho_users, :reset_password_token_expires_at, :datetime, :default => nil
|
5
|
+
add_column :morpho_users, :reset_password_email_sent_at, :datetime, :default => nil
|
6
|
+
add_column :morpho_users, :access_count_to_reset_password_page, :integer, :default => 0
|
7
|
+
|
8
|
+
add_index :morpho_users, :reset_password_token
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class SorceryUserActivation < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
add_column :morpho_users, :activation_state, :string, :default => nil
|
4
|
+
add_column :morpho_users, :activation_token, :string, :default => nil
|
5
|
+
add_column :morpho_users, :activation_token_expires_at, :datetime, :default => nil
|
6
|
+
|
7
|
+
add_index :morpho_users, :activation_token
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class SorceryBruteForceProtection < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
add_column :morpho_users, :failed_logins_count, :integer, :default => 0
|
4
|
+
add_column :morpho_users, :lock_expires_at, :datetime, :default => nil
|
5
|
+
add_column :morpho_users, :unlock_token, :string, :default => nil
|
6
|
+
|
7
|
+
add_index :morpho_users, :unlock_token
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class SorceryActivityLogging < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
add_column :morpho_users, :last_login_at, :datetime, :default => nil
|
4
|
+
add_column :morpho_users, :last_logout_at, :datetime, :default => nil
|
5
|
+
add_column :morpho_users, :last_activity_at, :datetime, :default => nil
|
6
|
+
add_column :morpho_users, :last_login_from_ip_address, :string, :default => nil
|
7
|
+
|
8
|
+
add_index :morpho_users, [:last_logout_at, :last_activity_at]
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class SorceryExternal < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :morpho_authentications do |t|
|
4
|
+
t.integer :user_id, :null => false
|
5
|
+
t.string :provider, :uid, :null => false
|
6
|
+
|
7
|
+
t.timestamps :null => false
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :morpho_authentications, [:provider, :uid]
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Morpho.configure do |config|
|
2
|
+
config.host = 'localhost:3000'
|
3
|
+
config.mailer.from = ''
|
4
|
+
config.mailer.address = 'smtp.mailtrap.io'
|
5
|
+
config.mailer.user_name = ''
|
6
|
+
config.mailer.password = ''
|
7
|
+
config.mailer.port = 2525
|
8
|
+
config.mailer.authentication = 'login'
|
9
|
+
config.mailer.enable_starttls_auto = false
|
10
|
+
config.jwt.secret = ''
|
11
|
+
config.jwt.algorithm = 'HS256'
|
12
|
+
config.jwt.header = 'Authorization'
|
13
|
+
config.jwt.expiration_time = 1.hour
|
14
|
+
config.api.title = ''
|
15
|
+
config.api.description = ''
|
16
|
+
config.auth.failed_login_attempts_limit = 5
|
17
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
data/lib/morpho.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'morpho/loader'
|
2
|
+
require 'morpho/engine'
|
3
|
+
require 'morpho/version'
|
4
|
+
require 'morpho/configuration'
|
2
5
|
|
3
6
|
module Morpho
|
4
|
-
|
7
|
+
class << self
|
8
|
+
attr_writer :config
|
9
|
+
|
10
|
+
def configure
|
11
|
+
yield config
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
@config ||= Morpho::Configuration.new
|
16
|
+
end
|
17
|
+
end
|
5
18
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'morpho/configurations/mailer'
|
2
|
+
require 'morpho/configurations/api'
|
3
|
+
require 'morpho/configurations/jwt'
|
4
|
+
require 'morpho/configurations/auth'
|
5
|
+
|
6
|
+
module Morpho
|
7
|
+
class Configuration
|
8
|
+
attr_accessor :host
|
9
|
+
|
10
|
+
attr_accessor :mailer
|
11
|
+
attr_accessor :api
|
12
|
+
attr_accessor :jwt
|
13
|
+
attr_accessor :auth
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.host = ''
|
17
|
+
|
18
|
+
self.mailer = Morpho::Configurations::Mailer.new
|
19
|
+
self.api = Morpho::Configurations::API.new
|
20
|
+
self.jwt = Morpho::Configurations::JWT.new
|
21
|
+
self.auth = Morpho::Configurations::Auth.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Morpho
|
2
|
+
module Configurations
|
3
|
+
class API
|
4
|
+
attr_accessor :title
|
5
|
+
attr_accessor :description
|
6
|
+
attr_accessor :entities
|
7
|
+
attr_accessor :versions
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
self.title = ''
|
11
|
+
self.description = ''
|
12
|
+
self.entities = []
|
13
|
+
self.versions = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def register_entity(entity)
|
17
|
+
self.entities << entity
|
18
|
+
end
|
19
|
+
|
20
|
+
def register_entities
|
21
|
+
end
|
22
|
+
|
23
|
+
def register_version(version)
|
24
|
+
self.versions << version
|
25
|
+
end
|
26
|
+
|
27
|
+
def register_versions
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Morpho
|
2
|
+
module Configurations
|
3
|
+
class JWT
|
4
|
+
attr_accessor :secret
|
5
|
+
attr_accessor :algorithm
|
6
|
+
attr_accessor :header
|
7
|
+
attr_accessor :expiration_time
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
self.secret = ''
|
11
|
+
self.algorithm = ''
|
12
|
+
self.header = ''
|
13
|
+
self.expiration_time = 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Morpho
|
2
|
+
module Configurations
|
3
|
+
class Mailer
|
4
|
+
attr_accessor :from
|
5
|
+
attr_accessor :address
|
6
|
+
attr_accessor :user_name
|
7
|
+
attr_accessor :password
|
8
|
+
attr_accessor :port
|
9
|
+
attr_accessor :authentication
|
10
|
+
attr_accessor :enable_starttls_auto
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
self.from = ''
|
14
|
+
self.address = ''
|
15
|
+
self.user_name = ''
|
16
|
+
self.password = ''
|
17
|
+
self.port = ''
|
18
|
+
self.authentication = ''
|
19
|
+
self.enable_starttls_auto = ''
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/morpho/engine.rb
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
module Morpho
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
isolate_namespace Morpho
|
4
|
+
engine_name 'morpho'
|
5
|
+
|
6
|
+
initializer 'morpho.paths', before: :set_autoload_paths do |app|
|
7
|
+
config.autoload_paths << File.expand_path('app/api', __dir__)
|
8
|
+
end
|
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
|
+
initializer 'morpho.configurations', after: :load_config_initializers do |app|
|
17
|
+
ActionMailer::Base.delivery_method = :smtp
|
18
|
+
ActionMailer::Base.perform_deliveries = true
|
19
|
+
|
20
|
+
ActionMailer::Base.default_options = {
|
21
|
+
from: Morpho.config.mailer.from
|
22
|
+
}
|
23
|
+
|
24
|
+
ActionMailer::Base.default_url_options = {
|
25
|
+
host: Morpho.config.host
|
26
|
+
}
|
27
|
+
|
28
|
+
ActionMailer::Base.smtp_settings = {
|
29
|
+
address: Morpho.config.mailer.address,
|
30
|
+
port: Morpho.config.mailer.port,
|
31
|
+
user_name: Morpho.config.mailer.user_name,
|
32
|
+
password: Morpho.config.mailer.password,
|
33
|
+
authentication: Morpho.config.mailer.authentication,
|
34
|
+
enable_starttls_auto: Morpho.config.mailer.enable_starttls_auto
|
35
|
+
}
|
36
|
+
end
|
4
37
|
end
|
5
38
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'draper'
|
2
|
+
require 'sorcery'
|
3
|
+
require 'jwt'
|
4
|
+
require 'validates_email_format_of'
|
5
|
+
require 'flash_rails_messages'
|
6
|
+
require 'simple_form'
|
7
|
+
require 'grape'
|
8
|
+
require 'grape-entity'
|
9
|
+
require 'grape-swagger'
|
10
|
+
require 'grape-swagger/entity'
|
11
|
+
require 'grape-swagger/representable'
|
data/lib/morpho/version.rb
CHANGED
data/lib/tasks/morpho_tasks.rake
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
<%# frozen_string_literal: true %>
|
2
|
+
<%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
|
3
|
+
<%%= f.error_notification %>
|
4
|
+
<%%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
|
5
|
+
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%- attributes.each do |attribute| -%>
|
8
|
+
<%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
|
9
|
+
<%- end -%>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="form-actions">
|
13
|
+
<%%= f.button :submit %>
|
14
|
+
</div>
|
15
|
+
<%% end %>
|