replace coherence with guardian
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
defmodule Coherence.Redirects do
|
||||
@moduledoc """
|
||||
Define controller action redirection functions.
|
||||
|
||||
This module contains default redirect functions for each of the controller
|
||||
actions that perform redirects. By using this Module you get the following
|
||||
functions:
|
||||
|
||||
* session_create/2
|
||||
* session_delete/2
|
||||
* password_create/2
|
||||
* password_update/2,
|
||||
* unlock_create_not_locked/2
|
||||
* unlock_create_invalid/2
|
||||
* unlock_create/2
|
||||
* unlock_edit_not_locked/2
|
||||
* unlock_edit/2
|
||||
* unlock_edit_invalid/2
|
||||
* registration_create/2
|
||||
* invitation_create/2
|
||||
* confirmation_create/2
|
||||
* confirmation_edit_invalid/2
|
||||
* confirmation_edit_expired/2
|
||||
* confirmation_edit/2
|
||||
* confirmation_edit_error/2
|
||||
|
||||
You can override any of the functions to customize the redirect path. Each
|
||||
function is passed the `conn` and `params` arguments from the controller.
|
||||
|
||||
## Examples
|
||||
|
||||
import EventosWeb.Router.Helpers
|
||||
|
||||
# override the log out action back to the log in page
|
||||
def session_delete(conn, _), do: redirect(conn, to: session_path(conn, :new))
|
||||
|
||||
# redirect the user to the login page after registering
|
||||
def registration_create(conn, _), do: redirect(conn, to: session_path(conn, :new))
|
||||
|
||||
# disable the user_return_to feature on login
|
||||
def session_create(conn, _), do: redirect(conn, to: landing_path(conn, :index))
|
||||
|
||||
"""
|
||||
use Redirects
|
||||
# Uncomment the import below if adding overrides
|
||||
# import EventosWeb.Router.Helpers
|
||||
|
||||
# Add function overrides below
|
||||
|
||||
# Example usage
|
||||
# Uncomment the following line to return the user to the login form after logging out
|
||||
# def session_delete(conn, _), do: redirect(conn, to: session_path(conn, :new))
|
||||
|
||||
end
|
||||
@@ -4,4 +4,8 @@ defmodule EventosWeb.PageController do
|
||||
def index(conn, _params) do
|
||||
render conn, "index.html"
|
||||
end
|
||||
|
||||
def app(conn, _params) do
|
||||
render conn, "index.html"
|
||||
end
|
||||
end
|
||||
|
||||
27
lib/eventos_web/controllers/session_controller.ex
Normal file
27
lib/eventos_web/controllers/session_controller.ex
Normal file
@@ -0,0 +1,27 @@
|
||||
defmodule EventosWeb.SessionController do
|
||||
use EventosWeb, :controller
|
||||
alias Eventos.Accounts.User
|
||||
alias Eventos.Accounts
|
||||
|
||||
def sign_in(conn, %{"email" => email, "password" => password}) do
|
||||
with %User{} = user <- Accounts.find(email) do
|
||||
# Attempt to authenticate the user
|
||||
with {:ok, token, _claims} <- Accounts.authenticate(%{user: user, password: password}) do
|
||||
# Render the token
|
||||
render conn, "token.json", token: token
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def sign_out(conn, _params) do
|
||||
conn
|
||||
|> Eventos.Guardian.Plug.sign_out()
|
||||
|> send_resp(204, "")
|
||||
end
|
||||
|
||||
def show(conn, _params) do
|
||||
user = Eventos.Guardian.Plug.current_resource(conn)
|
||||
|
||||
send_resp(conn, 200, Poison.encode!(%{user: user}))
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user