<commit_before># frozen_string_literal: true

class Api::UsersController < ApiController
  def sign_up
    user = create_user
    if user
      render json: user
    else
      render_400 'Invalid params'
    end
  end

  def sign_in
    user = User.find_by(email: params[:email])
    if user.valid_password?(params[:password])
      render json: user
    else
      render_400
    end
  end

  def sign_out
    user = User.find_by(authentication_token: params[:token])
    user.delete_authentication_token
    render json: { message: 'success', status: 200 }, status: 200
  rescue
    render_400 'Invalid params'
  end

  private

  def create_user
    user = User.find_by(email: params[:email])
    return false unless user.nil?
    user = User.new(
      email: params['email'],
      password: params['password'],
      password_confirmation: params['password_confirmation']
    )
    user.save!
    user.ensure_authentication_token
    user
  rescue
    false
  end
end
<commit_msg>Fixed to failure sign in when already created user.<commit_after># frozen_string_literal: true

class Api::UsersController < ApiController
  def sign_up
    user = create_user
    if user
      render json: user
    else
      render_400 'Invalid params'
    end
  end

  def sign_in
    user = User.find_by(email: params[:email])
    if user&.valid_password?(params[:password]) || false
      render json: user
    else
      render_400
    end
  end

  def sign_out
    user = User.find_by(authentication_token: params[:token])
    user.delete_authentication_token
    render json: { message: 'success', status: 200 }, status: 200
  rescue
    render_400 'Invalid params'
  end

  private

  def create_user
    user = User.find_by(email: params[:email])
    return false unless user.nil?
    user = User.new(
      email: params['email'],
      password: params['password'],
      password_confirmation: params['password_confirmation']
    )
    user.save!
    user.ensure_authentication_token
    user
  rescue
    false
  end
end

{'fraction_non_alphanumeric': 0.0840751730959446, 'fraction_numerical': 0.01483679525222552, 'mean_word_length': 3.013888888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1545261', 'n_tokens_mistral': 636, 'n_tokens_neox': 613, 'n_words': 167}