Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def update
- if user_params[:current_email].present?
- if @current_user.has_valid_email?(user_params[:current_email])
- @current_user.update(email: user_params[:new_email])
- else
- render json: {errors: ["Current Email did not match!"]}, status: :unprocessable_entity and return
- end
- end
- if user_params[:current_password].present?
- if @current_user.has_valid_password?(user_params[:current_password])
- @current_user.update(password: user_params[:new_password])
- else
- render json: {errors: ["Current Password did not match!"]}, status: :unprocessable_entity and return
- end
- end
- if @current_user.update(sanitized_params)
- @web_user = @current_user
- render :show
- else
- render json: {errors: @current_user.errors.full_messages}, status: :unprocessable_entity
- end
- end
- private
- def sanitized_params
- user_params.slice!(:current_email,:new_email,:current_password,:new_password)
- end
- def user_params
- params.permit(:current_email, :new_email, :current_password, :new_password, :password_confirmation, :reminders_frequency,
- :coaching_style, :coaching_style_status,:suggestion_preference,:language,:region)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement