Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. def update
  2. if user_params[:current_email].present?
  3. if @current_user.has_valid_email?(user_params[:current_email])
  4. @current_user.update(email: user_params[:new_email])
  5. else
  6. render json: {errors: ["Current Email did not match!"]}, status: :unprocessable_entity and return
  7. end
  8. end
  9. if user_params[:current_password].present?
  10. if @current_user.has_valid_password?(user_params[:current_password])
  11. @current_user.update(password: user_params[:new_password])
  12. else
  13. render json: {errors: ["Current Password did not match!"]}, status: :unprocessable_entity and return
  14. end
  15. end
  16. if @current_user.update(sanitized_params)
  17. @web_user = @current_user
  18. render :show
  19. else
  20. render json: {errors: @current_user.errors.full_messages}, status: :unprocessable_entity
  21. end
  22. end
  23.  
  24.  
  25.  
  26.  
  27. private
  28.  
  29. def sanitized_params
  30. user_params.slice!(:current_email,:new_email,:current_password,:new_password)
  31. end
  32.  
  33. def user_params
  34. params.permit(:current_email, :new_email, :current_password, :new_password, :password_confirmation, :reminders_frequency,
  35. :coaching_style, :coaching_style_status,:suggestion_preference,:language,:region)
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement