<commit_before>class Muck::UserSessionsController < ApplicationController
  
  ssl_required :new, :create
  before_filter :login_required, :only => :destroy
  before_filter :not_logged_in_required, :only => [:new, :create]
  
  def show
    if logged_in?
      redirect_to current_user
    else
      flash[:notice] = t('muck.users.login_fail')
      redirect_to login_path
    end
  end
  
  def new
    @title = t('muck.users.sign_in_title')
    @user_session = UserSession.new
    respond_to do |format|
      format.html { render :template => 'user_sessions/new' }
    end
  end
  
  def create
    @title = t('muck.users.sign_in_title')    
    @user_session = UserSession.new(params[:user_session])
    if success = before_create_user_session
      @user_session.save do |result|
        success = result
      end
    end
    success = after_create_user_session(success)
    after_create_response(success)
  end
  
  def destroy
    @title = t('muck.users.sign_out_title')
    before_destroy_user_session
    current_user.reset_single_access_token! if params[:reset_api_key]
    current_user_session.destroy
    flash[:notice] = t('muck.users.login_out_success')
    after_destroy_user_session
    respond_to do |format|
      format.html { redirect_to logout_complete_path }
      format.json { render :json => { :logged_in => false, :message => t('muck.users.login_out_success') } }
    end
  end
  
  def login_check
    render :json => { :logged_in => logged_in? }
  end
  
  protected
  
    # Override to act on @user_session before it is created
    def before_create_user_session
      true
    end
    
    # Override to act on @user_session after it is created
    # success indicates whether or not the user was successfully created
    def after_create_user_session(success)
      success
    end
    
    # Override to act on @user_session before it is destroyed
    def before_destroy_user_session
    end
    
    # Override to act on @user_session after it is destroyed
    def after_destroy_user_session
    end
    
    def after_create_response(success)
      if success
        respond_to do |format|
          format.html do
            flash[:notice] = t('muck.users.login_success')            
            redirect_back_or_default(user_path(@user_session.user))
          end
          format.json { render :json => { :logged_in => true, :message => t('muck.users.login_success'), :user => @user_session.to_json } }
        end
      else
        respond_to do |format|
          format.html do
            flash[:notice] = t('muck.users.login_fail')
            render :template => 'user_sessions/new'
          end
          format.json { render :json => { :logged_in => false, :message => t('muck.users.login_fail') } }
        end
      end
      success
    end
  <commit_msg>Fixed to_json for user session controller<commit_after>class Muck::UserSessionsController < ApplicationController
  
  ssl_required :new, :create
  before_filter :login_required, :only => :destroy
  before_filter :not_logged_in_required, :only => [:new, :create]
  
  def show
    if logged_in?
      redirect_to current_user
    else
      flash[:notice] = t('muck.users.login_fail')
      redirect_to login_path
    end
  end
  
  def new
    @title = t('muck.users.sign_in_title')
    @user_session = UserSession.new
    respond_to do |format|
      format.html { render :template => 'user_sessions/new' }
    end
  end
  
  def create
    @title = t('muck.users.sign_in_title')    
    @user_session = UserSession.new(params[:user_session])
    if success = before_create_user_session
      @user_session.save do |result|
        success = result
      end
    end
    success = after_create_user_session(success)
    after_create_response(success)
  end
  
  def destroy
    @title = t('muck.users.sign_out_title')
    before_destroy_user_session
    current_user.reset_single_access_token! if params[:reset_api_key]
    current_user_session.destroy
    flash[:notice] = t('muck.users.login_out_success')
    after_destroy_user_session
    respond_to do |format|
      format.html { redirect_to logout_complete_path }
      format.json { render :json => { :logged_in => false, :message => t('muck.users.login_out_success') } }
    end
  end
  
  def login_check
    render :json => { :logged_in => logged_in? }
  end
  
  protected
  
    # Override to act on @user_session before it is created
    def before_create_user_session
      true
    end
    
    # Override to act on @user_session after it is created
    # success indicates whether or not the user was successfully created
    def after_create_user_session(success)
      success
    end
    
    # Override to act on @user_session before it is destroyed
    def before_destroy_user_session
    end
    
    # Override to act on @user_session after it is destroyed
    def after_destroy_user_session
    end
    
    def after_create_response(success)
      if success
        respond_to do |format|
          format.html do
            flash[:notice] = t('muck.users.login_success')            
            redirect_back_or_default(user_path(@user_session.user))
          end
          format.json { render :json => { :logged_in => true, :message => t('muck.users.login_success'), :user => @user_session.user } }
        end
      else
        respond_to do |format|
          format.html do
            flash[:notice] = t('muck.users.login_fail')
            render :template => 'user_sessions/new'
          end
          format.json { render :json => { :logged_in => false, :message => t('muck.users.login_fail') } }
        end
      end
      success
    end
  
{'fraction_non_alphanumeric': 0.08606339649371347, 'fraction_numerical': 0.0, 'mean_word_length': 2.6915032679738564, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '4433705', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1741, 'n_words': 413}