trying to implement all with elixir-way
This commit is contained in:
parent
6a1dbbca8a
commit
a599dd8930
@ -1,5 +1,6 @@
|
||||
defmodule DraincloudCore.Auth do
|
||||
def is_logon(token) :: boolean() do
|
||||
|
||||
def is_logon(_token) do
|
||||
# TODO here
|
||||
true
|
||||
end
|
||||
end
|
||||
|
@ -0,0 +1,7 @@
|
||||
defmodule DrainCloudCoreWeb.AuthController do
|
||||
use DrainCloudCoreWeb, :controller
|
||||
|
||||
def logon(conn, _params) do
|
||||
|
||||
end
|
||||
end
|
@ -1,14 +0,0 @@
|
||||
defmodule DrainCloudCoreWeb.PageController do
|
||||
use DrainCloudCoreWeb, :controller
|
||||
def home(conn, _params) when is_logon(conn) do
|
||||
# The home page is often custom made,
|
||||
# so skip the default app layout.
|
||||
|
||||
if Map.has_key?(conn.req_headers, 'x-access-token') do
|
||||
{_, token} = Map.fetch(conn.req_headers, 'x-access-token')
|
||||
|
||||
end
|
||||
|
||||
render(conn, :home, layout: false)
|
||||
end
|
||||
end
|
@ -0,0 +1,26 @@
|
||||
defmodule DrainCloudCoreWeb.PageController do
|
||||
use DrainCloudCoreWeb, :controller
|
||||
|
||||
def home(conn, _params) do
|
||||
# The home page is often custom made,
|
||||
# so skip the default app layout.
|
||||
|
||||
# TODO
|
||||
# 1. check is user is logged in
|
||||
# 2. if is - fetch the main page contents (files, folders etc)
|
||||
# 2.1 fetch session by token. If NotFOund -> (3)
|
||||
# 2.2 fetch content by sessions user_id
|
||||
# 2.3 render page
|
||||
# If not:
|
||||
# 3. Redirect to the login page
|
||||
|
||||
# if Map.has_key?(conn.req_headers, 'x-access-token') do
|
||||
# {_, token} = Map.fetch(conn.req_headers, 'x-access-token')
|
||||
|
||||
# end
|
||||
|
||||
:logger.debug("[#{__MODULE__}] request: ", conn)
|
||||
|
||||
render(conn, :home, layout: false)
|
||||
end
|
||||
end
|
13
lib/draincloud_core_web/controllers/request/request_utils.ex
Normal file
13
lib/draincloud_core_web/controllers/request/request_utils.ex
Normal file
@ -0,0 +1,13 @@
|
||||
defmodule DraincloudCoreWeb.Request do
|
||||
# defstruct :
|
||||
def has_token?(conn) do
|
||||
# TODO try with pattern-matching please
|
||||
# case conn do
|
||||
# {} ->
|
||||
# end
|
||||
|
||||
if Map.has_key?(conn, "req_headers") do
|
||||
Map.has_key?(conn.req_headers, 'x-access-token')
|
||||
end
|
||||
end
|
||||
end
|
7
priv/repo/migrations/20240901221317_users.exs
Normal file
7
priv/repo/migrations/20240901221317_users.exs
Normal file
@ -0,0 +1,7 @@
|
||||
defmodule DrainCloudCore.Repo.Migrations.Users do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
# TODO users table migration
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user