<commit_before># Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

require 'user_system'

class ApplicationController < ActionController::Base

  include UserSystem
  helper :user
  #model :user

  layout 'main'

  before_filter :set_charset, :load_current_user, :check_flashes
  after_filter  :fix_unicode_for_safari, :store_location

  def page_not_found
    if params[:controller] == 'page' and @current_user.has_create_permission?
      flash[:notice] = 'Sidan finns inte, du får skapa den'
      redirect_to page_new_url(:id => params[:id])
    else
      headers["Code"] = 404
      flash[:error] = 'Sidan hittades inte.'
      redirect_to page_list_url(:id => nil)
    end
  end

  def permission_denied
    access_denied
  end

  def logged_in?
    @current_user.real?
  end
  helper_method :logged_in?

  def registration_available?
    WikiConf['user']['registration']
  end
  helper_method :registration_available?

  def default_url_options(options)
    { :protocol => WikiConf['main']['default_protocol'] }
  end

  def load_current_user
    if session[:user_login] or cookies[:cookie_token]
      user = User.find_by_login(session[:user_login]) || User.find_by_cookie_token(cookies[:cookie_token])
      if user and not session[:user_login] # Then it was a cookie login
        session[:user_login] = user.login
        user.update_attribute(:last_login, Time.now)
        user.update_attribute(:ip, request.remote_ip.split(',').first)
      end
      
      if user.nil? # Kick out the user and make him a guest
        session[:user_login] = nil
        cookies.delete :cookie_token
        user = Guest.new(:ip => request.remote_ip.split(',').first)
        flash[:error] = 'Du finns inte med i systemet, adjö!'
        flash[:logout] = true
        redirect_back_or_default index_url
      end
    else
      user = Guest.new(:ip => request.remote_ip.split(',').first)
    end
    
    @current_user = user
  end

  def xhr_call
    request.xhr?<commit_msg>Rails 2.x will not give options<commit_after># Filters added to this controller will be run for all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

require 'user_system'

class ApplicationController < ActionController::Base

  include UserSystem
  helper :user
  #model :user

  layout 'main'

  before_filter :set_charset, :load_current_user, :check_flashes
  after_filter  :fix_unicode_for_safari, :store_location

  def page_not_found
    if params[:controller] == 'page' and @current_user.has_create_permission?
      flash[:notice] = 'Sidan finns inte, du får skapa den'
      redirect_to page_new_url(:id => params[:id])
    else
      headers["Code"] = 404
      flash[:error] = 'Sidan hittades inte.'
      redirect_to page_list_url(:id => nil)
    end
  end

  def permission_denied
    access_denied
  end

  def logged_in?
    @current_user.real?
  end
  helper_method :logged_in?

  def registration_available?
    WikiConf['user']['registration']
  end
  helper_method :registration_available?

  def default_url_options(options=nil)
    { :protocol => WikiConf['main']['default_protocol'] }
  end

  def load_current_user
    if session[:user_login] or cookies[:cookie_token]
      user = User.find_by_login(session[:user_login]) || User.find_by_cookie_token(cookies[:cookie_token])
      if user and not session[:user_login] # Then it was a cookie login
        session[:user_login] = user.login
        user.update_attribute(:last_login, Time.now)
        user.update_attribute(:ip, request.remote_ip.split(',').first)
      end
      
      if user.nil? # Kick out the user and make him a guest
        session[:user_login] = nil
        cookies.delete :cookie_token
        user = Guest.new(:ip => request.remote_ip.split(',').first)
        flash[:error] = 'Du finns inte med i systemet, adjö!'
        flash[:logout] = true
        redirect_back_or_default index_url
      end
    else
      user = Guest.new(:ip => request.remote_ip.split(',').first)
    end
    
    @current_user = user
  end

  def xhr_call
    request.xhr?
{'fraction_non_alphanumeric': 0.09785202863961814, 'fraction_numerical': 0.0016706443914081145, 'mean_word_length': 3.4537725823591923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '336923', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1284, 'n_words': 336}