login screen and related auth logic implemented #1

Merged
optclblast merged 4 commits from login_screen into master 2024-09-04 21:30:18 +00:00
11 changed files with 56 additions and 16 deletions
Showing only changes of commit a599dd8930 - Show all commits

View File

@ -1,5 +1,6 @@
defmodule DraincloudCore.Auth do
def is_logon(token) :: boolean() do
def is_logon(_token) do
# TODO here
true
end
end

View File

@ -0,0 +1,7 @@
defmodule DrainCloudCoreWeb.AuthController do
use DrainCloudCoreWeb, :controller
def logon(conn, _params) do
end
end

View File

@ -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

View File

@ -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

View 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

View File

@ -0,0 +1,7 @@
defmodule DrainCloudCore.Repo.Migrations.Users do
use Ecto.Migration
def change do
# TODO users table migration
end
end