Skip to content

Commit 9459c61

Browse files
committed
fix: disabled profile edit on omniauth sign in
1 parent e0e3eac commit 9459c61

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

app/helpers/application_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ def sso_provider_button(provider, link_to_path)
2525
html_element
2626
end
2727
end
28+
29+
def disable_profile_editing_on_omniauth_connection?
30+
current_organization.enabled_omniauth_providers.any? && session["omniauth.provider"].present?
31+
end
2832
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- replace "erb[loud]:contains('email_field :email')" -->
2+
<%= f.email_field :email, disabled: disable_profile_editing_on_omniauth_connection? || current_user.unconfirmed_email.present?, autocomplete: "email" %>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!-- replace "erb[loud]:contains('text_field :name')" -->
2+
<%= f.text_field :name, disabled: disable_profile_editing_on_omniauth_connection?, autocomplete: "name" %>

config/initializers/omniauth.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
ActiveSupport::Notifications.subscribe "decidim.user.omniauth_registration" do |_name, data|
4+
Rails.logger.debug "decidim.user.omniauth_registration event in config/initializers/omniauth.rb"
5+
6+
update_user_profile(data)
7+
end
8+
9+
def update_user_profile(data)
10+
user = Decidim::User.find(data[:user_id])
11+
12+
user.email = data[:email] if data[:email].present?
13+
user.skip_reconfirmation! if data[:email].present? && user.email_changed?
14+
user.name = data[:name] if data[:name].present?
15+
16+
user.save!(validate: false, touch: false)
17+
end

0 commit comments

Comments
 (0)