<commit_before>class TokenAuthenticationsController < ApplicationController
  
  before_filter :authenticate_user!, :except => [:new, :create]
  
  def new
  end
  
  def show
    respond_to do |format|
      format.html {
        render
      }
      format.json { 
        render :json => {:auth_key => current_user.authentication_token }, 
          :callback => params[:callback] 
      }
    end
  end
  
  def create
    @user = User.find_by_email(params[:email])
    if @user and @user.valid_password?(params[:password])
      sign_in(:user, @user)
    else
      @user = nil
    end
    respond_to do |format|
      format.html {
        if @user
          current_user.reset_authentication_token!
          redirect_to show_token_authentications_path
        else
          redirect_to new_token_authentication_path, :alert => "incorrect email or password"
        end
      }
      format.json { 
        if @user
          redirect_to show_token_authentications_path({:format => :json})
        else
          render :json => {:error => "incorrect email or password"}, :callback => params[:callback] 
        end
      }
    end
  end

  def destroy
    unless user_signed_in?
      redirect_to new_user_session_path, :error => "you are not signed in, we did not destroy a token"
    end
    current_user.authentication_token = nil
    current_user.save
    redirect_to new_token_authentication_path, :notice => "Your login token is no longer valid"
  end

end<commit_msg>reset tokens on json endpoint as well<commit_after>class TokenAuthenticationsController < ApplicationController
  
  before_filter :authenticate_user!, :except => [:new, :create]
  
  def new
  end
  
  def show
    respond_to do |format|
      format.html {
        render
      }
      format.json { 
        render :json => {:auth_key => current_user.authentication_token }, 
          :callback => params[:callback] 
      }
    end
  end
  
  def create
    @user = User.find_by_email(params[:email])
    if @user and @user.valid_password?(params[:password])
      sign_in(:user, @user)
    else
      @user = nil
    end
    respond_to do |format|
      format.html {
        if @user
          current_user.reset_authentication_token!
          redirect_to show_token_authentications_path
        else
          redirect_to new_token_authentication_path, :alert => "incorrect email or password"
        end
      }
      format.json { 
        if @user
          current_user.reset_authentication_token!
          redirect_to show_token_authentications_path({:format => :json})
        else
          render :json => {:error => "incorrect email or password"}, :callback => params[:callback] 
        end
      }
    end
  end

  def destroy
    unless user_signed_in?
      redirect_to new_user_session_path, :error => "you are not signed in, we did not destroy a token"
    end
    current_user.authentication_token = nil
    current_user.save
    redirect_to new_token_authentication_path, :notice => "Your login token is no longer valid"
  end

end
{'fraction_non_alphanumeric': 0.08155212101282473, 'fraction_numerical': 0.0, 'mean_word_length': 2.508650519031142, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '3828081', 'n_tokens_mistral': 904, 'n_tokens_neox': 881, 'n_words': 230}