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,25 @@
|
|
1
|
+
module Hello
|
2
|
+
module Encryptors
|
3
|
+
class Complex < Simple
|
4
|
+
def initialize(cost=nil)
|
5
|
+
require 'bcrypt'
|
6
|
+
cost ||= Rails.env.test? ? 1 : 10
|
7
|
+
BCrypt::Engine.cost = cost
|
8
|
+
rescue LoadError
|
9
|
+
s = "your Gemfile needs: gem 'bcrypt'"
|
10
|
+
puts [s.red, s.yellow, s.green]
|
11
|
+
raise
|
12
|
+
end
|
13
|
+
|
14
|
+
def encrypt(string)
|
15
|
+
BCrypt::Password.create(string).to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def match(string, digest)
|
19
|
+
BCrypt::Password.new(digest) == string
|
20
|
+
rescue BCrypt::Errors::InvalidHash
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Hello
|
4
|
+
module Encryptors
|
5
|
+
class Simple
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
# probability = 1 / ((8*2) ** (8*2))
|
9
|
+
def single(complexity = 8)
|
10
|
+
SecureRandom.hex(complexity)
|
11
|
+
end
|
12
|
+
|
13
|
+
def pair(complexity = 8)
|
14
|
+
s = single(complexity)
|
15
|
+
[s, encrypt(s)]
|
16
|
+
end
|
17
|
+
|
18
|
+
def encrypt(s)
|
19
|
+
Digest::MD5.hexdigest(s)
|
20
|
+
end
|
21
|
+
|
22
|
+
def match(string, token)
|
23
|
+
encrypt(string) == token
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/hello/engine.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Hello
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
isolate_namespace Hello
|
4
|
+
|
5
|
+
config.hello = nil
|
6
|
+
|
7
|
+
initializer 'hello.filter' do |app|
|
8
|
+
app.config.filter_parameters += [:password, :token]
|
9
|
+
end
|
10
|
+
|
11
|
+
initializer 'hello.add_middleware' do |app|
|
12
|
+
app.config.app_middleware.use Hello::Middleware
|
13
|
+
end
|
14
|
+
|
15
|
+
config.generators do |g|
|
16
|
+
g.test_framework :rspec, view_specs: false,
|
17
|
+
controller_specs: false
|
18
|
+
# g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
19
|
+
g.assets false
|
20
|
+
g.helper false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/hello/errors.rb
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
module Hello
|
2
|
+
module Locales
|
3
|
+
ALL = {
|
4
|
+
'af' => 'Afrikaans',
|
5
|
+
'af-ZA' => 'Afrikaans (South Africa)',
|
6
|
+
'ar' => 'Arabic',
|
7
|
+
'ar-AE' => 'Arabic (U.A.E.)',
|
8
|
+
'ar-BH' => 'Arabic (Bahrain)',
|
9
|
+
'ar-DZ' => 'Arabic (Algeria)',
|
10
|
+
'ar-EG' => 'Arabic (Egypt)',
|
11
|
+
'ar-IQ' => 'Arabic (Iraq)',
|
12
|
+
'ar-JO' => 'Arabic (Jordan)',
|
13
|
+
'ar-KW' => 'Arabic (Kuwait)',
|
14
|
+
'ar-LB' => 'Arabic (Lebanon)',
|
15
|
+
'ar-LY' => 'Arabic (Libya)',
|
16
|
+
'ar-MA' => 'Arabic (Morocco)',
|
17
|
+
'ar-OM' => 'Arabic (Oman)',
|
18
|
+
'ar-QA' => 'Arabic (Qatar)',
|
19
|
+
'ar-SA' => 'Arabic (Saudi Arabia)',
|
20
|
+
'ar-SY' => 'Arabic (Syria)',
|
21
|
+
'ar-TN' => 'Arabic (Tunisia)',
|
22
|
+
'ar-YE' => 'Arabic (Yemen)',
|
23
|
+
'az' => 'Azeri (Latin)',
|
24
|
+
'az-AZ' => 'Azeri (Cyrillic) (Azerbaijan)',
|
25
|
+
'be' => 'Belarusian',
|
26
|
+
'be-BY' => 'Belarusian (Belarus)',
|
27
|
+
'bg' => 'Bulgarian',
|
28
|
+
'bg-BG' => 'Bulgarian (Bulgaria)',
|
29
|
+
'bs-BA' => 'Bosnian (Bosnia and Herzegovina)',
|
30
|
+
'ca' => 'Catalan',
|
31
|
+
'ca-ES' => 'Catalan (Spain)',
|
32
|
+
'cs' => 'Czech',
|
33
|
+
'cs-CZ' => 'Czech (Czech Republic)',
|
34
|
+
'cy' => 'Welsh',
|
35
|
+
'cy-GB' => 'Welsh (United Kingdom)',
|
36
|
+
'da' => 'Danish',
|
37
|
+
'da-DK' => 'Danish (Denmark)',
|
38
|
+
'de' => 'German',
|
39
|
+
'de-AT' => 'German (Austria)',
|
40
|
+
'de-CH' => 'German (Switzerland)',
|
41
|
+
'de-DE' => 'German (Germany)',
|
42
|
+
'de-LI' => 'German (Liechtenstein)',
|
43
|
+
'de-LU' => 'German (Luxembourg)',
|
44
|
+
'dv' => 'Divehi',
|
45
|
+
'dv-MV' => 'Divehi (Maldives)',
|
46
|
+
'el' => 'Greek',
|
47
|
+
'el-GR' => 'Greek (Greece)',
|
48
|
+
'en' => 'English',
|
49
|
+
'en-AU' => 'English (Australia)',
|
50
|
+
'en-BZ' => 'English (Belize)',
|
51
|
+
'en-CA' => 'English (Canada)',
|
52
|
+
'en-CB' => 'English (Caribbean)',
|
53
|
+
'en-GB' => 'English (United Kingdom)',
|
54
|
+
'en-IE' => 'English (Ireland)',
|
55
|
+
'en-JM' => 'English (Jamaica)',
|
56
|
+
'en-NZ' => 'English (New Zealand)',
|
57
|
+
'en-PH' => 'English (Republic of the Philippines)',
|
58
|
+
'en-TT' => 'English (Trinidad and Tobago)',
|
59
|
+
'en-US' => 'English (United States)',
|
60
|
+
'en-ZA' => 'English (South Africa)',
|
61
|
+
'en-ZW' => 'English (Zimbabwe)',
|
62
|
+
'eo' => 'Esperanto',
|
63
|
+
'es' => 'Spanish',
|
64
|
+
'es-AR' => 'Spanish (Argentina)',
|
65
|
+
'es-BO' => 'Spanish (Bolivia)',
|
66
|
+
'es-CL' => 'Spanish (Chile)',
|
67
|
+
'es-CO' => 'Spanish (Colombia)',
|
68
|
+
'es-CR' => 'Spanish (Costa Rica)',
|
69
|
+
'es-DO' => 'Spanish (Dominican Republic)',
|
70
|
+
'es-EC' => 'Spanish (Ecuador)',
|
71
|
+
'es-ES' => 'Spanish (Spain)',
|
72
|
+
'es-GT' => 'Spanish (Guatemala)',
|
73
|
+
'es-HN' => 'Spanish (Honduras)',
|
74
|
+
'es-MX' => 'Spanish (Mexico)',
|
75
|
+
'es-NI' => 'Spanish (Nicaragua)',
|
76
|
+
'es-PA' => 'Spanish (Panama)',
|
77
|
+
'es-PE' => 'Spanish (Peru)',
|
78
|
+
'es-PR' => 'Spanish (Puerto Rico)',
|
79
|
+
'es-PY' => 'Spanish (Paraguay)',
|
80
|
+
'es-SV' => 'Spanish (El Salvador)',
|
81
|
+
'es-UY' => 'Spanish (Uruguay)',
|
82
|
+
'es-VE' => 'Spanish (Venezuela)',
|
83
|
+
'et' => 'Estonian',
|
84
|
+
'et-EE' => 'Estonian (Estonia)',
|
85
|
+
'eu' => 'Basque',
|
86
|
+
'eu-ES' => 'Basque (Spain)',
|
87
|
+
'fa' => 'Farsi',
|
88
|
+
'fa-IR' => 'Farsi (Iran)',
|
89
|
+
'fi' => 'Finnish',
|
90
|
+
'fi-FI' => 'Finnish (Finland)',
|
91
|
+
'fo' => 'Faroese',
|
92
|
+
'fo-FO' => 'Faroese (Faroe Islands)',
|
93
|
+
'fr' => 'French',
|
94
|
+
'fr-BE' => 'French (Belgium)',
|
95
|
+
'fr-CA' => 'French (Canada)',
|
96
|
+
'fr-CH' => 'French (Switzerland)',
|
97
|
+
'fr-FR' => 'French (France)',
|
98
|
+
'fr-LU' => 'French (Luxembourg)',
|
99
|
+
'fr-MC' => 'French (Principality of Monaco)',
|
100
|
+
'gl' => 'Galician',
|
101
|
+
'gl-ES' => 'Galician (Spain)',
|
102
|
+
'gu' => 'Gujarati',
|
103
|
+
'gu-IN' => 'Gujarati (India)',
|
104
|
+
'he' => 'Hebrew',
|
105
|
+
'he-IL' => 'Hebrew (Israel)',
|
106
|
+
'hi' => 'Hindi',
|
107
|
+
'hi-IN' => 'Hindi (India)',
|
108
|
+
'hr' => 'Croatian',
|
109
|
+
'hr-BA' => 'Croatian (Bosnia and Herzegovina)',
|
110
|
+
'hr-HR' => 'Croatian (Croatia)',
|
111
|
+
'hu' => 'Hungarian',
|
112
|
+
'hu-HU' => 'Hungarian (Hungary)',
|
113
|
+
'hy' => 'Armenian',
|
114
|
+
'hy-AM' => 'Armenian (Armenia)',
|
115
|
+
'id' => 'Indonesian',
|
116
|
+
'id-ID' => 'Indonesian (Indonesia)',
|
117
|
+
'is' => 'Icelandic',
|
118
|
+
'is-IS' => 'Icelandic (Iceland)',
|
119
|
+
'it' => 'Italian',
|
120
|
+
'it-CH' => 'Italian (Switzerland)',
|
121
|
+
'it-IT' => 'Italian (Italy)',
|
122
|
+
'ja' => 'Japanese',
|
123
|
+
'ja-JP' => 'Japanese (Japan)',
|
124
|
+
'ka' => 'Georgian',
|
125
|
+
'ka-GE' => 'Georgian (Georgia)',
|
126
|
+
'kk' => 'Kazakh',
|
127
|
+
'kk-KZ' => 'Kazakh (Kazakhstan)',
|
128
|
+
'kn' => 'Kannada',
|
129
|
+
'kn-IN' => 'Kannada (India)',
|
130
|
+
'ko' => 'Korean',
|
131
|
+
'ko-KR' => 'Korean (Korea)',
|
132
|
+
'kok' => 'Konkani',
|
133
|
+
'kok-IN' => 'Konkani (India)',
|
134
|
+
'ky' => 'Kyrgyz',
|
135
|
+
'ky-KG' => 'Kyrgyz (Kyrgyzstan)',
|
136
|
+
'lt' => 'Lithuanian',
|
137
|
+
'lt-LT' => 'Lithuanian (Lithuania)',
|
138
|
+
'lv' => 'Latvian',
|
139
|
+
'lv-LV' => 'Latvian (Latvia)',
|
140
|
+
'mi' => 'Maori',
|
141
|
+
'mi-NZ' => 'Maori (New Zealand)',
|
142
|
+
'mk' => 'FYRO Macedonian',
|
143
|
+
'mk-MK' => 'FYRO Macedonian (Former Yugoslav Republic of Macedonia)',
|
144
|
+
'mn' => 'Mongolian',
|
145
|
+
'mn-MN' => 'Mongolian (Mongolia)',
|
146
|
+
'mr' => 'Marathi',
|
147
|
+
'mr-IN' => 'Marathi (India)',
|
148
|
+
'ms' => 'Malay',
|
149
|
+
'ms-BN' => 'Malay (Brunei Darussalam)',
|
150
|
+
'ms-MY' => 'Malay (Malaysia)',
|
151
|
+
'mt' => 'Maltese',
|
152
|
+
'mt-MT' => 'Maltese (Malta)',
|
153
|
+
'nb' => 'Norwegian (Bokm?l)',
|
154
|
+
'nb-NO' => 'Norwegian (Bokm?l) (Norway)',
|
155
|
+
'nl' => 'Dutch',
|
156
|
+
'nl-BE' => 'Dutch (Belgium)',
|
157
|
+
'nl-NL' => 'Dutch (Netherlands)',
|
158
|
+
'nn-NO' => 'Norwegian (Nynorsk) (Norway)',
|
159
|
+
'ns' => 'Northern Sotho',
|
160
|
+
'ns-ZA' => 'Northern Sotho (South Africa)',
|
161
|
+
'pa' => 'Punjabi',
|
162
|
+
'pa-IN' => 'Punjabi (India)',
|
163
|
+
'pl' => 'Polish',
|
164
|
+
'pl-PL' => 'Polish (Poland)',
|
165
|
+
'ps' => 'Pashto',
|
166
|
+
'ps-AR' => 'Pashto (Afghanistan)',
|
167
|
+
'pt' => 'Portuguese',
|
168
|
+
'pt-BR' => 'Portuguese (Brazil)',
|
169
|
+
'pt-PT' => 'Portuguese (Portugal)',
|
170
|
+
'qu' => 'Quechua',
|
171
|
+
'qu-BO' => 'Quechua (Bolivia)',
|
172
|
+
'qu-EC' => 'Quechua (Ecuador)',
|
173
|
+
'qu-PE' => 'Quechua (Peru)',
|
174
|
+
'ro' => 'Romanian',
|
175
|
+
'ro-RO' => 'Romanian (Romania)',
|
176
|
+
'ru' => 'Russian',
|
177
|
+
'ru-RU' => 'Russian (Russia)',
|
178
|
+
'sa' => 'Sanskrit',
|
179
|
+
'sa-IN' => 'Sanskrit (India)',
|
180
|
+
'se' => 'Sami (Northern)',
|
181
|
+
'se-FI' => 'Sami (Northern) (Finland)',
|
182
|
+
'se-NO' => 'Sami (Northern) (Norway)',
|
183
|
+
'se-SE' => 'Sami (Lule) (Sweden)',
|
184
|
+
'sk' => 'Slovak',
|
185
|
+
'sk-SK' => 'Slovak (Slovakia)',
|
186
|
+
'sl' => 'Slovenian',
|
187
|
+
'sl-SI' => 'Slovenian (Slovenia)',
|
188
|
+
'sq' => 'Albanian',
|
189
|
+
'sq-AL' => 'Albanian (Albania)',
|
190
|
+
'sr-BA' => 'Serbian (Latin) (Bosnia and Herzegovina)',
|
191
|
+
'sr-SP' => 'Serbian (Latin) (Serbia and Montenegro)',
|
192
|
+
'sv' => 'Swedish',
|
193
|
+
'sv-FI' => 'Swedish (Finland)',
|
194
|
+
'sv-SE' => 'Swedish (Sweden)',
|
195
|
+
'sw' => 'Swahili',
|
196
|
+
'sw-KE' => 'Swahili (Kenya)',
|
197
|
+
'syr' => 'Syriac',
|
198
|
+
'syr-SY' => 'Syriac (Syria)',
|
199
|
+
'ta' => 'Tamil',
|
200
|
+
'ta-IN' => 'Tamil (India)',
|
201
|
+
'te' => 'Telugu',
|
202
|
+
'te-IN' => 'Telugu (India)',
|
203
|
+
'th' => 'Thai',
|
204
|
+
'th-TH' => 'Thai (Thailand)',
|
205
|
+
'tl' => 'Tagalog',
|
206
|
+
'tl-PH' => 'Tagalog (Philippines)',
|
207
|
+
'tn' => 'Tswana',
|
208
|
+
'tn-ZA' => 'Tswana (South Africa)',
|
209
|
+
'tr' => 'Turkish',
|
210
|
+
'tr-TR' => 'Turkish (Turkey)',
|
211
|
+
'tt' => 'Tatar',
|
212
|
+
'tt-RU' => 'Tatar (Russia)',
|
213
|
+
'ts' => 'Tsonga',
|
214
|
+
'uk' => 'Ukrainian',
|
215
|
+
'uk-UA' => 'Ukrainian (Ukraine)',
|
216
|
+
'ur' => 'Urdu',
|
217
|
+
'ur-PK' => 'Urdu (Islamic Republic of Pakistan)',
|
218
|
+
'uz' => 'Uzbek (Latin)',
|
219
|
+
'uz-UZ' => 'Uzbek (Cyrillic) (Uzbekistan)',
|
220
|
+
'vi' => 'Vietnamese',
|
221
|
+
'vi-VN' => 'Vietnamese (Viet Nam)',
|
222
|
+
'xh' => 'Xhosa',
|
223
|
+
'xh-ZA' => 'Xhosa (South Africa)',
|
224
|
+
'zh' => 'Chinese',
|
225
|
+
'zh-CN' => 'Chinese (S)',
|
226
|
+
'zh-HK' => 'Chinese (Hong Kong)',
|
227
|
+
'zh-MO' => 'Chinese (Macau)',
|
228
|
+
'zh-SG' => 'Chinese (Singapore)',
|
229
|
+
'zh-TW' => 'Chinese (T)',
|
230
|
+
'zu' => 'Zulu',
|
231
|
+
'zu-ZA' => 'Zulu (South Africa)'
|
232
|
+
}.freeze
|
233
|
+
|
234
|
+
def self.all
|
235
|
+
ALL
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Cannot be named ActiveRecord or will compete with ::ActiveRecord
|
2
|
+
module Hello
|
3
|
+
module RailsActiveRecord
|
4
|
+
autoload :User, 'hello/rails_active_record/user'
|
5
|
+
autoload :Credential, 'hello/rails_active_record/credential'
|
6
|
+
autoload :EmailCredential, 'hello/rails_active_record/email_credential'
|
7
|
+
autoload :PasswordCredential, 'hello/rails_active_record/password_credential'
|
8
|
+
autoload :Access, 'hello/rails_active_record/access'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Hello
|
2
|
+
module RailsActiveRecord
|
3
|
+
class Access < ::ActiveRecord::Base
|
4
|
+
self.table_name = 'accesses'
|
5
|
+
|
6
|
+
# ASSOCIATIONS
|
7
|
+
belongs_to :user, counter_cache: true, class_name: '::User'
|
8
|
+
|
9
|
+
# VALIDATIONS
|
10
|
+
validates_presence_of :user, :expires_at, :user_agent_string, :token
|
11
|
+
validates_uniqueness_of :token
|
12
|
+
|
13
|
+
before_validation on: :create do
|
14
|
+
self.token = "#{user_id}-#{Hello::Encryptors::Simple.instance.single(16)}"
|
15
|
+
end
|
16
|
+
|
17
|
+
# CUSTOM METHODS
|
18
|
+
|
19
|
+
def keep_alive!
|
20
|
+
renew! if expiring?
|
21
|
+
end
|
22
|
+
|
23
|
+
def full_device_name
|
24
|
+
Hello::Utils::DeviceName.instance.parse(user_agent_string)
|
25
|
+
end
|
26
|
+
|
27
|
+
def active_token_or_destroy
|
28
|
+
if expires_at.future?
|
29
|
+
token
|
30
|
+
else
|
31
|
+
destroy && (return nil)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def as_json_web_api
|
36
|
+
as_json.slice(*%w(expires_at token user_id)).merge({ user: user.as_json_web_api })
|
37
|
+
end
|
38
|
+
|
39
|
+
def sudo_expire!
|
40
|
+
update! sudo_expires_at: 1.second.ago
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def expiring?
|
46
|
+
expires_at < 20.minutes.from_now
|
47
|
+
end
|
48
|
+
|
49
|
+
def renew!
|
50
|
+
update_attributes!(expires_at: 30.minutes.from_now)
|
51
|
+
end
|
52
|
+
|
53
|
+
class << self
|
54
|
+
def destroy_all_expired
|
55
|
+
where('expires_at < ?', Time.now).destroy_all
|
56
|
+
true
|
57
|
+
end
|
58
|
+
|
59
|
+
def cached_destroy_all_expired
|
60
|
+
@@destroy_all_expired ||= destroy_all_expired
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Hello
|
2
|
+
module RailsActiveRecord
|
3
|
+
class Credential < ::ActiveRecord::Base
|
4
|
+
self.table_name = 'credentials'
|
5
|
+
|
6
|
+
# ASSOCIATIONS
|
7
|
+
belongs_to :user, counter_cache: true, class_name: '::User'
|
8
|
+
|
9
|
+
# VALIDATIONS
|
10
|
+
validates_presence_of :user, :type
|
11
|
+
validates_inclusion_of :type, in: %w(EmailCredential PasswordCredential)
|
12
|
+
|
13
|
+
# CUSTOM METHODS
|
14
|
+
|
15
|
+
# def is_email?
|
16
|
+
# is_a?(EmailCredential)
|
17
|
+
# end
|
18
|
+
|
19
|
+
def first_error_message
|
20
|
+
errors.messages.values.flatten.first if errors.any?
|
21
|
+
end
|
22
|
+
|
23
|
+
# verifying token
|
24
|
+
|
25
|
+
def verifying_token_is?(unencrypted_token)
|
26
|
+
digest = simple_encryptor.encrypt(unencrypted_token)
|
27
|
+
verifying_token_digest == digest
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset_verifying_token!
|
31
|
+
uuid, digest = simple_encryptor.pair
|
32
|
+
update!(verifying_token_digest: digest, verifying_token_digested_at: 1.second.ago)
|
33
|
+
uuid
|
34
|
+
end
|
35
|
+
|
36
|
+
def invalidate_verifying_token!
|
37
|
+
update(verifying_token_digest: nil, verifying_token_digested_at: nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def hello_is_user_being_destroyed?
|
43
|
+
!!Thread.current['Hello.destroying_user']
|
44
|
+
end
|
45
|
+
|
46
|
+
def simple_encryptor
|
47
|
+
Hello::Encryptors::Simple.instance
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|