Created
September 16, 2015 11:26
-
-
Save MartinElvar/c0d3ac65f690a4f2f5be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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