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
|
include OpenFest::Users::DeviseController
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
resource.find_or_initialize_personal_profile(current_conference)
|
@user = resource
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@user = User.find(current_user.id)
|
@user = User.find(current_user.id)
|
||||||
|
|
||||||
successfully_updated = if needs_password?(@user, params)
|
successfully_updated =
|
||||||
@user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update))
|
if needs_password?(@user, params)
|
||||||
else
|
@user.update_with_password(params_for_update)
|
||||||
# remove the virtual current_password attribute
|
else
|
||||||
# update_without_password doesn't know how to ignore it
|
# remove the virtual current_password attribute
|
||||||
params[:user].delete(:current_password)
|
# update_without_password doesn't know how to ignore it
|
||||||
@user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
|
params[:user].delete(:current_password)
|
||||||
end
|
@user.update_without_password(params_for_update)
|
||||||
|
end
|
||||||
|
|
||||||
if successfully_updated
|
if successfully_updated
|
||||||
set_flash_message :notice, :updated
|
set_flash_message :notice, :updated
|
||||||
|
@ -29,6 +30,10 @@ class OpenFest::Users::RegistrationsController < Devise::RegistrationsController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def params_for_update
|
||||||
|
params.require(:user).permit(:email, :language, :password, :password_confirmation, :current_password)
|
||||||
|
end
|
||||||
|
|
||||||
def needs_password?(user, params)
|
def needs_password?(user, params)
|
||||||
user.email != params[:user][:email] ||
|
user.email != params[:user][:email] ||
|
||||||
params[:user][:password].present? ||
|
params[:user][:password].present? ||
|
||||||
|
|
|
@ -1,23 +1,10 @@
|
||||||
- content_for(:title) { t :edit_speaker_profile }
|
- 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|
|
= 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
|
.form-inputs
|
||||||
h3.entry-title = t :login_data
|
h3.entry-title = t :login_data
|
||||||
= f.input :email, required: true
|
= f.input :email, required: true
|
||||||
|
= f.input :language, collection: I18n.available_locales, required: true
|
||||||
|
|
||||||
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
|
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
|
||||||
p
|
p
|
||||||
|
|
Loading…
Reference in New Issue