Update directory structure to Phoenix 1.3 layout

phx13
Marcin Kulik 7 years ago
parent f249d4a276
commit ea8d1c9b40

1
assets/.gitignore vendored

@ -0,0 +1 @@
/node_modules

@ -14,8 +14,8 @@ exports.config = {
// To change the order of concatenation of files, explicitly mention here // To change the order of concatenation of files, explicitly mention here
order: { order: {
before: [ before: [
"web/static/vendor/js/jquery-2.2.4.min.js", "vendor/js/jquery-2.2.4.min.js",
"web/static/vendor/js/bootstrap.js" "vendor/js/bootstrap.js"
] ]
} }
}, },
@ -23,19 +23,19 @@ exports.config = {
joinTo: "css/app.css", joinTo: "css/app.css",
order: { order: {
before: [ before: [
"web/static/vendor/css/bootstrap.css", "vendor/css/bootstrap.css",
"web/static/css/source-sans-pro.css", "css/source-sans-pro.css",
"web/static/css/base.sass", "css/base.sass",
"web/static/css/header.sass", "css/header.sass",
"web/static/css/flash.sass", "css/flash.sass",
"web/static/css/footer.sass", "css/footer.sass",
"web/static/css/home.sass", "css/home.sass",
"web/static/css/asciicasts.sass", "css/asciicasts.sass",
"web/static/css/users.sass", "css/users.sass",
"web/static/css/preview.sass", "css/preview.sass",
"web/static/css/player.sass", "css/player.sass",
"web/static/css/contributing.sass", "css/contributing.sass",
"web/static/css/simple-layout.sass", "css/simple-layout.sass",
] ]
} }
}, },
@ -46,34 +46,31 @@ exports.config = {
conventions: { conventions: {
// This option sets where we should place non-css and non-js assets in. // This option sets where we should place non-css and non-js assets in.
// By default, we set this to "/web/static/assets". Files in this directory // By default, we set this to "/assets/static". Files in this directory
// will be copied to `paths.public`, which is "priv/static" by default. // will be copied to `paths.public`, which is "priv/static" by default.
assets: /^(web\/static\/assets)/ assets: /^(static)/
}, },
// Phoenix paths configuration // Phoenix paths configuration
paths: { paths: {
// Dependencies and current project directories to watch // Dependencies and current project directories to watch
watched: [ watched: ["static", "css", "js", "vendor"],
"web/static",
"test/static"
],
// Where to compile files to // Where to compile files to
public: "priv/static" public: "../priv/static"
}, },
// Configure your plugins // Configure your plugins
plugins: { plugins: {
babel: { babel: {
// Do not use ES6 compiler in vendor code // Do not use ES6 compiler in vendor code
ignore: [/web\/static\/vendor/] ignore: [/vendor/]
} }
}, },
modules: { modules: {
autoRequire: { autoRequire: {
"js/app.js": ["web/static/js/app"] "js/app.js": ["js/app"]
} }
}, },

@ -6,16 +6,16 @@
"watch": "brunch watch --stdin" "watch": "brunch watch --stdin"
}, },
"dependencies": { "dependencies": {
"phoenix": "file:deps/phoenix", "phoenix": "file:../deps/phoenix",
"phoenix_html": "file:deps/phoenix_html" "phoenix_html": "file:../deps/phoenix_html"
}, },
"devDependencies": { "devDependencies": {
"babel-brunch": "~6.0.0", "babel-brunch": "6.0.6",
"brunch": "2.7.4", "brunch": "2.10.7",
"clean-css-brunch": "~2.0.0", "clean-css-brunch": "2.10.0",
"css-brunch": "~2.0.0", "css-brunch": "~2.0.0",
"sass-brunch": "^2.6.3", "sass-brunch": "^2.6.3",
"javascript-brunch": "~2.0.0", "javascript-brunch": "~2.0.0",
"uglify-js-brunch": "~2.0.1" "uglify-js-brunch": "2.1.1"
} }
} }

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Before

Width:  |  Height:  |  Size: 768 B

After

Width:  |  Height:  |  Size: 768 B

Before

Width:  |  Height:  |  Size: 188 KiB

After

Width:  |  Height:  |  Size: 188 KiB

Before

Width:  |  Height:  |  Size: 731 B

After

Width:  |  Height:  |  Size: 731 B

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

