From a75def4b952f2c9baf37ee3b9a703ddbbb2981d4 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Wed, 5 Aug 2015 16:27:10 +0300 Subject: [PATCH] Update user --- .../20150805161830_add_language_to_users.rb | 5 ++++ .../users/registrations_controller.rb | 23 +++++++++++-------- .../open_fest/users/registrations/edit.slim | 15 +----------- 3 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 db/migrate/20150805161830_add_language_to_users.rb diff --git a/db/migrate/20150805161830_add_language_to_users.rb b/db/migrate/20150805161830_add_language_to_users.rb new file mode 100644 index 0000000..e9ae846 --- /dev/null +++ b/db/migrate/20150805161830_add_language_to_users.rb @@ -0,0 +1,5 @@ +class AddLanguageToUsers < ActiveRecord::Migration + def change + add_column :users, :language, :string + end +end diff --git a/lib/open_fest/app/controllers/open_fest/users/registrations_controller.rb b/lib/open_fest/app/controllers/open_fest/users/registrations_controller.rb index 85b97ed..bcbbdcd 100644 --- a/lib/open_fest/app/controllers/open_fest/users/registrations_controller.rb +++ b/lib/open_fest/app/controllers/open_fest/users/registrations_controller.rb @@ -2,20 +2,21 @@ class OpenFest::Users::RegistrationsController < Devise::RegistrationsController include OpenFest::Users::DeviseController def edit - resource.find_or_initialize_personal_profile(current_conference) + @user = resource end def update @user = User.find(current_user.id) - successfully_updated = if needs_password?(@user, params) - @user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update)) - else - # remove the virtual current_password attribute - # update_without_password doesn't know how to ignore it - params[:user].delete(:current_password) - @user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update)) - end + successfully_updated = + if needs_password?(@user, params) + @user.update_with_password(params_for_update) + else + # remove the virtual current_password attribute + # update_without_password doesn't know how to ignore it + params[:user].delete(:current_password) + @user.update_without_password(params_for_update) + end if successfully_updated set_flash_message :notice, :updated @@ -29,6 +30,10 @@ class OpenFest::Users::RegistrationsController < Devise::RegistrationsController private + def params_for_update + params.require(:user).permit(:email, :language, :password, :password_confirmation, :current_password) + end + def needs_password?(user, params) user.email != params[:user][:email] || params[:user][:password].present? || diff --git a/lib/open_fest/app/views/open_fest/users/registrations/edit.slim b/lib/open_fest/app/views/open_fest/users/registrations/edit.slim index 000a638..54fd8cb 100644 --- a/lib/open_fest/app/views/open_fest/users/registrations/edit.slim +++ b/lib/open_fest/app/views/open_fest/users/registrations/edit.slim @@ -1,23 +1,10 @@ - content_for(:title) { t :edit_speaker_profile } = simple_form_for(resource, wrapper: :default, as: :user, url: user_registration_path, html: { method: :put, multipart: true }) do |f| - .form_inputs - h2.entry-title = t :personal_profile - = f.error_notification - = f.simple_fields_for :personal_profile, resource.personal_profile(current_conference) do |ff| - = ff.input :picture, as: :file, required: true - = ff.input :first_name, autofocus: true - = ff.input :last_name - = ff.input :public_email - = ff.input :organisation - = ff.input :github - = ff.input :twitter - = ff.input :mobile_phone, input_html: {value: ff.object.mobile_phone.try(:phony_formatted, format: :international)} - = ff.input :biography - .form-inputs h3.entry-title = t :login_data = f.input :email, required: true + = f.input :language, collection: I18n.available_locales, required: true - if devise_mapping.confirmable? && resource.pending_reconfirmation? p