<commit_before>
class Facebooked::AppRenderer < ParagraphRenderer

  features '/facebooked/app_feature'

  paragraph :login

  def login
    return render_paragraph :text => 'Facebook Application Login' if editor?
    return render_paragraph :nothing => true if self.logged_in?
    data_paragraph :type => 'text/html', :text => login_html
  end

  protected

  def logged_in?
    if params[:signed_request]
      signed_request = Facebooked::SignedRequest.new params[:signed_request]
      if ! signed_request.valid? || signed_request.user_id.nil? || self.provider.provider_id.nil? || signed_request.user_id != self.provider.provider_id
        self.process_logout
        return false
      end
    end

    self.provider.logged_in?
  end

  def provider
    @provider ||= Facebooked::OauthProvider.new session
  end

  def login_html
    <<-LOGIN
<html>
<head>
<script type="text/javascript">
top.location = "#{url_for :controller => '/facebooked/client', :action => 'login'}";
</script>
</head>
</html>
    LOGIN
  end
end<commit_msg>redirect user to the page they originally requested<commit_after>
class Facebooked::AppRenderer < ParagraphRenderer

  features '/facebooked/app_feature'

  paragraph :login

  def login
    return render_paragraph :text => 'Facebook Application Login' if editor?

    if self.logged_in?
      return render_paragraph(:nothing => true) unless session[:lock_lockout]

      lock_lockout = session[:lock_lockout]
      session[:lock_lockout] = nil
      return render_paragraph(:nothing => true) if self.lock_lockout_url == lock_lockout

      return redirect_paragraph lock_lockout
    end

    session[:lock_lockout] = self.lock_lockout_url
    data_paragraph :type => 'text/html', :text => login_html
  end

  protected

  def logged_in?
    if params[:signed_request]
      # make sure the signed_request user and the user logged in with oauth are the same user
      signed_request = Facebooked::SignedRequest.new params[:signed_request]
      return false unless signed_request.valid? && signed_request.user_id && self.provider.logged_in? && self.provider.provider_id && signed_request.user_id == self.provider.provider_id
    end

    self.provider.logged_in?
  end

  def provider
    @provider ||= Facebooked::OauthProvider.new session
  end

  def login_html
    <<-LOGIN
<html>
<head>
<script type="text/javascript">
top.location = "#{url_for :controller => '/facebooked/client', :action => 'login'}";
</script>
</head>
</html>
    LOGIN
  end

  # removes the signed_request from the url
  def lock_lockout_url
    url = request.request_uri
    url, query = url.split '?'
    query = query.split('&').map { |p| p.match(/^signed_request=/) ? nil : p }.compact.join('&') unless query.blank?
    url = "#{url}?#{query}" unless query.blank?
    url
  end
end
{'fraction_non_alphanumeric': 0.111745805069618, 'fraction_numerical': 0.0, 'mean_word_length': 3.831034482758621, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5096229', 'n_tokens_mistral': 871, 'n_tokens_neox': 842, 'n_words': 218}