hello-rails 0.0.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +97 -0
- data/Rakefile +23 -0
- data/app/controllers/hello/application_controller.rb +27 -0
- data/app/controllers/hello/authentication/sessions_controller.rb +81 -0
- data/app/controllers/hello/authentication/sign_in_controller.rb +39 -0
- data/app/controllers/hello/authentication/sudo_mode_controller.rb +40 -0
- data/app/controllers/hello/concerns/authentication/sign_in.rb +44 -0
- data/app/controllers/hello/concerns/management/forgot_password.rb +45 -0
- data/app/controllers/hello/concerns/management/reset_password.rb +33 -0
- data/app/controllers/hello/concerns/registration/sign_up.rb +64 -0
- data/app/controllers/hello/internationalization/locale_controller.rb +28 -0
- data/app/controllers/hello/management/accesses_controller.rb +29 -0
- data/app/controllers/hello/management/confirm_emails_controller.rb +41 -0
- data/app/controllers/hello/management/emails_controller.rb +67 -0
- data/app/controllers/hello/management/forgot_password_controller.rb +41 -0
- data/app/controllers/hello/management/passwords_controller.rb +57 -0
- data/app/controllers/hello/management/profiles_controller.rb +71 -0
- data/app/controllers/hello/management/reset_password_controller.rb +53 -0
- data/app/controllers/hello/registration/sign_up_controller.rb +63 -0
- data/app/helpers/hello/application_helper.rb +5 -0
- data/app/mailers/hello/mailer.rb +26 -0
- data/app/models/access.rb +2 -0
- data/app/models/credential.rb +2 -0
- data/app/models/email_credential.rb +2 -0
- data/app/models/password_credential.rb +2 -0
- data/app/models/user.rb +2 -0
- data/app/views/hello/authentication/_sign_in.html.erb +64 -0
- data/app/views/hello/authentication/new_session.html.erb +4 -0
- data/app/views/hello/authentication/sessions.html.erb +36 -0
- data/app/views/hello/authentication/sign_in.html.erb +3 -0
- data/app/views/hello/authentication/sudo_mode.html.erb +37 -0
- data/app/views/hello/internationalization/locales.html.erb +7 -0
- data/app/views/hello/mailer/confirm_email.html.erb +12 -0
- data/app/views/hello/mailer/forgot_password.html.erb +12 -0
- data/app/views/hello/mailer/welcome.html.erb +11 -0
- data/app/views/hello/management/accesses.html.erb +47 -0
- data/app/views/hello/management/cancel.html.erb +14 -0
- data/app/views/hello/management/email_credentials/expired_confirmation_token.html.erb +1 -0
- data/app/views/hello/management/email_credentials/index.html.erb +84 -0
- data/app/views/hello/management/password_credentials/_forgot_form.html.erb +17 -0
- data/app/views/hello/management/password_credentials/_reset_form.html.erb +39 -0
- data/app/views/hello/management/password_credentials/forgot.html.erb +10 -0
- data/app/views/hello/management/password_credentials/forgot_success.html.erb +26 -0
- data/app/views/hello/management/password_credentials/reset.html.erb +3 -0
- data/app/views/hello/management/password_credentials/show.html.erb +25 -0
- data/app/views/hello/management/user.html.erb +73 -0
- data/app/views/hello/registration/_sign_up.html.erb +86 -0
- data/app/views/hello/registration/sign_up.html.erb +3 -0
- data/app/views/hello/registration/sign_up_widget.html.erb +3 -0
- data/app/views/hello/shared/_errors.html.erb +11 -0
- data/app/views/hello/shared/_flash.html.erb +8 -0
- data/app/views/hello/shared/_nav_pills.html.erb +15 -0
- data/app/views/hello/shared/_session_expiration.html.erb +15 -0
- data/app/views/hello/shared/_settings.html.erb +41 -0
- data/config/locales/hello.en.yml +69 -0
- data/config/locales/hello.es.yml +71 -0
- data/config/locales/hello.fr.yml +71 -0
- data/config/locales/hello.pl.yml +71 -0
- data/config/locales/hello.pt-BR.yml +71 -0
- data/config/locales/hello.zh-CN.yml +71 -0
- data/config/locales/hello.zh-TW.yml +71 -0
- data/config/routes.rb +74 -0
- data/db/migrate/1_create_credentials.rb +17 -0
- data/db/migrate/2_create_accesses.rb +15 -0
- data/db/migrate/3_create_users.rb +23 -0
- data/lib/generators/hello/concerns/USAGE +8 -0
- data/lib/generators/hello/concerns/concerns_generator.rb +10 -0
- data/lib/generators/hello/from_devise/USAGE +8 -0
- data/lib/generators/hello/from_devise/from_devise_generator.rb +13 -0
- data/lib/generators/hello/from_devise/templates/from_devise.migration.rb +39 -0
- data/lib/generators/hello/install/USAGE +8 -0
- data/lib/generators/hello/install/install_generator.rb +94 -0
- data/lib/generators/hello/install/templates/application.html.erb +35 -0
- data/lib/generators/hello/install/templates/hello_helper.rb +16 -0
- data/lib/generators/hello/install/templates/initializer.rb +24 -0
- data/lib/generators/hello/install/templates/models/concerns/user/authorization.rb +21 -0
- data/lib/generators/hello/install/templates/models/user.rb +9 -0
- data/lib/generators/hello/install/templates/onboarding/index.html.erb +5 -0
- data/lib/generators/hello/install/templates/onboarding/onboarding_controller.rb +33 -0
- data/lib/generators/hello/install/templates/root/index.html.erb +7 -0
- data/lib/generators/hello/install/templates/root/root_controller.rb +6 -0
- data/lib/generators/hello/install/templates/users/controllers/users_controller.rb +71 -0
- data/lib/generators/hello/install/templates/users/views/users/index.html.erb +29 -0
- data/lib/generators/hello/install/templates/users/views/users/list.html.erb +35 -0
- data/lib/generators/hello/install/templates/users/views/users/new.html.erb +60 -0
- data/lib/generators/hello/install/templates/users/views/users/show.html.erb +74 -0
- data/lib/generators/hello/locales/USAGE +12 -0
- data/lib/generators/hello/locales/locales_generator.rb +64 -0
- data/lib/generators/hello/views/USAGE +8 -0
- data/lib/generators/hello/views/views_generator.rb +9 -0
- data/lib/hello-rails.rb +1 -0
- data/lib/hello.rb +36 -0
- data/lib/hello/CHANGES.md +26 -0
- data/lib/hello/business.rb +47 -0
- data/lib/hello/business/authentication/sign_in.rb +92 -0
- data/lib/hello/business/authentication/sign_out.rb +8 -0
- data/lib/hello/business/authentication/sudo_mode_authentication.rb +25 -0
- data/lib/hello/business/authentication/sudo_mode_expiration.rb +17 -0
- data/lib/hello/business/base.rb +33 -0
- data/lib/hello/business/internationalization/update_locale.rb +33 -0
- data/lib/hello/business/management/add_email.rb +19 -0
- data/lib/hello/business/management/cancel_account.rb +22 -0
- data/lib/hello/business/management/confirm_email.rb +36 -0
- data/lib/hello/business/management/forgot_password.rb +47 -0
- data/lib/hello/business/management/remove_email.rb +19 -0
- data/lib/hello/business/management/reset_password.rb +34 -0
- data/lib/hello/business/management/send_confirmation_email.rb +40 -0
- data/lib/hello/business/management/unlink_access.rb +8 -0
- data/lib/hello/business/management/update_profile.rb +44 -0
- data/lib/hello/business/registration/sign_up.rb +159 -0
- data/lib/hello/configuration.rb +12 -0
- data/lib/hello/encryptors.rb +6 -0
- data/lib/hello/encryptors/complex.rb +25 -0
- data/lib/hello/encryptors/simple.rb +27 -0
- data/lib/hello/engine.rb +23 -0
- data/lib/hello/errors.rb +12 -0
- data/lib/hello/locales.rb +238 -0
- data/lib/hello/middleware.rb +13 -0
- data/lib/hello/rails_active_record.rb +10 -0
- data/lib/hello/rails_active_record/access.rb +65 -0
- data/lib/hello/rails_active_record/credential.rb +51 -0
- data/lib/hello/rails_active_record/email_credential.rb +60 -0
- data/lib/hello/rails_active_record/password_credential.rb +70 -0
- data/lib/hello/rails_active_record/user.rb +99 -0
- data/lib/hello/rails_controller.rb +124 -0
- data/lib/hello/rails_controller/restrict_by_role.rb +79 -0
- data/lib/hello/rails_helper.rb +35 -0
- data/lib/hello/request_manager.rb +14 -0
- data/lib/hello/request_manager/abstract.rb +77 -0
- data/lib/hello/request_manager/factory.rb +32 -0
- data/lib/hello/request_manager/stateful.rb +53 -0
- data/lib/hello/request_manager/stateful/finder.rb +58 -0
- data/lib/hello/request_manager/stateful/session_wrapper.rb +37 -0
- data/lib/hello/request_manager/stateless.rb +35 -0
- data/lib/hello/time_zones.rb +7 -0
- data/lib/hello/utils.rb +11 -0
- data/lib/hello/utils/device_name.rb +34 -0
- data/lib/hello/version.rb +4 -0
- data/lib/tasks/hello_tasks.rake +4 -0
- data/spec/bdd/hello/authentication/authorization/authorization_role_restriction_spec.rb +291 -0
- data/spec/bdd/hello/authentication/authorization/authorization_router_constraints_spec.rb +41 -0
- data/spec/bdd/hello/authentication/authorization/authorization_sensitive_restriction_spec.rb +84 -0
- data/spec/bdd/hello/authentication/authorization/bdd.yml +1 -0
- data/spec/bdd/hello/authentication/bdd.yml +1 -0
- data/spec/bdd/hello/authentication/classic_sign_in_spec.rb +264 -0
- data/spec/bdd/hello/authentication/manage_sessions_spec.rb +292 -0
- data/spec/bdd/hello/authentication/sign_out_spec.rb +159 -0
- data/spec/bdd/hello/bdd.yml +1 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/bdd.yml +1 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_locale_page_spec.rb +90 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_profile_page_spec.rb +64 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_sign_in_form_spec.rb +31 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_locale/change_locale_on_the_sign_up_form_spec.rb +34 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/bdd.yml +1 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_profile_page_spec.rb +14 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_sign_in_form_spec.rb +14 -0
- data/spec/bdd/hello/internalionalization/anyone_can_change_their_timezone/change_timezone_on_the_sign_up_form_spec.rb +14 -0
- data/spec/bdd/hello/internalionalization/bdd.yml +1 -0
- data/spec/bdd/hello/management/bdd.yml +1 -0
- data/spec/bdd/hello/management/cancel_account_spec.rb +128 -0
- data/spec/bdd/hello/management/manage_email_credentials/bdd.yml +1 -0
- data/spec/bdd/hello/management/manage_email_credentials/manage_email_credentials_emails_api_spec.rb +7 -0
- data/spec/bdd/hello/management/manage_email_credentials/manage_email_credentials_emails_page_spec.rb +252 -0
- data/spec/bdd/hello/management/manage_password_credentials/bdd.yml +1 -0
- data/spec/bdd/hello/management/manage_password_credentials/manage_password_forgot_password_spec.rb +68 -0
- data/spec/bdd/hello/management/manage_password_credentials/manage_password_page_spec.rb +60 -0
- data/spec/bdd/hello/management/manage_password_credentials/manage_password_reset_password_spec.rb +145 -0
- data/spec/bdd/hello/management/manage_profile/bdd.yml +1 -0
- data/spec/bdd/hello/management/manage_profile/manage_profile_api_spec.rb +7 -0
- data/spec/bdd/hello/management/manage_profile/manage_profile_page_spec.rb +65 -0
- data/spec/bdd/hello/management/manage_social_credentials/bdd.yml +1 -0
- data/spec/bdd/hello/management/manage_social_credentials/manage_social_credentials_pending_spec.rb +7 -0
- data/spec/bdd/hello/management/unlink_sessions_spec.rb +59 -0
- data/spec/bdd/hello/other/bdd.yml +1 -0
- data/spec/bdd/hello/other/create_user_spec.rb +70 -0
- data/spec/bdd/hello/other/impersonate_user_spec.rb +58 -0
- data/spec/bdd/hello/other/list_users_spec.rb +86 -0
- data/spec/bdd/hello/registration/bdd.yml +1 -0
- data/spec/bdd/hello/registration/classic_sign_up_spec.rb +228 -0
- data/spec/bdd/hello/registration/onboarding_process_spec.rb +101 -0
- data/spec/bdd/hello/support.rb +62 -0
- data/spec/business/hello/authentication/sign_in_spec.rb +72 -0
- data/spec/business/hello/registration/sign_up_spec.rb +258 -0
- data/spec/controllers/authentication_spec.rb +97 -0
- data/spec/controllers/localization_spec.rb +65 -0
- data/spec/controllers/request_can_carry_an_access_token_spec.rb +223 -0
- data/spec/fixtures/hello/password_mailer/confirmation +3 -0
- data/spec/fixtures/hello/password_mailer/forgot +3 -0
- data/spec/fixtures/hello/password_mailer/sign_up +3 -0
- data/spec/mailers/hello/mailer_spec.rb +53 -0
- data/spec/models/access_spec.rb +19 -0
- data/spec/models/credential_spec.rb +9 -0
- data/spec/models/email_credential_spec.rb +163 -0
- data/spec/models/hello/sign_up_model_spec.rb +64 -0
- data/spec/models/password_credential_spec.rb +75 -0
- data/spec/models/user_spec.rb +93 -0
- data/spec/others/configuration_spec.rb +25 -0
- data/spec/others/encryptors/complex_spec.rb +26 -0
- data/spec/others/encryptors/simple_spec.rb +21 -0
- data/spec/others/helper_spec.rb +10 -0
- data/spec/others/localization_consistency_spec.rb +73 -0
- data/spec/requests/forgot_password_spec.rb +36 -0
- data/spec/requests/reset_password_spec.rb +7 -0
- data/spec/requests/security/user_spec.rb +19 -0
- data/spec/routing/hello/accesses_routing_spec.rb +17 -0
- data/spec/routing/hello/emails_routing_spec.rb +37 -0
- data/spec/routing/hello/locale_routing_spec.rb +17 -0
- data/spec/routing/hello/profile_routing_spec.rb +29 -0
- data/spec/routing/hello/registration_routing_spec.rb +23 -0
- data/spec/routing/hello/sign_out_routing_spec.rb +11 -0
- data/spec/routing/hello/sudo_mode_routing_spec.rb +23 -0
- data/spec/routing/hello/users_routing_spec.rb +15 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/spec_helper/codeclimate.rb +2 -0
- data/spec/spec_helper/configure_rspec.rb +23 -0
- data/spec/spec_helper/create_database.rb +5 -0
- data/spec/spec_helper/dummy_and_test_dependencies.rb +17 -0
- data/spec/spec_helper/support.rb +1 -0
- data/spec/support/factories.rb +60 -0
- data/spec/support/feature_injection.rb +118 -0
- data/spec/support/features/feature_support_given.rb +46 -0
- data/spec/support/features/feature_support_then.rb +43 -0
- data/spec/support/helpers/aliases.rb +76 -0
- data/spec/support/helpers/configuration.rb +6 -0
- data/spec/support/helpers/current.rb +16 -0
- data/spec/support/helpers/expect.rb +61 -0
- data/spec/support/helpers/given.rb +49 -0
- data/spec/support/helpers/shortcuts.rb +24 -0
- data/spec/support/helpers/then.rb +29 -0
- data/spec/support/helpers/when.rb +108 -0
- data/spec/support/requests/request_support.rb +8 -0
- data/spec/utils/device_name_spec.rb +228 -0
- metadata +562 -11
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateCredentials < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :credentials do |t|
|
4
|
+
t.references :user, index: true
|
5
|
+
t.string :type
|
6
|
+
|
7
|
+
t.string :email
|
8
|
+
t.string :digest
|
9
|
+
|
10
|
+
t.datetime :confirmed_at
|
11
|
+
t.string :verifying_token_digest
|
12
|
+
t.datetime :verifying_token_digested_at
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateAccesses < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :accesses do |t|
|
4
|
+
t.references :user, index: true
|
5
|
+
t.string :user_agent_string
|
6
|
+
t.string :token
|
7
|
+
t.string :ip
|
8
|
+
t.datetime :expires_at, default: DateTime.new(2000, 1, 1)
|
9
|
+
t.datetime :sudo_expires_at, default: DateTime.new(2000, 1, 1)
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
t.index :token
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
must_create_user_table = !table_exists?(:users)
|
4
|
+
create_table(:users, &:timestamps) if must_create_user_table
|
5
|
+
|
6
|
+
add_users_column_safe :name, :string
|
7
|
+
|
8
|
+
add_users_column_safe :role, :string
|
9
|
+
add_users_column_safe :locale, :string
|
10
|
+
add_users_column_safe :time_zone, :string
|
11
|
+
add_users_column_safe :username, :string
|
12
|
+
|
13
|
+
add_users_column_safe :credentials_count, :integer, default: 0
|
14
|
+
add_users_column_safe :accesses_count, :integer, default: 0
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def add_users_column_safe(column_name, type, options = {})
|
20
|
+
return if column_exists?(:users, column_name)
|
21
|
+
add_column(:users, column_name, type, options)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Hello::ConcernsGenerator < Rails::Generators::Base
|
2
|
+
# source_root File.expand_path('../templates', __FILE__)
|
3
|
+
source_root File.expand_path('../../../../../', __FILE__)
|
4
|
+
|
5
|
+
def copy_the_controller_concerns
|
6
|
+
directory 'app/controllers/hello/concerns'
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
class Hello::FromDeviseGenerator < ActiveRecord::Generators::Base
|
4
|
+
# ActiveRecord::Generators::Base inherits from Rails::Generators::NamedBase which requires a NAME parameter for the
|
5
|
+
# new table name. Our generator doesn't need it.
|
6
|
+
argument :name, type: :string, default: 'not-needed'
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
def create_the_migration
|
11
|
+
migration_template 'from_devise.migration.rb', 'db/migrate/from_devise.hello.rb'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# customize this migration if you need, PRs accepted
|
2
|
+
class FromDevise < ActiveRecord::Migration
|
3
|
+
def up
|
4
|
+
from_users_to_credentials
|
5
|
+
remove_devise_columns
|
6
|
+
end
|
7
|
+
|
8
|
+
def down
|
9
|
+
fail "you can't roll this back, use a backup"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def from_users_to_credentials
|
15
|
+
puts "before Credential.count (#{Credential.count.to_s.red})"
|
16
|
+
User.find_each do |user|
|
17
|
+
puts "starting User ##{user.id} #{user.email}"
|
18
|
+
username = extract_username(user)
|
19
|
+
credential_fields = { email: user.email, username: username, password: Hello::Encryptors::Simple.instance.single }
|
20
|
+
user.email_credentials.create!(credential_fields)
|
21
|
+
end
|
22
|
+
puts "after Credential.count (#{Credential.count.to_s.green})"
|
23
|
+
end
|
24
|
+
|
25
|
+
def extract_username(user)
|
26
|
+
username = user.try(:username).to_s
|
27
|
+
username = username.gsub('.', '_dot_')
|
28
|
+
end
|
29
|
+
|
30
|
+
def remove_devise_columns
|
31
|
+
columns = [:username, :encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at]
|
32
|
+
columns.each { |column_name| remove_users_column_safe(column_name) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove_users_column_safe(column_name)
|
36
|
+
return unless column_exists?(:users, column_name)
|
37
|
+
remove_column(:users, column_name)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
class Hello::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def copy_the_initializer
|
5
|
+
copy_file 'initializer.rb', 'config/initializers/hello.rb'
|
6
|
+
end
|
7
|
+
|
8
|
+
def locale_fix
|
9
|
+
gsub_file 'config/locales/en.yml', 'hello: "Hello world"', 'hello_world: "Hello world"'
|
10
|
+
rescue Errno::ENOENT
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_helper
|
14
|
+
copy_file 'hello_helper.rb', 'app/helpers/hello_helper.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
# a root route is needed
|
18
|
+
# we were previously redirecting to /hello which caused a redirection loop bug
|
19
|
+
def generate_root
|
20
|
+
my_route "root to: 'root#index'"
|
21
|
+
copy_file 'root/root_controller.rb', 'app/controllers/root_controller.rb'
|
22
|
+
copy_file 'root/index.html.erb', 'app/views/root/index.html.erb'
|
23
|
+
end
|
24
|
+
|
25
|
+
def append_to_the_routes
|
26
|
+
my_route 'mount Hello::Engine => "/hello"'
|
27
|
+
my_route "get '/hello/sign_out' => 'hello/authentication/sessions#sign_out'"
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_the_migrations
|
31
|
+
rake 'hello:install:migrations'
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_layout_file
|
35
|
+
destination = 'app/views/layouts/application.html.erb'
|
36
|
+
|
37
|
+
answer = ask('Replace application.html.erb automatically? [Yn]')
|
38
|
+
answer_yes = answer.blank? || answer.downcase.starts_with?('y')
|
39
|
+
|
40
|
+
if answer_yes
|
41
|
+
copy_file 'application.html.erb', 'app/views/layouts/application.html.erb'
|
42
|
+
else
|
43
|
+
the_template_path = File.expand_path('../templates', __FILE__)
|
44
|
+
app_erb_path = File.join(the_template_path, 'application.html.erb')
|
45
|
+
content = open(app_erb_path).read
|
46
|
+
puts ('-' * 100).light_yellow
|
47
|
+
puts ' We recommend you add these elements to your application.html.erb file'.light_yellow
|
48
|
+
puts ('-' * 100).light_yellow
|
49
|
+
puts content.light_green.on_black.bold
|
50
|
+
puts ('-' * 100).light_yellow
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_models
|
55
|
+
directory 'models', 'app/models'
|
56
|
+
end
|
57
|
+
|
58
|
+
def generate_profile
|
59
|
+
my_route %(
|
60
|
+
resources :users, only: [:index, :show, :new, :create] do
|
61
|
+
collection do
|
62
|
+
get 'list'
|
63
|
+
end
|
64
|
+
member do
|
65
|
+
post 'impersonate'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
)
|
69
|
+
directory 'users/controllers', 'app/controllers'
|
70
|
+
directory 'users/views', 'app/views'
|
71
|
+
end
|
72
|
+
|
73
|
+
def generate_onboarding
|
74
|
+
my_route %(
|
75
|
+
get 'onboarding' => 'onboarding#index'
|
76
|
+
post 'onboarding' => 'onboarding#continue'
|
77
|
+
)
|
78
|
+
copy_file 'onboarding/onboarding_controller.rb', 'app/controllers/onboarding_controller.rb'
|
79
|
+
copy_file 'onboarding/index.html.erb', 'app/views/onboarding/index.html.erb'
|
80
|
+
end
|
81
|
+
|
82
|
+
# hook_for :test_framework
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
86
|
+
def my_route(routing_code)
|
87
|
+
log :route, routing_code
|
88
|
+
sentinel = /\.routes\.draw do\s*$/
|
89
|
+
|
90
|
+
in_root do
|
91
|
+
inject_into_file 'config/routes.rb', "\n #{routing_code}", after: sentinel, verbose: false, force: false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Hello</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<!-- Latest compiled and minified CSS -->
|
12
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
|
13
|
+
<!-- Optional theme -->
|
14
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
|
15
|
+
<!-- Latest compiled and minified JavaScript -->
|
16
|
+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
|
17
|
+
|
18
|
+
<div class="container">
|
19
|
+
<div class="header">
|
20
|
+
<%= render "/hello/shared/nav_pills" %>
|
21
|
+
|
22
|
+
<h3 class="text-muted"><a href="/">Project name</a></h3>
|
23
|
+
<p class="lead">Hello, <%= current_user && current_user.name || "Guest" %>!</p>
|
24
|
+
|
25
|
+
<%= render "/hello/shared/session_expiration" %>
|
26
|
+
</div>
|
27
|
+
|
28
|
+
<%= render "/hello/shared/flash" %>
|
29
|
+
|
30
|
+
<%= yield %>
|
31
|
+
|
32
|
+
</div>
|
33
|
+
|
34
|
+
</body>
|
35
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module HelloHelper
|
2
|
+
|
3
|
+
# Please take one of two actions
|
4
|
+
# 1. Add gem 'nav_lynx' to your Gemfile and remove this file
|
5
|
+
# 2. edit partial 'views/hello/shared/_settings' and replace `nav_link_to` for `link_to`
|
6
|
+
def nav_link_to(*args)
|
7
|
+
if defined?(NavLYNX)
|
8
|
+
super
|
9
|
+
else
|
10
|
+
puts "#{__FILE__}"
|
11
|
+
args.pop
|
12
|
+
link_to(*args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Hello.configure do |config|
|
2
|
+
config.mailer_sender = 'hello@example.com'
|
3
|
+
|
4
|
+
config.email_presence = true
|
5
|
+
config.email_regex = /\A[A-Z0-9._-]+@[A-Z0-9.-]+\.[A-Z0-9.-]+\z/i
|
6
|
+
config.email_length = 4..250
|
7
|
+
|
8
|
+
config.username_presence = true
|
9
|
+
config.username_regex = /\A[a-z0-9_-]+\z/i
|
10
|
+
config.username_length = 4..32
|
11
|
+
|
12
|
+
config.password_presence = true
|
13
|
+
config.password_regex = /\A[a-z0-9]+\z/i
|
14
|
+
config.password_length = 4..250
|
15
|
+
|
16
|
+
config.sign_up_disabled = false # {reason: "standard maintenance", until: "3PM"}
|
17
|
+
config.sign_up_fields = %w(username time_zone locale name)
|
18
|
+
|
19
|
+
config.locales = %w(en es fr pl pt-BR zh-CN)
|
20
|
+
config.time_zones = Hello::TimeZones.all
|
21
|
+
|
22
|
+
config.sudo_expires_in = 10.minutes
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class User < Hello::RailsActiveRecord::User
|
2
|
+
module Authorization
|
3
|
+
|
4
|
+
def guest?
|
5
|
+
%w(guest).include?(role)
|
6
|
+
end
|
7
|
+
|
8
|
+
def onboarding?
|
9
|
+
%w(onboarding).include?(role)
|
10
|
+
end
|
11
|
+
|
12
|
+
def user?
|
13
|
+
%w(user webmaster).include?(role)
|
14
|
+
end
|
15
|
+
|
16
|
+
def webmaster?
|
17
|
+
%w(webmaster).include?(role)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class OnboardingController < ApplicationController
|
2
|
+
dont_kick :onboarding
|
3
|
+
|
4
|
+
def index
|
5
|
+
end
|
6
|
+
|
7
|
+
def continue
|
8
|
+
respond_to do |format|
|
9
|
+
if update(params[:role])
|
10
|
+
format.html { redirect_to root_path, notice: 'Welcome!' }
|
11
|
+
format.json { render json: { user: current_user.as_json_web_api }, status: :ok }
|
12
|
+
else
|
13
|
+
format.html { render action: 'index' }
|
14
|
+
format.json { render json: { errors: 'invalid role supplied' }, status: :unprocessable_entity }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def update(role)
|
22
|
+
case role
|
23
|
+
when 'user'
|
24
|
+
current_user.update! role: 'user'
|
25
|
+
return true
|
26
|
+
when 'webmaster'
|
27
|
+
current_user.update! role: 'webmaster'
|
28
|
+
return true
|
29
|
+
else
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class UsersController < ApplicationController
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# any role
|
6
|
+
#
|
7
|
+
|
8
|
+
before_action :find_user, only: [:show, :impersonate]
|
9
|
+
|
10
|
+
# GET /users
|
11
|
+
def index
|
12
|
+
@users = User.order(:id)
|
13
|
+
@count = User.count
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /users/username
|
17
|
+
# GET /users/id -> redirects to /users/username
|
18
|
+
def show
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
#
|
23
|
+
#
|
24
|
+
# webmaster role
|
25
|
+
#
|
26
|
+
|
27
|
+
dont_kick :webmaster, only: [:list, :new, :create, :impersonate]
|
28
|
+
sudo_mode only: [:list, :new, :create, :impersonate]
|
29
|
+
before_action :init_user, only: [:new, :create]
|
30
|
+
|
31
|
+
# GET /users/list
|
32
|
+
def list
|
33
|
+
@users = User.order(:id)
|
34
|
+
@count = User.count
|
35
|
+
end
|
36
|
+
|
37
|
+
# GET /users/new
|
38
|
+
def new
|
39
|
+
@starting_role = 'onboarding'
|
40
|
+
end
|
41
|
+
|
42
|
+
# POST /users
|
43
|
+
def create
|
44
|
+
if @user.register(params.require(:user))
|
45
|
+
@user.user.update!(role: params[:role])
|
46
|
+
redirect_to new_user_path, notice: t('hello.business.registration.sign_up.success')
|
47
|
+
else
|
48
|
+
@starting_role = params[:role]
|
49
|
+
render action: :new
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# POST /users/1/impersonate
|
54
|
+
def impersonate
|
55
|
+
sign_in!(@user, 60.minutes.from_now, 60.minutes.from_now)
|
56
|
+
|
57
|
+
redirect_to root_path, notice: t('hello.business.authentication.sign_in.success')
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def find_user
|
63
|
+
@user = User.find_by_username!(params[:id])
|
64
|
+
rescue ActiveRecord::RecordNotFound
|
65
|
+
redirect_to User.find_by_id!(params[:id]) # forces redirect to path with username if used id on URL
|
66
|
+
end
|
67
|
+
|
68
|
+
def init_user
|
69
|
+
@user = Hello::ClassicSignUpEntity.new
|
70
|
+
end
|
71
|
+
end
|