     end
 
     assign(conn, :current_user, user)
+  end
+
+  def require_current_user(%Conn{assigns: %{current_user: %User{}}} = conn, _) do
+    conn
+  end
+  def require_current_user(conn, opts) do
+    msg = Keyword.get(opts, :flash, "Please log in first.")
+
+    conn
+    |> save_return_path
+    |> put_flash(:info, msg)
+    |> redirect(to: "/login/new")
+    |> halt
   end
 
   def log_in(conn, %User{} = user) do

defmodule AsciinemaWeb.Auth do
  import Plug.Conn
  alias Asciinema.Accounts.User
  alias Asciinema.Repo


    opts
  end

  def call(%Conn{assigns: %{current_user: %User{}}} = conn, _opts) do
    conn
  end
  def call(conn, _opts) do
