-
Notifications
You must be signed in to change notification settings - Fork 5
feature/ github oauth integration #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d4828f5
7cc86e2
fb4885b
68ea4bf
72a0030
a1a9b0a
042249f
b7f8af6
ed709f5
8f2f392
163baea
56253fe
d0afb15
1ec7f73
8bc4afa
3bdbd69
72272b1
ba905b6
e9caf22
4292d62
d2f638c
4ac9afb
81bfbf2
ee4ff34
0cf31b7
93149c0
fe025da
12a9d28
df59892
dfb4dd0
1254186
04ea923
850edda
4af60c2
d9a4a1a
275fd16
a773b3b
e11d25a
d12eee2
25c4405
adbd0ea
d3712d5
ce61d54
bab1aeb
4872016
5bebdd0
09eda33
ba02c2f
1598daf
e6f76c2
2c28bd7
96f0560
71a142d
6324d4e
4afdb1f
b61e6b6
df2125c
ba84c40
d0ff490
fdc0f66
728680a
8700a1b
4add9dd
d063df6
590b59a
4f616f6
20d1abc
7170747
ea3b6df
b7c0c68
8ac0493
eb7d6f9
b7ef209
61181ef
6a7b670
6bdb807
e623c52
0e1d92a
10d44f0
81bd298
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BetterTogether | ||
| class OmniauthCallbacksController < Devise::OmniauthCallbacksController # rubocop:todo Style/Documentation | ||
| # See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy | ||
| before_action :verify_oauth_state, only: %i[github] | ||
|
|
||
| before_action :set_person_platform_integration, except: [:failure] | ||
| before_action :set_user, except: [:failure] | ||
| before_action :generate_oauth_state, only: %i[github] | ||
|
|
||
| attr_reader :person_platform_integration, :user | ||
|
|
||
| def github | ||
| handle_auth 'Github' | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def verify_oauth_state | ||
| return unless params[:state] != session[:oauth_state] | ||
|
|
||
| flash[:alert] = 'Invalid OAuth state parameter' | ||
| redirect_to new_user_registration_path | ||
| end | ||
|
|
||
| def handle_auth(kind) # rubocop:todo Metrics/AbcSize | ||
| if user.present? | ||
| flash[:success] = t 'devise_omniauth_callbacks.success', kind: kind if is_navigational_format? | ||
| sign_in_and_redirect user, event: :authentication | ||
| redirect_to edit_user_registration_path | ||
| else | ||
| flash[:alert] = | ||
| t 'devise_omniauth_callbacks.failure', kind:, reason: "#{auth.info.email} is not authorized" | ||
| redirect_to new_user_registration_path | ||
| end | ||
| end | ||
|
|
||
| def auth | ||
| request.env['omniauth.auth'] | ||
| end | ||
|
|
||
| def set_person_platform_integration | ||
| @person_platform_integration = PersonPlatformIntegration.find_by(provider: auth.provider, uid: auth.uid) | ||
| end | ||
|
|
||
| def set_user | ||
| @user = ::BetterTogether.user_class.from_omniauth( | ||
| person_platform_integration:, | ||
| auth:, | ||
| current_user: | ||
| ) | ||
| end | ||
|
|
||
| def generate_oauth_state | ||
| session[:oauth_state] = SecureRandom.hex(24) | ||
| end | ||
|
|
||
| def failure | ||
| flash[:error] = 'There was a problem signing you in. Please register or try signing in later.' | ||
| redirect_to helpers.base_url | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ module BetterTogether | |
| # Responds to requests for pages | ||
| class PagesController < FriendlyResourceController # rubocop:todo Metrics/ClassLength | ||
| before_action :set_page, only: %i[show edit update destroy] | ||
| skip_before_action :check_platform_setup, unless: -> { ::BetterTogether::Platform.where(host: true).any? } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update check to use host scope instead of where query |
||
|
|
||
| before_action only: %i[new edit], if: -> { Rails.env.development? } do | ||
| # Make sure that all BLock subclasses are loaded in dev to generate new block buttons | ||
| BetterTogether::Content::Block.load_all_subclasses | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BetterTogether | ||
| # Allows for the management of PersonPlatformIntegrations | ||
| class PersonPlatformIntegrationsController < ApplicationController | ||
| before_action :set_person_platform_integration, only: %i[show edit update destroy] | ||
|
|
||
| # GET /better_together/person_platform_integrations | ||
| def index | ||
| @person_platform_integrations = BetterTogether::PersonPlatformIntegration.all | ||
| end | ||
|
|
||
| # GET /better_together/person_platform_integrations/1 | ||
| def show; end | ||
|
|
||
| # GET /better_together/person_platform_integrations/new | ||
| def new | ||
| @person_platform_integration = BetterTogether::PersonPlatformIntegration.new | ||
| end | ||
|
|
||
| # GET /better_together/person_platform_integrations/1/edit | ||
| def edit; end | ||
|
|
||
| # POST /better_together/person_platform_integrations | ||
| def create | ||
| @better_together_person_platform_integration = BetterTogether::PersonPlatformIntegration.new(person_platform_integration_params) | ||
| if @person_platform_integration.save | ||
| redirect_to @person_platform_integration, notice: 'PersonPlatformIntegration was successfully created.' | ||
| else | ||
| render :new, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| # PATCH/PUT /better_together/person_platform_integrations/1 | ||
| def update | ||
| if @person_platform_integration.update(person_platform_integration_params) | ||
| redirect_to @person_platform_integration, notice: 'PersonPlatformIntegration was successfully updated.', | ||
| status: :see_other | ||
| else | ||
| render :edit, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| # DELETE /better_together/person_platform_integrations/1 | ||
| def destroy | ||
| @person_platform_integration.destroy! | ||
| redirect_to person_platform_integrations_url, notice: 'PersonPlatformIntegration was successfully destroyed.', | ||
| status: :see_other | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Use callbacks to share common setup or constraints between actions. | ||
| def set_person_platform_integration | ||
| @person_platform_integration = BetterTogether::PersonPlatformIntegration.find(params[:id]) | ||
| end | ||
|
|
||
| # Only allow a list of trusted parameters through. | ||
| def person_platform_integration_params | ||
| params.require(:person_platform_integration).permit(:provider, :uid, :token, :secret, :profile_url, :user_id) | ||
| end | ||
| end | ||
| end |
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be removed or moved to seed branch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BetterTogether | ||
| # CRUD for Seed records | ||
| class SeedsController < ApplicationController | ||
| before_action :set_seed, only: %i[show edit update destroy] | ||
|
|
||
| # GET /seeds | ||
| def index | ||
| @seeds = Seed.all | ||
| end | ||
|
|
||
| # GET /seeds/1 | ||
| def show; end | ||
|
|
||
| # GET /seeds/new | ||
| def new | ||
| @seed = Seed.new | ||
| end | ||
|
|
||
| # GET /seeds/1/edit | ||
| def edit; end | ||
|
|
||
| # POST /seeds | ||
| def create | ||
| @seed = Seed.new(seed_params) | ||
|
|
||
| if @seed.save | ||
| redirect_to @seed, notice: 'Seed was successfully created.' | ||
| else | ||
| render :new, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| # PATCH/PUT /seeds/1 | ||
| def update | ||
| if @seed.update(seed_params) | ||
| redirect_to @seed, notice: 'Seed was successfully updated.', status: :see_other | ||
Check noticeCode scanning / Brakeman Possible unprotected redirect. Note
Possible unprotected redirect.
|
||
| else | ||
| render :edit, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| # DELETE /seeds/1 | ||
| def destroy | ||
| @seed.destroy! | ||
| redirect_to seeds_url, notice: 'Seed was successfully destroyed.', status: :see_other | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Use callbacks to share common setup or constraints between actions. | ||
| def set_seed | ||
| @seed = Seed.find(params[:id]) | ||
| end | ||
|
|
||
| # Only allow a list of trusted parameters through. | ||
| def seed_params | ||
| params.fetch(:seed, {}) | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,7 @@ def language_select_field(form: nil, field_name: :locale, selected_locale: I18n. | |
|
|
||
| def locale_options_for_select(selected_locale = I18n.locale) | ||
| options_for_select( | ||
| I18n.available_locales.map { |locale| [I18n.t("locales.#{locale}", locale:), locale] }, | ||
| I18n.available_locales.map { |locale| [I18n.t("better_together.languages.#{locale}", locale:), locale] }, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check this key |
||
| selected_locale | ||
| ) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BetterTogether | ||
| # This module conains helper methods for PersonPLatformIntegrations | ||
| module PersonPlatformIntegrationsHelper | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module BetterTogether | ||
| module SeedsHelper # rubocop:todo Style/Documentation | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove