<commit_before>defmodule Officetournament.UserSessionController do
  use Officetournament.Web, :controller
  require Logger

  alias Officetournament.Login
  alias Officetournament.User

  plug :scrub_params, "login" when action in [:create, :update]

  def index(conn, _params) do
    conn
    |> render("index.html")
  end

  def login(conn, %{"login" => %{"username" => username, "password" => password}}) do
    user = find_user_and_pass(username, password)

    if user do
      conn
      |> put_flash(:info, "Welcome #{user.username}!")
      |> put_session(:current_user_id, user.id)
      |> redirect(to: home_path(conn, :index))
    else
      conn
      |> put_flash(:error, "Username and password not found.")
      |> redirect(to: user_session_path(conn, :index))
    end
  end

  def login(conn, params) do
    conn
    |> put_layout(false)
    |> put_status(401)
    |> render "unauthorized.html"
  end

  def logout(conn, params) do
    conn
    |> clear_session
    |> redirect(to: home_path(conn, :index))
  end

  def find_by_id(user_id) do<commit_msg>Add a logout flash notice<commit_after>defmodule Officetournament.UserSessionController do
  use Officetournament.Web, :controller
  require Logger

  alias Officetournament.Login
  alias Officetournament.User

  plug :scrub_params, "login" when action in [:create, :update]

  def index(conn, _params) do
    conn
    |> render("index.html")
  end

  def login(conn, %{"login" => %{"username" => username, "password" => password}}) do
    user = find_user_and_pass(username, password)

    if user do
      conn
      |> put_flash(:info, "Welcome #{user.username}!")
      |> put_session(:current_user_id, user.id)
      |> redirect(to: home_path(conn, :index))
    else
      conn
      |> put_flash(:error, "Username and password not found.")
      |> redirect(to: user_session_path(conn, :index))
    end
  end

  def login(conn, params) do
    conn
    |> put_layout(false)
    |> put_status(401)
    |> render "unauthorized.html"
  end

  def logout(conn, params) do
    conn
    |> clear_session
    |> put_flash(:info, "You have been logged out.")
    |> redirect(to: home_path(conn, :index))
  end

  def find_by_id(user_id) do
{'fraction_non_alphanumeric': 0.12460353420933394, 'fraction_numerical': 0.002718622564567286, 'mean_word_length': 3.4606060606060605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '4812629', 'n_tokens_mistral': 765, 'n_tokens_neox': 711, 'n_words': 181}