Skip to content

Instantly share code, notes, and snippets.

@MartinElvar
Created September 16, 2015 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinElvar/c0d3ac65f690a4f2f5be to your computer and use it in GitHub Desktop.
Save MartinElvar/c0d3ac65f690a4f2f5be to your computer and use it in GitHub Desktop.
defmodule Mobil.Session do
alias Mobil.Admin
def current_user(conn) do
id = Plug.get_session(conn, :current_user)
if id, do: Repo.get(Admin, id)
end
end
defmodule Mobil.Web do
def model do
quote do
use Ecto.Model
end
end
def controller do
quote do
use Phoenix.Controller
alias Mobil.Repo
import Ecto.Model
import Ecto.Query, only: [from: 2]
import Mobil.Router.Helpers
end
end
def view do
quote do
use Phoenix.View, root: "web/templates"
# Import convenience functions from controllers
import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1]
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
import Mobil.Router.Helpers
# Add auth helpers.
import Mobil.Session, only: [current_user: 1]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment