WIP: Move profile actions to `Settings::ProfileController`
This commit is contained in:
parent
e64f206f5b
commit
efa0048c87
|
@ -0,0 +1,32 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::ProfileController < ApplicationController
|
||||||
|
before_action :authenticate_user!
|
||||||
|
|
||||||
|
def edit; end
|
||||||
|
|
||||||
|
def update
|
||||||
|
user_attributes = params.require(:user).permit(:show_foreign_themes, :profile_picture_x, :profile_picture_y, :profile_picture_w, :profile_picture_h,
|
||||||
|
:profile_header_x, :profile_header_y, :profile_header_w, :profile_header_h, :profile_picture, :profile_header)
|
||||||
|
if current_user.update(user_attributes)
|
||||||
|
text = t(".success")
|
||||||
|
text += t(".notice.profile_picture") if user_attributes[:profile_picture]
|
||||||
|
text += t(".notice.profile_header") if user_attributes[:profile_header]
|
||||||
|
flash[:success] = text
|
||||||
|
else
|
||||||
|
flash[:error] = t(".error")
|
||||||
|
end
|
||||||
|
redirect_to edit_user_profile_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_profile
|
||||||
|
profile_attributes = params.require(:profile).permit(:display_name, :motivation_header, :website, :location, :description, :anon_display_name)
|
||||||
|
|
||||||
|
if current_user.profile.update(profile_attributes)
|
||||||
|
flash[:success] = t(".success")
|
||||||
|
else
|
||||||
|
flash[:error] = t(".error")
|
||||||
|
end
|
||||||
|
redirect_to edit_user_profile_path
|
||||||
|
end
|
||||||
|
end
|
|
@ -21,36 +21,6 @@ class UserController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# region Account settings
|
|
||||||
def edit
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
user_attributes = params.require(:user).permit(:show_foreign_themes, :profile_picture_x, :profile_picture_y, :profile_picture_w, :profile_picture_h,
|
|
||||||
:profile_header_x, :profile_header_y, :profile_header_w, :profile_header_h, :profile_picture, :profile_header)
|
|
||||||
if current_user.update(user_attributes)
|
|
||||||
text = t(".success")
|
|
||||||
text += t(".notice.profile_picture") if user_attributes[:profile_picture]
|
|
||||||
text += t(".notice.profile_header") if user_attributes[:profile_header]
|
|
||||||
flash[:success] = text
|
|
||||||
else
|
|
||||||
flash[:error] = t(".error")
|
|
||||||
end
|
|
||||||
redirect_to edit_user_profile_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_profile
|
|
||||||
profile_attributes = params.require(:profile).permit(:display_name, :motivation_header, :website, :location, :description, :anon_display_name)
|
|
||||||
|
|
||||||
if current_user.profile.update(profile_attributes)
|
|
||||||
flash[:success] = t(".success")
|
|
||||||
else
|
|
||||||
flash[:error] = t(".error")
|
|
||||||
end
|
|
||||||
redirect_to edit_user_profile_path
|
|
||||||
end
|
|
||||||
# endregion
|
|
||||||
|
|
||||||
# region Privacy settings
|
# region Privacy settings
|
||||||
def edit_privacy
|
def edit_privacy
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
.card
|
||||||
|
.card-body
|
||||||
|
= bootstrap_form_for(current_user, url: { action: :edit }, html: { multipart: true }, method: :patch) do |f|
|
||||||
|
|
||||||
|
.media#profile-picture-media
|
||||||
|
.pull-left
|
||||||
|
%img.avatar-lg.mr-3{ src: current_user.profile_picture.url(:medium) }
|
||||||
|
.media-body
|
||||||
|
= f.file_field :profile_picture, accept: APP_CONFIG[:accepted_image_formats].join(",")
|
||||||
|
|
||||||
|
.row.d-none#profile-picture-crop-controls
|
||||||
|
.col-sm-10.col-md-8
|
||||||
|
%strong= t(".adjust.profile_picture")
|
||||||
|
%img#profile-picture-cropper{ src: current_user.profile_picture.url(:medium) }
|
||||||
|
|
||||||
|
.row.mb-2#profile-header-media
|
||||||
|
.col
|
||||||
|
%img.mw-100.mr-3{ src: current_user.profile_header.url(:mobile) }
|
||||||
|
.col-xs-12.mt-3.mt-sm-0.pl-3.pr-3
|
||||||
|
= f.file_field :profile_header, accept: APP_CONFIG[:accepted_image_formats].join(",")
|
||||||
|
|
||||||
|
.row.d-none#profile-header-crop-controls
|
||||||
|
.col-sm-10.col-md-8
|
||||||
|
%strong= t(".adjust.profile_header")
|
||||||
|
%img#profile-header-cropper{ src: current_user.profile_header.url(:web) }
|
||||||
|
|
||||||
|
= f.check_box :show_foreign_themes
|
||||||
|
|
||||||
|
- %i[profile_picture_x profile_picture_y profile_picture_w profile_picture_h].each do |attrib|
|
||||||
|
= f.hidden_field attrib, id: attrib
|
||||||
|
|
||||||
|
- %i[profile_header_x profile_header_y profile_header_w profile_header_h].each do |attrib|
|
||||||
|
= f.hidden_field attrib, id: attrib
|
||||||
|
|
||||||
|
= f.primary
|
||||||
|
.card
|
||||||
|
.card-body
|
||||||
|
= bootstrap_form_for(current_user.profile, url: { action: :update_profile }, html: { multipart: true }, method: :patch) do |f|
|
||||||
|
|
||||||
|
= f.text_field :display_name
|
||||||
|
|
||||||
|
= f.text_field :motivation_header
|
||||||
|
|
||||||
|
= f.text_field :anon_display_name, placeholder: APP_CONFIG["anonymous_name"]
|
||||||
|
|
||||||
|
= f.text_field :website
|
||||||
|
|
||||||
|
= f.text_field :location
|
||||||
|
|
||||||
|
= f.text_area :description
|
||||||
|
|
||||||
|
= f.primary
|
||||||
|
|
||||||
|
- provide(:title, generate_title(t(".title")))
|
||||||
|
- parent_layout "user/settings"
|
|
@ -1,4 +0,0 @@
|
||||||
= render "settings/profile"
|
|
||||||
|
|
||||||
- provide(:title, generate_title(t(".title")))
|
|
||||||
- parent_layout "user/settings"
|
|
|
@ -1,3 +0,0 @@
|
||||||
= render "settings/theme"
|
|
||||||
|
|
||||||
|
|
|
@ -62,15 +62,15 @@ Rails.application.routes.draw do
|
||||||
delete '/settings/account' => 'user/registrations#destroy'
|
delete '/settings/account' => 'user/registrations#destroy'
|
||||||
end
|
end
|
||||||
|
|
||||||
match '/settings/profile', to: 'user#edit', via: 'get', as: :edit_user_profile
|
|
||||||
match '/settings/profile', to: 'user#update', via: 'patch', as: :update_user_profile
|
|
||||||
match '/settings/profile_info', to: 'user#update_profile', via: 'patch', as: :update_user_profile_info
|
|
||||||
|
|
||||||
namespace :settings do
|
namespace :settings do
|
||||||
get :theme, to: redirect('/settings/theme/edit')
|
get :theme, to: redirect('/settings/theme/edit')
|
||||||
resource :theme, controller: :theme, only: %i[edit update destroy]
|
resource :theme, controller: :theme, only: %i[edit update destroy]
|
||||||
|
|
||||||
|
get :profile, to: redirect('/settings/profile/edit')
|
||||||
|
resource :profile, controller: :profile, only: %i[edit update update_profile]
|
||||||
end
|
end
|
||||||
resolve('Theme') { [:settings_theme] } # to make link_to/form_for work nicely when passing a `Theme` object to it, see also: https://api.rubyonrails.org/v6.1.5.1/classes/ActionDispatch/Routing/Mapper/CustomUrls.html#method-i-resolve
|
resolve('Theme') { [:settings_theme] } # to make link_to/form_for work nicely when passing a `Theme` object to it, see also: https://api.rubyonrails.org/v6.1.5.1/classes/ActionDispatch/Routing/Mapper/CustomUrls.html#method-i-resolve
|
||||||
|
resolve('Profile') { [:settings_profile] }
|
||||||
|
|
||||||
match '/settings/security', to: 'user#edit_security', via: :get, as: :edit_user_security
|
match '/settings/security', to: 'user#edit_security', via: :get, as: :edit_user_security
|
||||||
match '/settings/security/2fa', to: 'user#update_2fa', via: :patch, as: :update_user_2fa
|
match '/settings/security/2fa', to: 'user#update_2fa', via: :patch, as: :update_user_2fa
|
||||||
|
|
Loading…
Reference in New Issue