fix some code style and add checks to ci
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
defmodule EventosWeb.AuthErrorHandler do
|
||||
@moduledoc """
|
||||
In case we have an auth error
|
||||
"""
|
||||
import Plug.Conn
|
||||
|
||||
def auth_error(conn, {type, _reason}, _opts) do
|
||||
body = Poison.encode!(%{message: to_string(type)})
|
||||
send_resp(conn, 401, body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.AuthPipeline do
|
||||
@moduledoc """
|
||||
Handles the app sessions
|
||||
"""
|
||||
|
||||
use Guardian.Plug.Pipeline, otp_app: :eventos,
|
||||
module: EventosWeb.Guardian,
|
||||
@@ -8,4 +11,4 @@ defmodule EventosWeb.AuthPipeline do
|
||||
plug Guardian.Plug.EnsureAuthenticated
|
||||
plug Guardian.Plug.LoadResource, ensure: true
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
defmodule EventosWeb.UserSocket do
|
||||
@moduledoc """
|
||||
Channel for User
|
||||
"""
|
||||
use Phoenix.Socket
|
||||
|
||||
## Channels
|
||||
# Channels
|
||||
# channel "room:*", EventosWeb.RoomChannel
|
||||
|
||||
## Transports
|
||||
# Transports
|
||||
transport :websocket, Phoenix.Transports.WebSocket
|
||||
# transport :longpoll, Phoenix.Transports.LongPoll
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
defmodule EventosWeb.AccountController do
|
||||
@moduledoc """
|
||||
Controller for Accounts
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Accounts
|
||||
alias Eventos.Accounts.Account
|
||||
import Logger
|
||||
|
||||
action_fallback EventosWeb.FallbackController
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.CategoryController do
|
||||
@moduledoc """
|
||||
Controller for Categories
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.EventController do
|
||||
@moduledoc """
|
||||
Controller for Events
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.GroupController do
|
||||
@moduledoc """
|
||||
Controller for Groups
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Groups
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.PageController do
|
||||
@moduledoc """
|
||||
Controller to load our webapp
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
plug :put_layout, false
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.SessionController do
|
||||
@moduledoc """
|
||||
Controller for (event) Sessions
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.TagController do
|
||||
@moduledoc """
|
||||
Controller for Tags
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.TrackController do
|
||||
@moduledoc """
|
||||
Controller for Tracks
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
|
||||
alias Eventos.Events
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
defmodule EventosWeb.UserController do
|
||||
@moduledoc """
|
||||
Controller for Users
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
import Logger
|
||||
|
||||
alias Eventos.Accounts
|
||||
alias Eventos.Accounts.User
|
||||
@@ -16,11 +18,10 @@ defmodule EventosWeb.UserController do
|
||||
def register(conn, %{"username" => username, "email" => email, "password" => password}) do
|
||||
case Accounts.register(%{email: email, password: password, username: username}) do
|
||||
{:ok, %User{} = user} ->
|
||||
Logger.debug(inspect user)
|
||||
{:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user)
|
||||
conn
|
||||
|> put_status(:created)
|
||||
|> render "show_with_token.json", %{token: token, user: user}
|
||||
|> render("show_with_token.json", %{token: token, user: user})
|
||||
{:error, error} ->
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
@@ -30,12 +31,14 @@ defmodule EventosWeb.UserController do
|
||||
|
||||
def show_current_account(conn, _params) do
|
||||
user = Guardian.Plug.current_resource(conn)
|
||||
|> Repo.preload :account
|
||||
user
|
||||
|> Repo.preload(:account)
|
||||
render(conn, "show_simple.json", user: user)
|
||||
end
|
||||
|
||||
defp handle_changeset_errors(errors) do
|
||||
Enum.map(errors, fn {field, detail} ->
|
||||
errors
|
||||
|> Enum.map(fn {field, detail} ->
|
||||
"#{field} " <> render_detail(detail)
|
||||
end)
|
||||
|> Enum.join
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
defmodule EventosWeb.UserSessionController do
|
||||
@moduledoc """
|
||||
Controller for user sessions
|
||||
"""
|
||||
use EventosWeb, :controller
|
||||
alias Eventos.Accounts.User
|
||||
alias Eventos.Accounts
|
||||
import Logger
|
||||
|
||||
def sign_in(conn, %{"email" => email, "password" => password}) do
|
||||
case Accounts.find_by_email(email) do
|
||||
@@ -22,7 +24,7 @@ defmodule EventosWeb.UserSessionController do
|
||||
|
||||
def sign_out(conn, _params) do
|
||||
conn
|
||||
|> Guardian.Plug.sign_out()
|
||||
|> EventosWeb.Guardian.Plug.sign_out()
|
||||
|> send_resp(204, "")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.Endpoint do
|
||||
@moduledoc """
|
||||
Endpoint for Eventos app
|
||||
"""
|
||||
use Phoenix.Endpoint, otp_app: :eventos
|
||||
|
||||
socket "/socket", EventosWeb.UserSocket
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
defmodule EventosWeb.Guardian do
|
||||
@moduledoc """
|
||||
Handles the JWT tokens encoding and decoding
|
||||
"""
|
||||
use Guardian, otp_app: :eventos, permissions: %{
|
||||
superuser: [:moderate, :super],
|
||||
user: [:base]
|
||||
}
|
||||
|
||||
import Logger
|
||||
|
||||
alias Eventos.Accounts
|
||||
alias Eventos.Accounts.{Account, User}
|
||||
alias Eventos.Accounts.User
|
||||
|
||||
def subject_for_token(user = %User{}, _claims) do
|
||||
def subject_for_token(%User{} = user, _claims) do
|
||||
{:ok, "User:" <> to_string(user.id)}
|
||||
end
|
||||
|
||||
@@ -19,8 +20,6 @@ defmodule EventosWeb.Guardian do
|
||||
|
||||
def resource_from_claims(%{"sub" => "User:" <> uid_str}) do
|
||||
try do
|
||||
Logger.debug("Inspecting resource token")
|
||||
Logger.debug(inspect uid_str)
|
||||
case Integer.parse(uid_str) do
|
||||
{uid, ""} ->
|
||||
{:ok, Accounts.get_user_with_account!(uid)}
|
||||
@@ -32,9 +31,7 @@ defmodule EventosWeb.Guardian do
|
||||
end
|
||||
end
|
||||
|
||||
def resource_from_claims(claims) do
|
||||
Logger.debug("Check bad resource")
|
||||
Logger.debug(inspect claims)
|
||||
def resource_from_claims(_) do
|
||||
{:error, :reason_for_error}
|
||||
end
|
||||
|
||||
@@ -45,7 +42,6 @@ defmodule EventosWeb.Guardian do
|
||||
end
|
||||
|
||||
def on_verify(claims, token, _options) do
|
||||
Logger.debug(inspect claims)
|
||||
with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
|
||||
{:ok, claims}
|
||||
end
|
||||
@@ -62,4 +58,4 @@ defmodule EventosWeb.Guardian do
|
||||
# |> encode_permissions_into_claims!(Keyword.get(opts, :permissions))
|
||||
# {:ok, claims}
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.Router do
|
||||
@moduledoc """
|
||||
Router for eventos app
|
||||
"""
|
||||
use EventosWeb, :router
|
||||
|
||||
pipeline :api do
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.AccountView do
|
||||
@moduledoc """
|
||||
View for Accounts
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.AccountView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.CategoryView do
|
||||
@moduledoc """
|
||||
View for Categories
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.CategoryView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.ChangesetView do
|
||||
@moduledoc """
|
||||
View for changesets in case of errors
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
|
||||
@doc """
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.ErrorView do
|
||||
@moduledoc """
|
||||
View for errors
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
|
||||
def render("404.html", _assigns) do
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.EventView do
|
||||
@moduledoc """
|
||||
View for Events
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.EventView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.GroupView do
|
||||
@moduledoc """
|
||||
View for Groups
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.GroupView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.MemberView do
|
||||
@moduledoc """
|
||||
View for Members
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.MemberView
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
defmodule EventosWeb.PageView do
|
||||
@moduledoc """
|
||||
View for our webapp
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
end
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.ParticipantView do
|
||||
@moduledoc """
|
||||
View for Participants
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.ParticipantView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.RequestView do
|
||||
@moduledoc """
|
||||
View for event request
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.RequestView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.SessionView do
|
||||
@moduledoc """
|
||||
View for event Sessions
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.SessionView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.TagView do
|
||||
@moduledoc """
|
||||
View for Tags
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.TagView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.TrackView do
|
||||
@moduledoc """
|
||||
View for Tracks
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.TrackView
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.UserSessionView do
|
||||
@moduledoc """
|
||||
View for user Sessions
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
|
||||
def render("token.json", %{token: token, user: user}) do
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
defmodule EventosWeb.UserView do
|
||||
@moduledoc """
|
||||
View for Users
|
||||
"""
|
||||
use EventosWeb, :view
|
||||
alias EventosWeb.UserView
|
||||
alias EventosWeb.AccountView
|
||||
|
||||
Reference in New Issue
Block a user