diff --git a/app/controllers/settings/profile_controller.rb b/app/controllers/settings/profile_controller.rb index 44a78a30..2d1576dd 100644 --- a/app/controllers/settings/profile_controller.rb +++ b/app/controllers/settings/profile_controller.rb @@ -6,20 +6,6 @@ class Settings::ProfileController < ApplicationController 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) @@ -27,6 +13,7 @@ class Settings::ProfileController < ApplicationController else flash[:error] = t(".error") end - redirect_to edit_user_profile_path + + redirect_to settings_profile_path end end diff --git a/app/controllers/settings/profile_picture_controller.rb b/app/controllers/settings/profile_picture_controller.rb new file mode 100644 index 00000000..c44e1200 --- /dev/null +++ b/app/controllers/settings/profile_picture_controller.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class Settings::ProfilePictureController < ApplicationController + before_action :authenticate_user! + + 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 settings_profile_path + end +end diff --git a/app/views/settings/profile/edit.haml b/app/views/settings/profile/edit.haml index a899c89b..30d3f783 100644 --- a/app/views/settings/profile/edit.haml +++ b/app/views/settings/profile/edit.haml @@ -1,6 +1,6 @@ .card .card-body - = bootstrap_form_for(current_user, url: { action: :edit }, html: { multipart: true }, method: :patch) do |f| + = bootstrap_form_for(current_user, url: settings_profile_picture_path, html: { multipart: true }, method: :patch) do |f| .media#profile-picture-media .pull-left @@ -35,7 +35,7 @@ = f.primary .card .card-body - = bootstrap_form_for(current_user.profile, url: { action: :update_profile }, html: { multipart: true }, method: :patch) do |f| + = bootstrap_form_for(current_user.profile, html: { multipart: true }, method: :patch) do |f| = f.text_field :display_name diff --git a/config/routes.rb b/config/routes.rb index cc967b6e..47c31f16 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -67,7 +67,9 @@ Rails.application.routes.draw do 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] + resource :profile, controller: :profile, only: %i[edit update] + + resource :profile_picture, controller: :profile_picture, only: %i[update] 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('Profile') { [:settings_profile] }