Update user
This commit is contained in:
parent
48119a687c
commit
a75def4b95
|
@ -0,0 +1,5 @@
|
|||
class AddLanguageToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :language, :string
|
||||
end
|
||||
end
|
|
@ -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? ||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue