Merge pull request 'login screen and related auth logic implemented' (#1) from login_screen into master
Reviewed-on: draincloud/draincloud-core#1
This commit is contained in:
commit
88ccb65110
@ -1,6 +1,11 @@
|
||||
# DrainCloudCore
|
||||
**DrainCloud** is an opensource cloud file management service, aimed for an ease of usage in a self-hosted usage scenarios.
|
||||
The main goal is to create a *easy-to-host* and very performant application with small footprint.
|
||||
|
||||
To start your Phoenix server:
|
||||
*TODO put docs here*
|
||||
|
||||
## Development
|
||||
To start your DrainCloudCore server:
|
||||
|
||||
* Run `mix setup` to install and setup dependencies
|
||||
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
|
||||
@ -9,7 +14,7 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
|
||||
|
||||
Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
|
||||
|
||||
## Learn more
|
||||
### Some phoenix related links
|
||||
|
||||
* Official website: https://www.phoenixframework.org/
|
||||
* Guides: https://hexdocs.pm/phoenix/overview.html
|
||||
|
@ -2,4 +2,92 @@
|
||||
@import "tailwindcss/components";
|
||||
@import "tailwindcss/utilities";
|
||||
|
||||
/* This file is for your main application CSS */
|
||||
|
||||
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f7f7f7;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
margin: 0;
|
||||
}
|
||||
header {
|
||||
width: 100%;
|
||||
background-color: #0d1547;
|
||||
padding: 15px 0;
|
||||
text-align: center;
|
||||
color: rgb(255, 241, 233);
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 1000;
|
||||
}
|
||||
.login-container {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
width: 300px;
|
||||
}
|
||||
h2 {
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
}
|
||||
.input-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.input-group label {
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
color: #555;
|
||||
}
|
||||
.input-group input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.login-button {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
background-color: #0d1547;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
.login-button:hover {
|
||||
background-color: #0d1547;
|
||||
}
|
||||
|
||||
.gallery-container {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
grid-gap: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
.gallery-item {
|
||||
background-color: #fff;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
text-align: center;
|
||||
}
|
||||
.gallery-item img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.gallery-item p {
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
color: #555;
|
||||
}
|
@ -42,3 +42,33 @@ liveSocket.connect()
|
||||
// >> liveSocket.disableLatencySim()
|
||||
window.liveSocket = liveSocket
|
||||
|
||||
function initialize_gallery() {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const imagePaths = [
|
||||
'image1.jpg',
|
||||
'image2.jpg',
|
||||
'image3.jpg',
|
||||
'image4.jpg',
|
||||
'image5.jpg'
|
||||
// Add more image filenames here
|
||||
];
|
||||
|
||||
const gallery = document.getElementById('gallery');
|
||||
|
||||
imagePaths.forEach(function(image) {
|
||||
const item = document.createElement('div');
|
||||
item.className = 'gallery-item';
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.src = '/images/' + image;
|
||||
img.alt = image;
|
||||
|
||||
const caption = document.createElement('p');
|
||||
caption.textContent = image;
|
||||
|
||||
item.appendChild(img);
|
||||
item.appendChild(caption);
|
||||
gallery.appendChild(item);
|
||||
});
|
||||
});
|
||||
}
|
@ -9,5 +9,26 @@ services:
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
minio:
|
||||
image: quay.io/minio/minio:RELEASE.2024-08-29T01-40-52Z
|
||||
command: server --console-address ":9001" http://minio/data{1...2}
|
||||
hostname: minio
|
||||
volumes:
|
||||
draincore-data: {}
|
||||
- data-1:/data1
|
||||
- data-2:/data2
|
||||
expose:
|
||||
- "9000"
|
||||
- "9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: minioadmin
|
||||
MINIO_ROOT_PASSWORD: minioadmin
|
||||
healthcheck:
|
||||
test: ["CMD", "mc", "ready", "local"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
volumes:
|
||||
draincore-data:
|
||||
data-1:
|
||||
data-2:
|
@ -10,6 +10,7 @@ defmodule DrainCloudCore.Application do
|
||||
children = [
|
||||
DrainCloudCoreWeb.Telemetry,
|
||||
DrainCloudCore.Repo,
|
||||
# DrainCloudCore.Rtc,
|
||||
{DNSCluster, query: Application.get_env(:draincloud_core, :dns_cluster_query) || :ignore},
|
||||
{Phoenix.PubSub, name: DrainCloudCore.PubSub},
|
||||
# Start a worker by calling: DrainCloudCore.Worker.start_link(arg)
|
||||
|
6
lib/draincloud_core/auth/auth.ex
Normal file
6
lib/draincloud_core/auth/auth.ex
Normal file
@ -0,0 +1,6 @@
|
||||
defmodule DraincloudCore.Auth do
|
||||
def is_logon(_token) do
|
||||
# TODO here
|
||||
true
|
||||
end
|
||||
end
|
@ -1,3 +1,103 @@
|
||||
defmodule DraincloudCore.Rtc do
|
||||
# Real Time Config module
|
||||
defmodule DrainCloudCore.Rtc.Application do
|
||||
use Application
|
||||
|
||||
def child_spec(opts) do
|
||||
%{
|
||||
id: __MODULE__,
|
||||
start: {__MODULE__, :start_link, [opts]},
|
||||
shutdown: 5_000,
|
||||
restart: :permanent,
|
||||
type: :supervisor
|
||||
}
|
||||
end
|
||||
def start_link(_) do
|
||||
children = [
|
||||
DrainCloudCore.Rtc
|
||||
]
|
||||
|
||||
opts = [strategy: :one_for_one, name: DrainCloudCore.Rtc.Supervisor]
|
||||
Supervisor.start_link(children, opts)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule DrainCloudCore.Rtc do
|
||||
alias :mnesia, as: Mnesia
|
||||
alias :logger, as: Log
|
||||
|
||||
use GenServer
|
||||
|
||||
# Real-time config table schemas
|
||||
@config_web [attributes: [
|
||||
:host,
|
||||
:enable_https,
|
||||
:port,
|
||||
]]
|
||||
|
||||
@config_pg [attributes: [
|
||||
:host,
|
||||
:port,
|
||||
:ssl,
|
||||
:user,
|
||||
:password,
|
||||
:db,
|
||||
]]
|
||||
|
||||
|
||||
@config_s3 [attributes: [
|
||||
:host,
|
||||
:port,
|
||||
# user / secret / secrets etc...
|
||||
]]
|
||||
|
||||
# def child_spec(opts) do
|
||||
# %{
|
||||
# id: __MODULE__,
|
||||
# start: {__MODULE__, :start_link, [opts]},
|
||||
# shutdown: 5_000,
|
||||
# restart: :permanent,
|
||||
# type: :worker
|
||||
# }
|
||||
# end
|
||||
|
||||
def start_link(default) when is_list(default) do
|
||||
GenServer.start_link(__MODULE__, default)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def init(stack) do
|
||||
{:ok, stack}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_call(:pop, _from, [head | tail]) do
|
||||
{:reply, head, tail}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_cast({:push, element}, state) do
|
||||
{:noreply, [element | state]}
|
||||
end
|
||||
|
||||
def fetch_config() do
|
||||
# Mnesia.read()
|
||||
end
|
||||
def init() do
|
||||
Log.info("[#{__MODULE__}] start initializin RTC subsystems")
|
||||
|
||||
if Mnesia.create_schema([node()]) != :ok do
|
||||
Log.warning("[#{__MODULE__}] schema #{node()} not created. skipping")
|
||||
end
|
||||
|
||||
if Mnesia.create_table(DrainCloudRtcWeb, @config_web) != {:atomic, :ok} do
|
||||
Log.warning("[#{__MODULE__}] table config_web not created. skipping")
|
||||
end
|
||||
|
||||
if Mnesia.create_table(DrainCloudRtcPG, @config_pg) != {:atomic, :ok} do
|
||||
Log.warning("[#{__MODULE__}] schema config_pg not created. skipping")
|
||||
end
|
||||
|
||||
if Mnesia.create_table(DrainCloudRtcS3, @config_s3) != {:atomic, :ok} do
|
||||
Log.warning("[#{__MODULE__}] schema config_s3 not created. skipping")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,6 +8,7 @@
|
||||
<%= assigns[:page_title] || "DrainCloudCore" %>
|
||||
</.live_title>
|
||||
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
|
||||
<script src="https://unpkg.com/htmx.org@2.0.2" integrity="sha384-Y7hw+L/jvKeWIRRkqWYfPcvVxHzVzn5REgzbawhxAuQGwX1XWe70vji+VSeHOThJ" crossorigin="anonymous"></script>
|
||||
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
|
||||
</script>
|
||||
</head>
|
||||
|
@ -0,0 +1,12 @@
|
||||
defmodule DrainCloudCoreWeb.AuthController do
|
||||
use DrainCloudCoreWeb, :controller
|
||||
alias DrainCloudCoreWeb.Request, as: Request
|
||||
|
||||
def logon(conn, _params) do
|
||||
if Request.hs_token?(conn) do
|
||||
# TODO validate token here
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
@ -0,0 +1,11 @@
|
||||
defmodule DrainCloudCoreWeb.MainController do
|
||||
use DrainCloudCoreWeb, :controller
|
||||
|
||||
def test(conn, _params) do
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> put_root_layout(false)
|
||||
|> json(%{data: %{name: "Some Name"}})
|
||||
end
|
||||
|
||||
end
|
@ -1,9 +0,0 @@
|
||||
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.
|
||||
render(conn, :home, layout: false)
|
||||
end
|
||||
end
|
@ -1,10 +0,0 @@
|
||||
defmodule DrainCloudCoreWeb.PageHTML do
|
||||
@moduledoc """
|
||||
This module contains pages rendered by PageController.
|
||||
|
||||
See the `page_html` directory for all templates available.
|
||||
"""
|
||||
use DrainCloudCoreWeb, :html
|
||||
|
||||
embed_templates "page_html/*"
|
||||
end
|
@ -1 +0,0 @@
|
||||
<h1>Hello</h1>
|
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
|
@ -15,9 +15,9 @@ defmodule DrainCloudCoreWeb.Router do
|
||||
end
|
||||
|
||||
scope "/", DrainCloudCoreWeb do
|
||||
pipe_through :browser
|
||||
pipe_through :api
|
||||
|
||||
get "/", PageController, :home
|
||||
get "/api", MainController, :test
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
2
mix.exs
2
mix.exs
@ -19,7 +19,7 @@ defmodule DrainCloudCore.MixProject do
|
||||
def application do
|
||||
[
|
||||
mod: {DrainCloudCore.Application, []},
|
||||
extra_applications: [:logger, :runtime_tools]
|
||||
extra_applications: [:logger, :runtime_tools, :mnesia]
|
||||
]
|
||||
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
|
5
schemas/users.sql
Normal file
5
schemas/users.sql
Normal file
@ -0,0 +1,5 @@
|
||||
create table users (
|
||||
id bigserial,
|
||||
login varchar(50),
|
||||
password varchar(256)
|
||||
);
|
Loading…
Reference in New Issue
Block a user