mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
Allow user to manage social media accounts on settings page
This commit is contained in:
parent
9daaad1f5c
commit
f3b2956e6e
12
app/controllers/omniauth_accounts_controller.rb
Normal file
12
app/controllers/omniauth_accounts_controller.rb
Normal file
@ -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
|
||||
@ -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?
|
||||
|
||||
@ -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
|
||||
|
||||
@ -62,12 +62,6 @@
|
||||
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<h4>Identity check (required)</h4>
|
||||
<div class="field">
|
||||
<%= f.label :current_password %> <i>(we need your current password to confirm any changes)</i><br />
|
||||
<%= f.password_field :current_password, autocomplete: "off" %>
|
||||
</div>
|
||||
|
||||
<div class="center">
|
||||
<div class="actions">
|
||||
<%= f.submit "Update your account information", class: 'btn blue' %>
|
||||
@ -76,5 +70,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<h4>Social Media Accounts</h4>
|
||||
<%- if devise_mapping.omniauthable? %>
|
||||
<% resource.omniauth_users.each do |omniauth_account| %>
|
||||
<%= link_to "Disconnect #{omniauth_account.provider} (#{omniauth_account.email})", omniauth_account_path(omniauth_account.id), method: :delete %>
|
||||
<br />
|
||||
<% end %>
|
||||
<%- resource_class.omniauth_providers.each do |provider| %>
|
||||
<%= link_to "Connect with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -213,6 +213,8 @@ Rails.application.routes.draw do
|
||||
scope '/market' do
|
||||
get '/', to: 'main#comingsoon'
|
||||
end
|
||||
|
||||
resources :omniauth_accounts, only: [:destroy]
|
||||
end
|
||||
|
||||
# rubocop:enable LineLength
|
||||
|
||||
Loading…
Reference in New Issue
Block a user