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,64 @@
|
|
1
|
+
module Hello
|
2
|
+
module Concerns
|
3
|
+
module Registration
|
4
|
+
module SignUp
|
5
|
+
|
6
|
+
def on_success
|
7
|
+
deliver_welcome_email
|
8
|
+
deliver_confirmation_email
|
9
|
+
|
10
|
+
access_token = sign_in!(@sign_up.user, expires_at, sudo_mode_expires_at)
|
11
|
+
|
12
|
+
respond_to do |format|
|
13
|
+
format.html { redirect_to path_to_go }
|
14
|
+
format.json { render json: access_token.as_json_web_api, status: :created }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_failure
|
19
|
+
respond_to do |format|
|
20
|
+
format.html { render_sign_up }
|
21
|
+
format.json { render json: @sign_up.errors, status: :unprocessable_entity }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def expires_at
|
28
|
+
30.days.from_now
|
29
|
+
end
|
30
|
+
|
31
|
+
def sudo_mode_expires_at
|
32
|
+
Hello.configuration.sudo_expires_in.from_now
|
33
|
+
end
|
34
|
+
|
35
|
+
def path_to_go
|
36
|
+
'/onboarding'
|
37
|
+
end
|
38
|
+
|
39
|
+
def deliver_welcome_email
|
40
|
+
Mailer.welcome(email, user, password).deliver
|
41
|
+
end
|
42
|
+
|
43
|
+
def deliver_confirmation_email
|
44
|
+
token = @sign_up.email_credential.reset_verifying_token!
|
45
|
+
url = hello.confirm_email_url(@sign_up.email_credential, token)
|
46
|
+
Mailer.confirm_email(email, user, url).deliver
|
47
|
+
end
|
48
|
+
|
49
|
+
def email
|
50
|
+
@sign_up.email_credential.email
|
51
|
+
end
|
52
|
+
|
53
|
+
def user
|
54
|
+
@sign_up.user
|
55
|
+
end
|
56
|
+
|
57
|
+
def password
|
58
|
+
@sign_up.password
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Hello
|
2
|
+
module Internationalization
|
3
|
+
class LocaleController < ApplicationController
|
4
|
+
dont_kick_people
|
5
|
+
|
6
|
+
# GET /hello/locale
|
7
|
+
def index
|
8
|
+
respond_to do |format|
|
9
|
+
format.html { render 'hello/internationalization/locales' }
|
10
|
+
format.json { render json: { locales: view_context.available_locales_with_names } }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# POST /hello/locale
|
15
|
+
def update
|
16
|
+
business = Business::Internationalization::UpdateLocale.new(params['locale'])
|
17
|
+
|
18
|
+
current_user && current_user.update!(locale: business.locale)
|
19
|
+
use_locale(business.locale)
|
20
|
+
|
21
|
+
respond_to do |format|
|
22
|
+
format.html { redirect_to :back, notice: business.success_message }
|
23
|
+
format.json { fail Hello::Errors::JsonNotSupported }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Hello
|
2
|
+
module Management
|
3
|
+
class AccessesController < ApplicationController
|
4
|
+
kick :guest, :onboarding
|
5
|
+
|
6
|
+
before_actions do
|
7
|
+
all { sudo_mode }
|
8
|
+
only(:index) { @accesses = current_user.accesses }
|
9
|
+
only(:destroy) { @access = current_user.accesses.find(params[:id]) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /hello/accesses
|
13
|
+
def index
|
14
|
+
render 'hello/management/accesses'
|
15
|
+
end
|
16
|
+
|
17
|
+
# DELETE /hello/accesses/1
|
18
|
+
def destroy
|
19
|
+
business = Business::Management::UnlinkAccess.new
|
20
|
+
if @access.destroy
|
21
|
+
flash[:notice] = business.success_message
|
22
|
+
else
|
23
|
+
flash[:alert] = business.alert_message
|
24
|
+
end
|
25
|
+
redirect_to hello.accesses_url
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Hello
|
2
|
+
module Management
|
3
|
+
class ConfirmEmailsController < ApplicationController
|
4
|
+
dont_kick_people
|
5
|
+
|
6
|
+
before_actions do
|
7
|
+
all { sign_out! }
|
8
|
+
only(:confirm) { @credential = ::EmailCredential.where(id: params[:id]).first }
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /hello/emails/1/confirm/:token
|
12
|
+
def confirm
|
13
|
+
business = Business::Management::ConfirmEmail.new(@credential)
|
14
|
+
|
15
|
+
if business.confirm_with_token(params[:token])
|
16
|
+
_sign_in
|
17
|
+
flash[:notice] = business.success_message
|
18
|
+
redirect_to profile_path
|
19
|
+
else
|
20
|
+
flash[:alert] = business.alert_message
|
21
|
+
redirect_to expired_confirmation_token_emails_path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# GET /hello/emails/expired_confirmation_token
|
26
|
+
def expired_confirmation_token
|
27
|
+
render 'hello/management/email_credentials/expired_confirmation_token'
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def _sign_in
|
33
|
+
# In RSpec and Capybara (Rails 4.2):
|
34
|
+
# when the user gets access, the session of the next request will assume the values it had before,
|
35
|
+
# if before you were a guest, you will be redirected as a user, but the following request will be as a guest again
|
36
|
+
# if before you were a user1, you will be redirected as a user2, but the following request will be as a user1 again
|
37
|
+
access_token = sign_in!(@credential.user, 1.hour.from_now)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Hello
|
2
|
+
module Management
|
3
|
+
class EmailsController < ApplicationController
|
4
|
+
kick :guest, :onboarding
|
5
|
+
sudo_mode
|
6
|
+
|
7
|
+
helper_method :credentials
|
8
|
+
|
9
|
+
before_actions do
|
10
|
+
only(:index) { @credential = ::EmailCredential.new }
|
11
|
+
only(:create) { @credential = current_user.email_credentials.build(email_credential_params) }
|
12
|
+
only(:destroy, :deliver) { @credential = current_user.email_credentials.find(params[:id]) }
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /hello/emails
|
16
|
+
def index
|
17
|
+
render_list
|
18
|
+
end
|
19
|
+
|
20
|
+
# POST /hello/emails
|
21
|
+
def create
|
22
|
+
business = Business::Management::AddEmail.new(@credential)
|
23
|
+
if @credential.save
|
24
|
+
redirect_to hello.emails_path, notice: business.success_message
|
25
|
+
else
|
26
|
+
flash.now[:alert] = business.error_message
|
27
|
+
render_list
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# DELETE /hello/emails/1
|
32
|
+
def destroy
|
33
|
+
business = Business::Management::RemoveEmail.new(@credential)
|
34
|
+
if @credential.destroy
|
35
|
+
redirect_to hello.emails_path, notice: business.success_message
|
36
|
+
else
|
37
|
+
flash.now[:alert] = business.error_message
|
38
|
+
render_list
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# POST /hello/emails/1/deliver
|
43
|
+
def deliver
|
44
|
+
business = Business::Management::SendConfirmationEmail.new(self, @credential)
|
45
|
+
business.deliver
|
46
|
+
flash[:notice] = business.success_message
|
47
|
+
redirect_to hello.emails_path
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Only allow a trusted parameter "white list" through.
|
53
|
+
def email_credential_params
|
54
|
+
params.require(:email_credential).permit(:email)
|
55
|
+
end
|
56
|
+
|
57
|
+
def credentials
|
58
|
+
# TODO: this is necessary to hide a temporary bug, must solve this later
|
59
|
+
current_user.credentials.where(type: 'EmailCredential')
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_list
|
63
|
+
render 'hello/management/email_credentials/index'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Hello
|
2
|
+
module Management
|
3
|
+
# you really should be overriding concerns instead of this file
|
4
|
+
class ForgotPasswordController < ApplicationController
|
5
|
+
include Hello::Concerns::Management::ForgotPassword
|
6
|
+
|
7
|
+
dont_kick :guest
|
8
|
+
|
9
|
+
before_action { @sender = Hello.configuration.mailer_sender }
|
10
|
+
|
11
|
+
# GET /hello/passwords/forgot
|
12
|
+
def index
|
13
|
+
@forgot_password = Business::Management::ForgotPassword.new
|
14
|
+
render 'hello/management/password_credentials/forgot'
|
15
|
+
end
|
16
|
+
|
17
|
+
# POST /hello/passwords/forgot
|
18
|
+
def forgot
|
19
|
+
@forgot_password = Business::Management::ForgotPassword.new(params.require(:forgot_password))
|
20
|
+
@user = @forgot_password.user
|
21
|
+
|
22
|
+
if @forgot_password.reset
|
23
|
+
on_success
|
24
|
+
else
|
25
|
+
on_failure
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def render_success
|
32
|
+
render 'hello/management/password_credentials/forgot_success'
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_form
|
36
|
+
render 'hello/management/password_credentials/forgot'
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Hello
|
2
|
+
module Management
|
3
|
+
class PasswordsController < ApplicationController
|
4
|
+
kick :guest, :onboarding
|
5
|
+
sudo_mode
|
6
|
+
|
7
|
+
before_action do
|
8
|
+
@password_credential = current_user.password_credential || fail(ActiveRecord::NotFound)
|
9
|
+
@update_profile = Business::Management::UpdateProfile.new(@password_credential)
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /hello/passwords
|
13
|
+
def index
|
14
|
+
respond_to do |format|
|
15
|
+
format.html { redirect_to password_path(@password_credential.id) }
|
16
|
+
format.json { head :no_content }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET /hello/passwords/1
|
21
|
+
def show
|
22
|
+
respond_to do |format|
|
23
|
+
format.html { render_password_view }
|
24
|
+
format.json { head :no_content }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# PATCH /hello/passwords/1
|
29
|
+
def update
|
30
|
+
@password_credential.password = password_credential_params[:password]
|
31
|
+
# @password_credential.password_confirmation = password_credential_params[:password_confirmation] if password_credential_params[:password_confirmation]
|
32
|
+
|
33
|
+
if @password_credential.save
|
34
|
+
respond_to do |format|
|
35
|
+
format.html { redirect_to hello.password_path(@password_credential), notice: @update_profile.success_message }
|
36
|
+
format.json { head :no_content }
|
37
|
+
end
|
38
|
+
else
|
39
|
+
respond_to do |format|
|
40
|
+
format.html { render_password_view }
|
41
|
+
format.json { render json: @password_credential.errors, status: :unprocessable_entity }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def password_credential_params
|
49
|
+
params.require(:password_credential)
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_password_view
|
53
|
+
render 'hello/management/password_credentials/show'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Hello
|
2
|
+
module Management
|
3
|
+
class ProfilesController < ApplicationController
|
4
|
+
|
5
|
+
kick :guest, :onboarding, only: [:show, :update]
|
6
|
+
|
7
|
+
before_action(only: [:show, :update]) do
|
8
|
+
@user = current_user
|
9
|
+
@user_business = Business::Management::UpdateProfile.new(@user)
|
10
|
+
end
|
11
|
+
|
12
|
+
# GET /hello/user
|
13
|
+
def show
|
14
|
+
respond_to do |format|
|
15
|
+
format.html { render 'hello/management/user' }
|
16
|
+
format.json { render json: @user.as_json_web_api, status: :ok }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# PATCH /hello/user
|
21
|
+
def update
|
22
|
+
if @user_business.update(user_params)
|
23
|
+
use_locale(current_user.locale)
|
24
|
+
flash[:notice] = @user_business.success_message
|
25
|
+
respond_to do |format|
|
26
|
+
format.html { redirect_to hello.profile_path }
|
27
|
+
format.json { render json: @user.as_json_web_api, status: :ok }
|
28
|
+
end
|
29
|
+
else
|
30
|
+
render 'hello/management/user'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
dont_kick :user, only: [:cancel, :destroy]
|
38
|
+
sudo_mode only: [:cancel, :destroy]
|
39
|
+
|
40
|
+
# GET /hello/user/cancel
|
41
|
+
def cancel
|
42
|
+
render 'hello/management/cancel'
|
43
|
+
end
|
44
|
+
|
45
|
+
# DELETE /hello/user
|
46
|
+
def destroy
|
47
|
+
@cancel_account = Business::Management::CancelAccount.new(current_user)
|
48
|
+
|
49
|
+
if @cancel_account.cancel_account
|
50
|
+
flash[:notice] = @cancel_account.success_message
|
51
|
+
respond_to do |format|
|
52
|
+
format.html { redirect_to '/' }
|
53
|
+
format.json { render json: { cancelled: true }, status: :ok }
|
54
|
+
end
|
55
|
+
else
|
56
|
+
flash.now[:alert] = @cancel_account.alert_message
|
57
|
+
respond_to do |format|
|
58
|
+
format.html { render 'hello/management/cancel' }
|
59
|
+
format.json { render json: { message: @cancel_account.alert_message }, status: :unprocessable_entity }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def user_params
|
67
|
+
params.require(:user)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Hello
|
2
|
+
module Management
|
3
|
+
# you really should be overriding concerns instead of this file
|
4
|
+
class ResetPasswordController < ApplicationController
|
5
|
+
include Hello::Concerns::Management::ResetPassword
|
6
|
+
|
7
|
+
sign_out!
|
8
|
+
|
9
|
+
before_action do
|
10
|
+
# a helping ivar
|
11
|
+
@current_url = request.fullpath
|
12
|
+
# find
|
13
|
+
@user = ::User.find(params[:user_id])
|
14
|
+
@password_credential = @user.password_credentials.find(params[:id])
|
15
|
+
unless @password_credential.verifying_token_is?(params[:token])
|
16
|
+
fail ActiveRecord::RecordNotFound
|
17
|
+
end
|
18
|
+
# business
|
19
|
+
@reset_password = Business::Management::ResetPassword.new(@password_credential)
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /passwords/:id/reset/:user_id/:token
|
23
|
+
def index
|
24
|
+
render_reset_form
|
25
|
+
end
|
26
|
+
|
27
|
+
# POST /passwords/:id/reset/:user_id/:token
|
28
|
+
def update
|
29
|
+
if @reset_password.update_password(new_password)
|
30
|
+
flash[:notice] = @reset_password.success_message
|
31
|
+
on_success
|
32
|
+
else
|
33
|
+
on_failure
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
rescue_from ActiveRecord::RecordNotFound do
|
38
|
+
flash[:alert] = Business::Management::ResetPassword.new(nil).alert_message
|
39
|
+
redirect_to forgot_passwords_path
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def render_reset_form
|
45
|
+
render 'hello/management/password_credentials/reset'
|
46
|
+
end
|
47
|
+
|
48
|
+
def new_password
|
49
|
+
params.require(:reset_password)[:password]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|