Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. class RegistrationsController < Devise::RegistrationsController
  2. PASS_RESOURCES = %w{password password_confirmation}
  3.  
  4. def after_update_path_for(user)
  5. #user_path(user)
  6. edit_user_registration_path
  7. end
  8.  
  9. def edit
  10. @user = @user.decorate
  11. super
  12. end
  13.  
  14. # add building location for user (city & country)
  15. def create
  16. build_params = sign_up_params.merge(time_zone: normalized_zone_name)
  17. build_resource(build_params)
  18.  
  19. resource.save
  20. yield resource if block_given?
  21.  
  22. if resource.persisted?
  23. if resource.active_for_authentication?
  24. set_flash_message :notice, :signed_up if is_flashing_format?
  25. sign_up(resource_name, resource)
  26. respond_with resource, location: after_sign_up_path_for(resource)
  27. else
  28. set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
  29. expire_data_after_sign_in!
  30. respond_with resource, location: after_inactive_sign_up_path_for(resource)
  31. end
  32. else
  33. clean_up_passwords resource
  34. set_minimum_password_length
  35. respond_with resource
  36. end
  37. end
  38.  
  39. # re-writing the devise update method to provide an ability to change user profile without providing current password
  40. def update
  41. #let devise get on with strong parameters
  42. resource_params = devise_parameter_sanitizer.sanitize(:account_update)
  43.  
  44. if resource_params[:password].blank?
  45. resource_params.delete(:password)
  46. resource_params.delete(:password_confirmation) if params[:password_confirmation].blank?
  47. end
  48.  
  49. @user = current_user
  50.  
  51. LocationService.new(@user, params).create_location
  52. ImagesService.new(@user, params).assign_images
  53.  
  54. if @user.update_attributes(resource_params)
  55. set_flash_message :notice, :updated
  56. # Sign in the user bypassing validation in case his password changed
  57. sign_in @user, :bypass => true
  58.  
  59. redirect_to after_update_path_for(@user)
  60. else
  61. @user = @user.decorate
  62. respond_with @user
  63. #render 'edit'
  64. end
  65. end
  66.  
  67. def destroy
  68. redirect_to root_path, flash: { alert: "Action is not allowed." }
  69. end
  70.  
  71. protected
  72.  
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement