2025-02-26 15:06:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class Settings::SubscriptionsController < ApplicationController
|
|
|
|
|
before_action :authenticate_user!
|
2025-04-04 16:16:52 -04:00
|
|
|
before_action :authenticate_non_self_hosted!
|
2025-02-26 15:06:43 -05:00
|
|
|
|
|
|
|
|
def index; end
|
2025-02-27 16:32:03 -05:00
|
|
|
|
|
|
|
|
def subscription_callback
|
|
|
|
|
token = params[:token]
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
decoded_token = JWT.decode(
|
|
|
|
|
token,
|
|
|
|
|
ENV['JWT_SECRET_KEY'],
|
|
|
|
|
true,
|
|
|
|
|
{ algorithm: 'HS256' }
|
|
|
|
|
).first.symbolize_keys
|
|
|
|
|
|
|
|
|
|
unless decoded_token[:user_id] == current_user.id
|
|
|
|
|
redirect_to settings_subscriptions_path, alert: 'Invalid subscription update request.'
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
2025-04-04 16:16:52 -04:00
|
|
|
current_user.update!(status: decoded_token[:status], active_until: decoded_token[:active_until])
|
2025-02-27 16:32:03 -05:00
|
|
|
|
|
|
|
|
redirect_to settings_subscriptions_path, notice: 'Your subscription has been updated successfully!'
|
|
|
|
|
rescue JWT::DecodeError
|
|
|
|
|
redirect_to settings_subscriptions_path, alert: 'Failed to verify subscription update.'
|
|
|
|
|
rescue ArgumentError
|
|
|
|
|
redirect_to settings_subscriptions_path, alert: 'Invalid subscription data received.'
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-02-26 15:06:43 -05:00
|
|
|
end
|