diff --git a/app/controllers/concerns/users/add_university_to_request_params.rb b/app/controllers/concerns/users/add_university_to_request_params.rb new file mode 100644 index 0000000000000000000000000000000000000000..84feb66858100878fd3f9fa9cf995ec686b62afd --- /dev/null +++ b/app/controllers/concerns/users/add_university_to_request_params.rb @@ -0,0 +1,14 @@ +module Users::AddUniversityToRequestParams + extend ActiveSupport::Concern + + included do + prepend_before_action :add_university_to_request_params, only: :create + end + + protected + + def add_brand_to_request_params + # inject university_id in users params submitted + request.params[:user][:university_id] = current_university.id unless request.params[:user].nil? + end +end diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 8e2a6ea73fe396bd3350a69505833f965f39f1ca..98000946ca7f1a503698e6bcf0d278fe7c90f399 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -1,10 +1,3 @@ class Users::ConfirmationsController < Devise::ConfirmationsController - prepend_before_action :set_university, only: :create - - protected - - def set_university - return if request.params[:user].nil? - request.params[:user][:university_id] = current_university.id - end + include Users::AddUniversityToRequestParams end diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..d02a3972e097c6ef33e9c9bde0cabd47ecc68f7b --- /dev/null +++ b/app/controllers/users/passwords_controller.rb @@ -0,0 +1,3 @@ +class Users::PasswordsController < Devise::PasswordsController + include Users::AddUniversityToRequestParams +end diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 15c254c2057b1f62f8cbe5c8589f667d76bf9f92..779a6029ca4b17c8b65f0d99d4fbca60ba840c9c 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -1,15 +1,11 @@ class Users::RegistrationsController < Devise::RegistrationsController - prepend_before_action :set_university, only: :create + include Users::AddUniversityToRequestParams + before_action :configure_sign_up_params, only: :create before_action :configure_account_update_params, only: :update protected - def set_university - return if request.params[:user].nil? - request.params[:user][:university_id] = current_university.id - end - def configure_sign_up_params devise_parameter_sanitizer.permit(:sign_up, keys: [:language_id, :first_name, :last_name]) end diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 569a1c8862be660ee009c5d35633b2debd3bb8e5..2e9ca5a51e4a81a89046a7db59cb262b5e7c66fa 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -1,10 +1,3 @@ class Users::SessionsController < Devise::SessionsController - prepend_before_action :set_university, only: :create - - protected - - def set_university - return if request.params[:user].nil? - request.params[:user][:university_id] = current_university.id - end + include Users::AddUniversityToRequestParams end diff --git a/app/controllers/users/unlocks_controller.rb b/app/controllers/users/unlocks_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..b1ef889214da83bd699990b4c1110d132a004626 --- /dev/null +++ b/app/controllers/users/unlocks_controller.rb @@ -0,0 +1,3 @@ +class Users::UnlocksController < Devise::UnlocksController + include Users::AddUniversityToRequestParams +end diff --git a/config/routes.rb b/config/routes.rb index 0881881caebf0922e1d5ca22bbeabf2972704d71..7612e90a35f2968074f16ceaafa3ddda25108f93 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,10 @@ Rails.application.routes.draw do devise_for :users, controllers: { confirmations: 'users/confirmations', + passwords: 'users/passwords', registrations: 'users/registrations', - sessions: 'users/sessions' + sessions: 'users/sessions', + unlocks: 'users/unlocks' } resources :languages