Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RegistrationsController < Devise::RegistrationsController
- PASS_RESOURCES = %w{password password_confirmation}
- def after_update_path_for(user)
- #user_path(user)
- edit_user_registration_path
- end
- def edit
- @user = @user.decorate
- super
- end
- # add building location for user (city & country)
- def create
- build_params = sign_up_params.merge(time_zone: normalized_zone_name)
- build_resource(build_params)
- resource.save
- yield resource if block_given?
- if resource.persisted?
- if resource.active_for_authentication?
- set_flash_message :notice, :signed_up if is_flashing_format?
- sign_up(resource_name, resource)
- respond_with resource, location: after_sign_up_path_for(resource)
- else
- set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
- expire_data_after_sign_in!
- respond_with resource, location: after_inactive_sign_up_path_for(resource)
- end
- else
- clean_up_passwords resource
- set_minimum_password_length
- respond_with resource
- end
- end
- # re-writing the devise update method to provide an ability to change user profile without providing current password
- def update
- #let devise get on with strong parameters
- resource_params = devise_parameter_sanitizer.sanitize(:account_update)
- if resource_params[:password].blank?
- resource_params.delete(:password)
- resource_params.delete(:password_confirmation) if params[:password_confirmation].blank?
- end
- @user = current_user
- LocationService.new(@user, params).create_location
- ImagesService.new(@user, params).assign_images
- if @user.update_attributes(resource_params)
- set_flash_message :notice, :updated
- # Sign in the user bypassing validation in case his password changed
- sign_in @user, :bypass => true
- redirect_to after_update_path_for(@user)
- else
- @user = @user.decorate
- respond_with @user
- #render 'edit'
- end
- end
- def destroy
- redirect_to root_path, flash: { alert: "Action is not allowed." }
- end
- protected
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement