diff --git a/app/controllers/settings/profile_controller.rb b/app/controllers/settings/profile_controller.rb new file mode 100644 index 00000000..44a78a30 --- /dev/null +++ b/app/controllers/settings/profile_controller.rb @@ -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 diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 537a65dc..05dfedb7 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -21,36 +21,6 @@ class UserController < ApplicationController 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 def edit_privacy end diff --git a/app/views/settings/profile/edit.haml b/app/views/settings/profile/edit.haml new file mode 100644 index 00000000..a899c89b --- /dev/null +++ b/app/views/settings/profile/edit.haml @@ -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" diff --git a/app/views/user/edit.haml b/app/views/user/edit.haml deleted file mode 100644 index e37c7b07..00000000 --- a/app/views/user/edit.haml +++ /dev/null @@ -1,4 +0,0 @@ -= render "settings/profile" - -- provide(:title, generate_title(t(".title"))) -- parent_layout "user/settings" diff --git a/app/views/user/edit_theme.haml b/app/views/user/edit_theme.haml deleted file mode 100644 index 35a146f4..00000000 --- a/app/views/user/edit_theme.haml +++ /dev/null @@ -1,3 +0,0 @@ -= render "settings/theme" - - diff --git a/config/routes.rb b/config/routes.rb index 5dafde63..cc967b6e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -62,15 +62,15 @@ Rails.application.routes.draw do delete '/settings/account' => 'user/registrations#destroy' 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 get :theme, to: redirect('/settings/theme/edit') 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 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/2fa', to: 'user#update_2fa', via: :patch, as: :update_user_2fa