<commit_before>defmodule Blog.Authenticable do
  import Plug.Conn
  import Phoenix.Controller

  def current_user_id(conn) do
    get_session(conn, :user_id)
  end

  def current_user(conn) do
    id = get_session(conn, :user_id)
    if id do
      Blog.User |> Blog.Repo.get(id)
    end
  end

  def sign_out_user(conn, _ ) do
    delete_session(conn, :user_id)
  end

  def sign_in(conn, %{ id: id }) do
    put_session(conn, :user_id, id)
  end

  def authenticate(conn, :user) do
    unless current_user(conn) do
      conn
      |> put_flash(:alert, "You must be authenticated to proceed")
      |> redirect(to: "/")
      |> halt
    else
      conn
    end
  end
<commit_msg>Redirect users to login page when accessing forbidden link<commit_after>defmodule Blog.Authenticable do
  import Plug.Conn
  import Phoenix.Controller

  def current_user_id(conn) do
    get_session(conn, :user_id)
  end

  def current_user(conn) do
    id = get_session(conn, :user_id)
    if id do
      Blog.User |> Blog.Repo.get(id)
    end
  end

  def sign_out_user(conn, _ ) do
    delete_session(conn, :user_id)
  end

  def sign_in(conn, %{ id: id }) do
    put_session(conn, :user_id, id)
  end

  def authenticate(conn, :user) do
    unless current_user(conn) do
      conn
      |> put_flash(:alert, "You must be authenticated to proceed")
      |> redirect(to: "/users/sign_in")
      |> halt
    else
      conn
    end
  end

{'fraction_non_alphanumeric': 0.09774964838255977, 'fraction_numerical': 0.0, 'mean_word_length': 2.845945945945946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4593619', 'n_tokens_mistral': 518, 'n_tokens_neox': 493, 'n_words': 133}