diff --git a/app/controllers/omniauth_accounts_controller.rb b/app/controllers/omniauth_accounts_controller.rb new file mode 100644 index 00000000..5f89905c --- /dev/null +++ b/app/controllers/omniauth_accounts_controller.rb @@ -0,0 +1,12 @@ +class OmniauthAccountsController < ApplicationController + before_action :authenticate_user! + + def destroy + if current_user.omniauth_users.find(params[:id]).destroy + flash[:notice] = 'The account was successfully disconnected.' + else + flash[:alert] = 'Something went wrong.' + end + redirect_to root_path + end +end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index d9f422b4..e7df9fb4 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -15,11 +15,15 @@ class RegistrationsController < Devise::RegistrationsController end def account_update_params - params.require(:user).permit(:name, :email, :password, :password_confirmation, :current_password, :email_updates, :fluid_preference) + params.require(:user).permit(:name, :email, :password, :password_confirmation, :email_updates, :fluid_preference) end protected + def update_resource(resource, params) + resource.update_without_password(params) + end + def add_account # If the user was created in the last 60 seconds, report it to Slack if resource.persisted? diff --git a/app/models/user.rb b/app/models/user.rb index 511c663f..3f620d55 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -113,6 +113,18 @@ class User < ActiveRecord::Base update secure_code: SecureRandom.uuid unless secure_code.present? end + + def update_without_password(params, *options) + if params[:password].blank? + params.delete(:password) + params.delete(:password_confirmation) if params[:password_confirmation].blank? + end + + result = update_attributes(params, *options) + clean_up_passwords + result + end + private # Attributes that are non-public, and should be blacklisted from any public diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 7a7a4aa7..7c29d054 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -62,12 +62,6 @@