@ -10,10 +10,10 @@ config :asciinema,
ecto_repos: [Asciinema.Repo] ecto_repos: [Asciinema.Repo]
# Configures the endpoint # Configures the endpoint
config :asciinema, Asciinema.Endpoint, config :asciinema, AsciinemaWeb.Endpoint,
url: [host: "localhost"], url: [host: "localhost"],
secret_key_base: System.get_env("SECRET_KEY_BASE"), secret_key_base: System.get_env("SECRET_KEY_BASE"),
render_errors: [view: Asciinema.ErrorView, accepts: ~w(html json)], render_errors: [view: AsciinemaWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: Asciinema.PubSub, pubsub: [name: Asciinema.PubSub,
adapter: Phoenix.PubSub.PG2] adapter: Phoenix.PubSub.PG2]

@ -6,24 +6,24 @@ use Mix.Config
# The watchers configuration can be used to run external # The watchers configuration can be used to run external
# watchers to your application. For example, we use it # watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources. # with brunch.io to recompile .js and .css sources.
config :asciinema, Asciinema.Endpoint, config :asciinema, AsciinemaWeb.Endpoint,
http: [port: 4000], http: [port: 4000],
debug_errors: true, debug_errors: true,
code_reloader: true, code_reloader: true,
check_origin: false, check_origin: false,
secret_key_base: System.get_env("SECRET_KEY_BASE") || "60BnXnzGGwwiZj91YA9XYKF9BCiM7lQ/1um8VXcWWLSdUp9OcPZV6YnQv7eFTYSY", secret_key_base: System.get_env("SECRET_KEY_BASE") || "60BnXnzGGwwiZj91YA9XYKF9BCiM7lQ/1um8VXcWWLSdUp9OcPZV6YnQv7eFTYSY",
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin", watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
cd: Path.expand("../", __DIR__)]] cd: Path.expand("../assets", __DIR__)]]
# Watch static and templates for browser reloading. # Watch static and templates for browser reloading.
config :asciinema, Asciinema.Endpoint, config :asciinema, AsciinemaWeb.Endpoint,
live_reload: [ live_reload: [
patterns: [ patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$}, ~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{priv/gettext/.*(po)$}, ~r{priv/gettext/.*(po)$},
~r{web/views/.*(ex)$}, ~r{lib/asciinema_web/views/.*(ex)$},
~r{web/templates/.*(eex|md)$} ~r{lib/asciinema_web/templates/.*(eex|md)$}
] ]
] ]

