<commit_before>class UsersController < ActionController::API
  include MessagesHelper
  include UsersHelper

  def index
    # Need to revise this. These routes should not be publicly accessible and/or should return a proper response or warning to anyone accessing them.
    render json: "APIs don't have index pages"
  end

  def show
    # Need to revise this. These routes should not be publicly accessible and/or should return a proper response or warning to anyone accessing them.
    user = User.find(1)
    if user.nil?
      render json: "No users here."
    else
      render json: "Found the user."
    end
  end

  def register
    p params
    # if user exists, go to new message page
    # else, make new user, set BCrypt password
    # and return / leave them on login page
    @user = User.new(
      email: params[:email],
      password_hash: params[:password_hash],
      phone_number: params[:phone_number])
      # should this be params[:password_hash]
      # BCrypt is confusing me
    @user.password = params[:password]

    if @user.save
      render json: { success: "user register and saved to database"}
    else
      render json: { error: "user did not save"}
    end
  end

  def login
    # if user exists in DB, return JSON
    # telling client to send user to new_message
    # otherwise, render form error message?
  end

  def send_verification_code
    current_user # This doesn't work right
    set_user_phone

    p params
    if /\+1\d{10}/.match(params[:number])
      set_user_verification_code
      build_and_send_code
    elsif /\d{10}/.match(params[:number])
      set_user_verification_code<commit_msg>change register route back to create (which works but is not RESTful and is kind of misleading), however the login route is not getting hit properly by the front end for some reason<commit_after>class UsersController < ActionController::API
  include MessagesHelper
  include UsersHelper

  def index
    # Need to revise this. These routes should not be publicly accessible and/or should return a proper response or warning to anyone accessing them.
    render json: "APIs don't have index pages"
  end

  def show
    # Need to revise this. These routes should not be publicly accessible and/or should return a proper response or warning to anyone accessing them.
    user = User.find(1)
    if user.nil?
      render json: "No users here."
    else
      render json: "Found the user."
    end
  end

  def create
    # can't make this def register because of Rails
    p params
    # if user exists, go to new message page
    # else, make new user, set BCrypt password
    # and return / leave them on login page
    @user = User.new(
      email: params[:email],
      password_hash: params[:password_hash],
      phone_number: params[:phone_number])
      # should this be params[:password_hash]
      # BCrypt is confusing me
    @user.password = params[:password]

    if @user.save
      render json: { success: "user registered and saved to database"}
    else
      render json: { error: "user did not save"}
    end
  end

  def login
    @user = User.find_by(id: params[:id])
    # id is used to come from local storage
    # need to use some way to pass this info along
    if @user
    render json: { success: "user exists, set to logged in" }
    else
      render json: { error: "user not found, login failed"}
    end
    # if user exists in DB, return JSON
    # telling client to send user to new_message
    # otherwise, render form error message?
  end

  def send_verification_code
    current_user # This doesn't work right
    set_user_phone

    p params
    if /\+1\d{10}/.match(params[:number])
      set_user_verification_code
      build_and_send_code
    elsif /\d{10}/.match(params[:number])
      set_user_verification_code
{'fraction_non_alphanumeric': 0.06859395532194482, 'fraction_numerical': 0.0031537450722733244, 'mean_word_length': 2.9035897435897438, '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': '346939', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1041, 'n_words': 453}