@ -11,7 +11,7 @@ use Mix.Config
# containing the digested version of static files. This # containing the digested version of static files. This
# manifest is generated by the mix phoenix.digest task # manifest is generated by the mix phoenix.digest task
# which you typically run after static files are built. # which you typically run after static files are built.
config :asciinema, Asciinema.Endpoint, config :asciinema, AsciinemaWeb.Endpoint,
http: [port: {:system, "PORT"}], http: [port: {:system, "PORT"}],
url: [scheme: System.get_env("URL_SCHEME") || "https", url: [scheme: System.get_env("URL_SCHEME") || "https",
host: System.get_env("URL_HOST") || "asciinema.org", host: System.get_env("URL_HOST") || "asciinema.org",
@ -26,7 +26,7 @@ config :logger, level: :info
# To get SSL working, you will need to add the `https` key # To get SSL working, you will need to add the `https` key
# to the previous section and set your `:url` port to 443: # to the previous section and set your `:url` port to 443:
# #
# config :asciinema, Asciinema.Endpoint, # config :asciinema, AsciinemaWeb.Endpoint,
# ... # ...
# url: [host: "example.com", port: 443], # url: [host: "example.com", port: 443],
# https: [port: 443, # https: [port: 443,
@ -40,7 +40,7 @@ config :logger, level: :info
# We also recommend setting `force_ssl`, ensuring no data is # We also recommend setting `force_ssl`, ensuring no data is
# ever sent via http, always redirecting to https: # ever sent via http, always redirecting to https:
# #
# config :asciinema, Asciinema.Endpoint, # config :asciinema, AsciinemaWeb.Endpoint,
# force_ssl: [hsts: true] # force_ssl: [hsts: true]
# #
# Check `Plug.SSL` for all available options in `force_ssl`. # Check `Plug.SSL` for all available options in `force_ssl`.
@ -55,7 +55,7 @@ config :logger, level: :info
# Alternatively, you can configure exactly which server to # Alternatively, you can configure exactly which server to
# start per endpoint: # start per endpoint:
# #
# config :asciinema, Asciinema.Endpoint, server: true # config :asciinema, AsciinemaWeb.Endpoint, server: true
# #
config :asciinema, Asciinema.Repo, config :asciinema, Asciinema.Repo,

@ -2,7 +2,7 @@ use Mix.Config
# We don't run a server during test. If one is required, # We don't run a server during test. If one is required,
# you can enable the server option below. # you can enable the server option below.
config :asciinema, Asciinema.Endpoint, config :asciinema, AsciinemaWeb.Endpoint,
http: [port: 4001], http: [port: 4001],
secret_key_base: "ssecretkeybasesecretkeybasesecretkeybasesecretkeybaseecretkeybase", secret_key_base: "ssecretkeybasesecretkeybasesecretkeybasesecretkeybaseecretkeybase",
server: false server: false

@ -1,4 +1,4 @@
defmodule Asciinema do defmodule Asciinema.Application do
use Application use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html # See http://elixir-lang.org/docs/stable/elixir/Application.html
@ -13,7 +13,7 @@ defmodule Asciinema do
# Start the Ecto repository # Start the Ecto repository
supervisor(Asciinema.Repo, []), supervisor(Asciinema.Repo, []),
# Start the endpoint when the application starts # Start the endpoint when the application starts
supervisor(Asciinema.Endpoint, []), supervisor(AsciinemaWeb.Endpoint, []),
# Start your own worker by calling: Asciinema.Worker.start_link(arg1, arg2, arg3) # Start your own worker by calling: Asciinema.Worker.start_link(arg1, arg2, arg3)
# worker(Asciinema.Worker, [arg1, arg2, arg3]), # worker(Asciinema.Worker, [arg1, arg2, arg3]),
:poolboy.child_spec(:worker, Asciinema.PngGenerator.A2png.poolboy_config(), []), :poolboy.child_spec(:worker, Asciinema.PngGenerator.A2png.poolboy_config(), []),
@ -27,11 +27,4 @@ defmodule Asciinema do
opts = [strategy: :one_for_one, name: Asciinema.Supervisor] opts = [strategy: :one_for_one, name: Asciinema.Supervisor]
Supervisor.start_link(children, opts) Supervisor.start_link(children, opts)
end end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
Asciinema.Endpoint.config_change(changed, removed)
:ok
end
end end

@ -1,6 +1,8 @@
defmodule Asciinema.Asciicast do defmodule Asciinema.Asciicasts.Asciicast do
use Asciinema.Web, :model use Ecto.Schema
alias Asciinema.{User, Asciicast} import Ecto.Changeset
alias Asciinema.Users.User
alias Asciinema.Asciicasts.Asciicast
alias Asciinema.PngGenerator.PngParams alias Asciinema.PngGenerator.PngParams
@default_png_scale 2 @default_png_scale 2

@ -1,7 +1,7 @@
defmodule Asciinema.Asciicasts do defmodule Asciinema.Asciicasts do
import Ecto.Query, warn: false import Ecto.Query, warn: false
alias Asciinema.{Repo, Asciicast, FileStore, StringUtils, Vt} alias Asciinema.{Repo, FileStore, StringUtils, Vt}
alias Asciinema.Asciicasts.{SnapshotUpdater, FramesGenerator} alias Asciinema.Asciicasts.{Asciicast, SnapshotUpdater, FramesGenerator}
def get_asciicast!(id) when is_integer(id) do def get_asciicast!(id) when is_integer(id) do
Repo.get!(Asciicast, id) Repo.get!(Asciicast, id)

@ -1,5 +1,5 @@
defmodule Asciinema.Asciicasts.FramesGenerator do defmodule Asciinema.Asciicasts.FramesGenerator do
alias Asciinema.Asciicast alias Asciinema.Asciicasts.Asciicast
@doc "Generates frames file for given asciicast" @doc "Generates frames file for given asciicast"
@callback generate_frames(asciicast :: %Asciicast{}) :: :ok | {:error, term} @callback generate_frames(asciicast :: %Asciicast{}) :: :ok | {:error, term}

@ -1,5 +1,5 @@
defmodule Asciinema.Asciicasts.FramesGenerator.Sidekiq do defmodule Asciinema.Asciicasts.FramesGenerator.Sidekiq do
alias Asciinema.Asciicast alias Asciinema.Asciicasts.Asciicast
alias Asciinema.SidekiqClient alias Asciinema.SidekiqClient
def generate_frames(%Asciicast{id: id}) do def generate_frames(%Asciicast{id: id}) do

@ -1,5 +1,5 @@
defmodule Asciinema.Asciicasts.SnapshotUpdater do defmodule Asciinema.Asciicasts.SnapshotUpdater do
alias Asciinema.Asciicast alias Asciinema.Asciicasts.Asciicast
@doc "Generates poster for given asciicast" @doc "Generates poster for given asciicast"
@callback update_snapshot(asciicast :: %Asciicast{}) :: :ok | {:error, term} @callback update_snapshot(asciicast :: %Asciicast{}) :: :ok | {:error, term}

@ -1,5 +1,6 @@
defmodule Asciinema.Asciicasts.SnapshotUpdater.Exq do defmodule Asciinema.Asciicasts.SnapshotUpdater.Exq do
alias Asciinema.{Repo, Asciicasts, Asciicast} alias Asciinema.{Repo, Asciicasts}
alias Asciinema.Asciicasts.Asciicast
def update_snapshot(%Asciicast{id: id}) do def update_snapshot(%Asciicast{id: id}) do
{:ok, _jid} = Exq.enqueue(Exq, "default", __MODULE__, [id]) {:ok, _jid} = Exq.enqueue(Exq, "default", __MODULE__, [id])

@ -1,5 +1,6 @@
defmodule Asciinema.Asciicasts.SnapshotUpdater.Sync do defmodule Asciinema.Asciicasts.SnapshotUpdater.Sync do
alias Asciinema.{Asciicast, Asciicasts} alias Asciinema.Asciicasts
alias Asciinema.Asciicasts.Asciicast
def update_snapshot(%Asciicast{} = asciicast) do def update_snapshot(%Asciicast{} = asciicast) do
{:ok, _} = Asciicasts.update_snapshot(asciicast) {:ok, _} = Asciicasts.update_snapshot(asciicast)

@ -1,5 +1,5 @@
defmodule Asciinema.Email do defmodule Asciinema.Email do
use Bamboo.Phoenix, view: Asciinema.EmailView use Bamboo.Phoenix, view: AsciinemaWeb.EmailView
import Bamboo.Email import Bamboo.Email
def signup_email(email_address, signup_url) do def signup_email(email_address, signup_url) do

@ -1,5 +1,5 @@
defmodule Asciinema.PngGenerator do defmodule Asciinema.PngGenerator do
alias Asciinema.Asciicast alias Asciinema.Asciicasts.Asciicast
alias Asciinema.PngGenerator.PngParams alias Asciinema.PngGenerator.PngParams
@doc "Generates PNG image from asciicast and returns path to it" @doc "Generates PNG image from asciicast and returns path to it"

@ -1,7 +1,7 @@
defmodule Asciinema.PngGenerator.A2png do defmodule Asciinema.PngGenerator.A2png do
@behaviour Asciinema.PngGenerator @behaviour Asciinema.PngGenerator
use GenServer use GenServer
alias Asciinema.Asciicast alias Asciinema.Asciicasts.Asciicast
alias Asciinema.PngGenerator.PngParams alias Asciinema.PngGenerator.PngParams
@pool_name :worker @pool_name :worker

@ -1,6 +1,7 @@
defmodule Asciinema.ApiToken do defmodule Asciinema.Users.ApiToken do
use Asciinema.Web, :model use Ecto.Schema
alias Asciinema.{ApiToken, User} import Ecto.Changeset
alias Asciinema.Users.{ApiToken, User}
schema "api_tokens" do schema "api_tokens" do
field :token, :string field :token, :string
@ -8,7 +9,7 @@ defmodule Asciinema.ApiToken do
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at)
belongs_to :user, Asciinema.User belongs_to :user, User
end end
@uuid4 ~r/\A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\z/ @uuid4 ~r/\A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\z/

@ -1,6 +1,7 @@
defmodule Asciinema.User do defmodule Asciinema.Users.User do
use Asciinema.Web, :model use Ecto.Schema
alias Asciinema.User import Ecto.Changeset
alias Asciinema.Users.User
@valid_email_re ~r/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i @valid_email_re ~r/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i
@ -16,8 +17,8 @@ defmodule Asciinema.User do
timestamps(inserted_at: :created_at) timestamps(inserted_at: :created_at)
has_many :asciicasts, Asciinema.Asciicast has_many :asciicasts, Asciinema.Asciicasts.Asciicast
has_many :api_tokens, Asciinema.ApiToken has_many :api_tokens, Asciinema.Users.ApiToken
end end
def changeset(struct, params \\ %{}) do def changeset(struct, params \\ %{}) do

@ -1,7 +1,8 @@
defmodule Asciinema.Users do defmodule Asciinema.Users do
import Ecto.Query, warn: false import Ecto.Query, warn: false
import Ecto, only: [assoc: 2] import Ecto, only: [assoc: 2]
alias Asciinema.{Repo, User, ApiToken, Asciicasts, Email, Mailer, Auth} alias Asciinema.Users.{User, ApiToken}
alias Asciinema.{Repo, Asciicasts, Email, Mailer}
def create_asciinema_user!() do def create_asciinema_user!() do
attrs = %{username: "asciinema", attrs = %{username: "asciinema",
@ -80,20 +81,20 @@ defmodule Asciinema.Users do
end end
defp signup_url(email) do defp signup_url(email) do
token = Phoenix.Token.sign(Asciinema.Endpoint, "signup", email) token = Phoenix.Token.sign(AsciinemaWeb.Endpoint, "signup", email)
Asciinema.Router.Helpers.users_url(Asciinema.Endpoint, :new, t: token) AsciinemaWeb.Router.Helpers.users_url(AsciinemaWeb.Endpoint, :new, t: token)
end end
defp login_url(%User{id: id, last_login_at: last_login_at}) do defp login_url(%User{id: id, last_login_at: last_login_at}) do
last_login_at = last_login_at && Timex.to_unix(last_login_at) last_login_at = last_login_at && Timex.to_unix(last_login_at)
token = Phoenix.Token.sign(Asciinema.Endpoint, "login", {id, last_login_at}) token = Phoenix.Token.sign(AsciinemaWeb.Endpoint, "login", {id, last_login_at})
Asciinema.Router.Helpers.session_url(Asciinema.Endpoint, :new, t: token) AsciinemaWeb.Router.Helpers.session_url(AsciinemaWeb.Endpoint, :new, t: token)
end end
@login_token_max_age 15 * 60 # 15 minutes @login_token_max_age 15 * 60 # 15 minutes
alias Phoenix.Token alias Phoenix.Token
alias Asciinema.Endpoint alias AsciinemaWeb.Endpoint
def verify_signup_token(token) do def verify_signup_token(token) do
with {:ok, email} <- Token.verify(Endpoint, "signup", token, max_age: @login_token_max_age), with {:ok, email} <- Token.verify(Endpoint, "signup", token, max_age: @login_token_max_age),
@ -124,11 +125,6 @@ defmodule Asciinema.Users do
end end
end end
def log_in(conn, %User{} = user) do
user = user |> User.login_changeset |> Repo.update!
Auth.login(conn, user)
end
def authenticate(api_token) do def authenticate(api_token) do
q = from u in User, q = from u in User,
join: at in ApiToken, join: at in ApiToken,

@ -1,12 +1,12 @@
defmodule Asciinema.Web do defmodule AsciinemaWeb do
@moduledoc """ @moduledoc """
A module that keeps using definitions for controllers, A module that keeps using definitions for controllers,
views and so on. views and so on.
This can be used in your application as: This can be used in your application as:
use Asciinema.Web, :controller use AsciinemaWeb, :controller
use Asciinema.Web, :view use AsciinemaWeb, :view
The definitions below will be executed for every view, The definitions below will be executed for every view,
controller, etc, so keep them short and clean, focused controller, etc, so keep them short and clean, focused
@ -16,35 +16,25 @@ defmodule Asciinema.Web do
below. below.
""" """
def model do
quote do
use Ecto.Schema
@timestamps_opts inserted_at: :created_at
import Ecto
import Ecto.Changeset
import Ecto.Query
end
end
def controller do def controller do
quote do quote do
use Phoenix.Controller use Phoenix.Controller, namespace: AsciinemaWeb
alias Asciinema.Repo alias Asciinema.Repo
import Ecto import Ecto
import Ecto.Query import Ecto.Query
import Asciinema.Router.Helpers import AsciinemaWeb.Router.Helpers
import Asciinema.Router.Helpers.Extra import AsciinemaWeb.Router.Helpers.Extra
import Asciinema.Gettext import AsciinemaWeb.Gettext
import Asciinema.Rails.Flash import AsciinemaWeb.Rails.Flash
end end
end end
def view do def view do
quote do quote do
use Phoenix.View, root: "web/templates" use Phoenix.View, root: "lib/asciinema_web/templates",
namespace: AsciinemaWeb
# Import convenience functions from controllers # Import convenience functions from controllers
import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1] import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1]
@ -52,10 +42,10 @@ defmodule Asciinema.Web do
# Use all HTML functionality (forms, tags, etc) # Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML use Phoenix.HTML
import Asciinema.Router.Helpers import AsciinemaWeb.Router.Helpers
import Asciinema.Router.Helpers.Extra import AsciinemaWeb.Router.Helpers.Extra
import Asciinema.ErrorHelpers import AsciinemaWeb.ErrorHelpers
import Asciinema.Gettext import AsciinemaWeb.Gettext
end end
end end
@ -73,7 +63,7 @@ defmodule Asciinema.Web do
alias Asciinema.Repo alias Asciinema.Repo
import Ecto import Ecto
import Ecto.Query import Ecto.Query
import Asciinema.Gettext import AsciinemaWeb.Gettext
end end
end end

@ -1,6 +1,7 @@
defmodule Asciinema.Auth do defmodule AsciinemaWeb.Auth do
import Plug.Conn import Plug.Conn
alias Asciinema.{Repo, User} alias Asciinema.Users.User
alias Asciinema.Repo
@user_key "warden.user.user.key" @user_key "warden.user.user.key"
@one_year_in_secs 31557600 @one_year_in_secs 31557600
@ -18,10 +19,12 @@ defmodule Asciinema.Auth do
assign(conn, :current_user, user) assign(conn, :current_user, user)
end end
def login(conn, %User{id: id, auth_token: auth_token} = user) do def log_in(conn, %User{} = user) do
user = user |> User.login_changeset |> Repo.update!
conn conn
|> put_session(@user_key, id) |> put_session(@user_key, user.id)
|> put_resp_cookie("auth_token", auth_token, max_age: @one_year_in_secs) |> put_resp_cookie("auth_token", user.auth_token, max_age: @one_year_in_secs)
|> assign(:current_user, user) |> assign(:current_user, user)
end end

@ -1,4 +1,4 @@
defmodule Asciinema.UserSocket do defmodule AsciinemaWeb.UserSocket do
use Phoenix.Socket use Phoenix.Socket
## Channels ## Channels
@ -30,7 +30,7 @@ defmodule Asciinema.UserSocket do
# Would allow you to broadcast a "disconnect" event and terminate # Would allow you to broadcast a "disconnect" event and terminate
# all active sockets and channels for a given user: # all active sockets and channels for a given user:
# #
# Asciinema.Endpoint.broadcast("users_socket:#{user.id}", "disconnect", %{}) # AsciinemaWeb.Endpoint.broadcast("users_socket:#{user.id}", "disconnect", %{})
# #
# Returning `nil` makes this socket anonymous. # Returning `nil` makes this socket anonymous.
def id(_socket), do: nil def id(_socket), do: nil

@ -1,7 +1,8 @@
defmodule Asciinema.Api.AsciicastController do defmodule AsciinemaWeb.Api.AsciicastController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
import Asciinema.Auth, only: [get_basic_auth: 1, put_basic_auth: 3] import AsciinemaWeb.Auth, only: [get_basic_auth: 1, put_basic_auth: 3]
alias Asciinema.{Asciicasts, Users, User} alias Asciinema.{Asciicasts, Users}
alias Asciinema.Users.User
plug :parse_v0_params plug :parse_v0_params
plug :authenticate plug :authenticate

@ -1,5 +1,5 @@
defmodule Asciinema.AsciicastAnimationController do defmodule AsciinemaWeb.AsciicastAnimationController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
alias Asciinema.Asciicasts alias Asciinema.Asciicasts
def show(conn, %{"id" => id}) do def show(conn, %{"id" => id}) do

@ -1,5 +1,5 @@
defmodule Asciinema.AsciicastEmbedController do defmodule AsciinemaWeb.AsciicastEmbedController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
@max_age 60 @max_age 60

@ -1,6 +1,7 @@
defmodule Asciinema.AsciicastFileController do defmodule AsciinemaWeb.AsciicastFileController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
alias Asciinema.{Asciicasts, Asciicast} alias Asciinema.Asciicasts
alias Asciinema.Asciicasts.Asciicast
def show(conn, %{"id" => id} = params) do def show(conn, %{"id" => id} = params) do
asciicast = Asciicasts.get_asciicast!(id) asciicast = Asciicasts.get_asciicast!(id)

@ -1,6 +1,7 @@
defmodule Asciinema.AsciicastImageController do defmodule AsciinemaWeb.AsciicastImageController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
alias Asciinema.{Asciicasts, Asciicast, PngGenerator} alias Asciinema.{Asciicasts, PngGenerator}
alias Asciinema.Asciicasts.Asciicast
alias Plug.MIME alias Plug.MIME
@max_age 604800 # 7 days @max_age 604800 # 7 days

@ -1,6 +1,6 @@
defmodule Asciinema.DocController do defmodule AsciinemaWeb.DocController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
alias Asciinema.{DocView, ErrorView} alias AsciinemaWeb.{DocView, ErrorView}
@topics ["how-it-works", "getting-started", "installation", "usage", "config", "embedding", "faq"] @topics ["how-it-works", "getting-started", "installation", "usage", "config", "embedding", "faq"]

@ -1,5 +1,5 @@
defmodule Asciinema.LoginController do defmodule AsciinemaWeb.LoginController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
alias Asciinema.Users alias Asciinema.Users
def new(conn, _params) do def new(conn, _params) do

@ -1,7 +1,9 @@
defmodule Asciinema.SessionController do defmodule AsciinemaWeb.SessionController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
import Asciinema.UserView, only: [profile_path: 1] import AsciinemaWeb.UserView, only: [profile_path: 1]
alias Asciinema.{Users, User} alias Asciinema.Users
alias AsciinemaWeb.Auth
alias Asciinema.Users.User
def new(conn, %{"t" => login_token}) do def new(conn, %{"t" => login_token}) do
conn conn
@ -34,7 +36,7 @@ defmodule Asciinema.SessionController do
case Users.verify_login_token(login_token) do case Users.verify_login_token(login_token) do
{:ok, user} -> {:ok, user} ->
conn conn
|> Users.log_in(user) |> Auth.log_in(user)
|> put_rails_flash(:notice, "Welcome back!") |> put_rails_flash(:notice, "Welcome back!")
|> redirect_to_profile |> redirect_to_profile
{:error, :token_invalid} -> {:error, :token_invalid} ->
@ -58,12 +60,12 @@ defmodule Asciinema.SessionController do
case {current_user, logging_user} do case {current_user, logging_user} do
{nil, %User{email: nil}} -> {nil, %User{email: nil}} ->
conn conn
|> Users.log_in(logging_user) |> Auth.log_in(logging_user)
|> put_rails_flash(:notice, "Welcome! Setting username and email will help you with logging in later.") |> put_rails_flash(:notice, "Welcome! Setting username and email will help you with logging in later.")
|> redirect_to_edit_profile |> redirect_to_edit_profile
{nil, %User{}} -> {nil, %User{}} ->
conn conn
|> Users.log_in(logging_user) |> Auth.log_in(logging_user)
|> put_rails_flash(:notice, "Welcome back!") |> put_rails_flash(:notice, "Welcome back!")
|> redirect_to_profile |> redirect_to_profile
{%User{id: id, email: nil}, %User{id: id}} -> {%User{id: id, email: nil}, %User{id: id}} ->
@ -78,7 +80,7 @@ defmodule Asciinema.SessionController do
{%User{email: nil}, %User{}} -> {%User{email: nil}, %User{}} ->
Users.merge!(logging_user, current_user) Users.merge!(logging_user, current_user)
conn conn
|> Users.log_in(logging_user) |> Auth.log_in(logging_user)
|> put_rails_flash(:notice, "Recorder token has been added to your account.") |> put_rails_flash(:notice, "Recorder token has been added to your account.")
|> redirect_to_profile |> redirect_to_profile
{%User{}, %User{email: nil}} -> {%User{}, %User{email: nil}} ->

@ -1,6 +1,7 @@
defmodule Asciinema.UserController do defmodule AsciinemaWeb.UserController do
use Asciinema.Web, :controller use AsciinemaWeb, :controller
alias Asciinema.Users alias Asciinema.Users
alias AsciinemaWeb.Auth
def new(conn, %{"t" => signup_token}) do def new(conn, %{"t" => signup_token}) do
conn conn
@ -18,7 +19,7 @@ defmodule Asciinema.UserController do
case Users.verify_signup_token(signup_token) do case Users.verify_signup_token(signup_token) do
{:ok, user} -> {:ok, user} ->
conn conn
|> Users.log_in(user) |> Auth.log_in(user)
|> put_rails_flash(:info, "Welcome to asciinema!") |> put_rails_flash(:info, "Welcome to asciinema!")
|> redirect(to: "/username/new") |> redirect(to: "/username/new")
{:error, :token_invalid} -> {:error, :token_invalid} ->

@ -1,7 +1,7 @@
defmodule Asciinema.Endpoint do defmodule AsciinemaWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :asciinema use Phoenix.Endpoint, otp_app: :asciinema
socket "/socket", Asciinema.UserSocket socket "/socket", AsciinemaWeb.UserSocket
# Serve at "/" the static files from "priv/static" directory. # Serve at "/" the static files from "priv/static" directory.
# #
@ -41,7 +41,7 @@ defmodule Asciinema.Endpoint do
key_digest: :sha, key_digest: :sha,
serializer: Poison serializer: Poison
plug Asciinema.TrailingFormat plug AsciinemaWeb.TrailingFormat
plug Asciinema.Router plug AsciinemaWeb.Router
end end

@ -1,4 +1,4 @@
defmodule Asciinema.Gettext do defmodule AsciinemaWeb.Gettext do
@moduledoc """ @moduledoc """
A module providing Internationalization with a gettext-based API. A module providing Internationalization with a gettext-based API.

@ -1,4 +1,4 @@
defmodule Asciinema.Rails.Flash do defmodule AsciinemaWeb.Rails.Flash do
import Plug.Conn import Plug.Conn
def put_rails_flash(conn, key, value) do def put_rails_flash(conn, key, value) do

@ -1,5 +1,5 @@
defmodule Asciinema.Router do defmodule AsciinemaWeb.Router do
use Asciinema.Web, :router use AsciinemaWeb, :router
pipeline :browser do pipeline :browser do
plug :accepts, ["html"] plug :accepts, ["html"]
@ -7,14 +7,14 @@ defmodule Asciinema.Router do
plug :fetch_flash plug :fetch_flash
plug :protect_from_forgery plug :protect_from_forgery
plug :put_secure_browser_headers plug :put_secure_browser_headers
plug Asciinema.Auth plug AsciinemaWeb.Auth
end end
pipeline :asciicast_embed_script do pipeline :asciicast_embed_script do
plug :accepts, ["js"] plug :accepts, ["js"]
end end
scope "/", Asciinema do scope "/", AsciinemaWeb do
pipe_through :asciicast_embed_script pipe_through :asciicast_embed_script
# rewritten by TrailingFormat from /a/123.js to /a/123/js # rewritten by TrailingFormat from /a/123.js to /a/123/js
@ -25,7 +25,7 @@ defmodule Asciinema.Router do
plug :accepts, ["json"] plug :accepts, ["json"]
end end
scope "/", Asciinema do scope "/", AsciinemaWeb do
pipe_through :asciicast_file pipe_through :asciicast_file
# rewritten by TrailingFormat from /a/123.json to /a/123/json # rewritten by TrailingFormat from /a/123.json to /a/123/json
@ -36,7 +36,7 @@ defmodule Asciinema.Router do
plug :accepts, ["png"] plug :accepts, ["png"]
end end
scope "/", Asciinema do scope "/", AsciinemaWeb do
pipe_through :asciicast_image pipe_through :asciicast_image
# rewritten by TrailingFormat from /a/123.png to /a/123/png # rewritten by TrailingFormat from /a/123.png to /a/123/png
@ -47,14 +47,14 @@ defmodule Asciinema.Router do
plug :accepts, ["html"] plug :accepts, ["html"]
end end
scope "/", Asciinema do scope "/", AsciinemaWeb do
pipe_through :asciicast_animation pipe_through :asciicast_animation
# rewritten by TrailingFormat from /a/123.gif to /a/123/gif # rewritten by TrailingFormat from /a/123.gif to /a/123/gif
get "/a/:id/gif", AsciicastAnimationController, :show get "/a/:id/gif", AsciicastAnimationController, :show
end end
scope "/", Asciinema do scope "/", AsciinemaWeb do
pipe_through :browser # Use the default browser stack pipe_through :browser # Use the default browser stack
get "/a/:id", AsciicastController, :show get "/a/:id", AsciicastController, :show
@ -71,7 +71,7 @@ defmodule Asciinema.Router do
get "/connect/:api_token", SessionController, :create, as: :connect get "/connect/:api_token", SessionController, :create, as: :connect
end end
scope "/api", Asciinema.Api, as: :api do scope "/api", AsciinemaWeb.Api, as: :api do
post "/asciicasts", AsciicastController, :create post "/asciicasts", AsciicastController, :create
end end
@ -81,8 +81,8 @@ defmodule Asciinema.Router do
# end # end
end end
defmodule Asciinema.Router.Helpers.Extra do defmodule AsciinemaWeb.Router.Helpers.Extra do
alias Asciinema.Router.Helpers, as: H alias AsciinemaWeb.Router.Helpers, as: H
def user_path(_conn, :edit) do def user_path(_conn, :edit) do
"/user/edit" "/user/edit"

@ -0,0 +1 @@
<%= render @view_module, "wrapper.html", Map.merge(assigns, %{layout: {AsciinemaWeb.LayoutView, "app.html"}, topic_template: @view_template}) %>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save