Initial commit
This commit is contained in:
commit
1d2ee62781
53 changed files with 2193 additions and 0 deletions
5
.formatter.exs
Normal file
5
.formatter.exs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[
|
||||||
|
import_deps: [:ecto, :phoenix],
|
||||||
|
inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
|
||||||
|
subdirectories: ["priv/*/migrations"]
|
||||||
|
]
|
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# The directory Mix will write compiled artifacts to.
|
||||||
|
/_build/
|
||||||
|
|
||||||
|
# If you run "mix test --cover", coverage assets end up here.
|
||||||
|
/cover/
|
||||||
|
|
||||||
|
# The directory Mix downloads your dependencies sources to.
|
||||||
|
/deps/
|
||||||
|
|
||||||
|
# Where 3rd-party dependencies like ExDoc output generated docs.
|
||||||
|
/doc/
|
||||||
|
|
||||||
|
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||||
|
/.fetch
|
||||||
|
|
||||||
|
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||||
|
erl_crash.dump
|
||||||
|
|
||||||
|
# Also ignore archive artifacts (built via "mix archive.build").
|
||||||
|
*.ez
|
||||||
|
|
||||||
|
# Ignore package tarball (built via "mix hex.build").
|
||||||
|
minisome-*.tar
|
||||||
|
|
||||||
|
# Ignore assets that are produced by build tools.
|
||||||
|
/priv/static/assets/
|
||||||
|
|
||||||
|
# Ignore digested assets cache.
|
||||||
|
/priv/static/cache_manifest.json
|
||||||
|
|
||||||
|
# In case you use Node.js/npm, you want to ignore these.
|
||||||
|
npm-debug.log
|
||||||
|
/assets/node_modules/
|
||||||
|
|
||||||
|
# Database files
|
||||||
|
*.db
|
||||||
|
*.db-*
|
||||||
|
|
2
.tool-versions
Normal file
2
.tool-versions
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
erlang 24.2.1
|
||||||
|
elixir 1.13.2-otp-24
|
19
README.md
Normal file
19
README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Minisome
|
||||||
|
|
||||||
|
To start your Phoenix server:
|
||||||
|
|
||||||
|
* Install dependencies with `mix deps.get`
|
||||||
|
* Create and migrate your database with `mix ecto.setup`
|
||||||
|
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
* Official website: https://www.phoenixframework.org/
|
||||||
|
* Guides: https://hexdocs.pm/phoenix/overview.html
|
||||||
|
* Docs: https://hexdocs.pm/phoenix
|
||||||
|
* Forum: https://elixirforum.com/c/phoenix-forum
|
||||||
|
* Source: https://github.com/phoenixframework/phoenix
|
120
assets/css/app.css
Normal file
120
assets/css/app.css
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/* This file is for your main application CSS */
|
||||||
|
@import "./phoenix.css";
|
||||||
|
|
||||||
|
/* Alerts and form errors used by phx.new */
|
||||||
|
.alert {
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
.alert-info {
|
||||||
|
color: #31708f;
|
||||||
|
background-color: #d9edf7;
|
||||||
|
border-color: #bce8f1;
|
||||||
|
}
|
||||||
|
.alert-warning {
|
||||||
|
color: #8a6d3b;
|
||||||
|
background-color: #fcf8e3;
|
||||||
|
border-color: #faebcc;
|
||||||
|
}
|
||||||
|
.alert-danger {
|
||||||
|
color: #a94442;
|
||||||
|
background-color: #f2dede;
|
||||||
|
border-color: #ebccd1;
|
||||||
|
}
|
||||||
|
.alert p {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
.alert:empty {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.invalid-feedback {
|
||||||
|
color: #a94442;
|
||||||
|
display: block;
|
||||||
|
margin: -1rem 0 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* LiveView specific classes for your customization */
|
||||||
|
.phx-no-feedback.invalid-feedback,
|
||||||
|
.phx-no-feedback .invalid-feedback {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-click-loading {
|
||||||
|
opacity: 0.5;
|
||||||
|
transition: opacity 1s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-loading{
|
||||||
|
cursor: wait;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-modal {
|
||||||
|
opacity: 1!important;
|
||||||
|
position: fixed;
|
||||||
|
z-index: 1;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
background-color: rgba(0,0,0,0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-modal-content {
|
||||||
|
background-color: #fefefe;
|
||||||
|
margin: 15vh auto;
|
||||||
|
padding: 20px;
|
||||||
|
border: 1px solid #888;
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-modal-close {
|
||||||
|
color: #aaa;
|
||||||
|
float: right;
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phx-modal-close:hover,
|
||||||
|
.phx-modal-close:focus {
|
||||||
|
color: black;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-in-scale {
|
||||||
|
animation: 0.2s ease-in 0s normal forwards 1 fade-in-scale-keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-out-scale {
|
||||||
|
animation: 0.2s ease-out 0s normal forwards 1 fade-out-scale-keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-in {
|
||||||
|
animation: 0.2s ease-out 0s normal forwards 1 fade-in-keys;
|
||||||
|
}
|
||||||
|
.fade-out {
|
||||||
|
animation: 0.2s ease-out 0s normal forwards 1 fade-out-keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-in-scale-keys{
|
||||||
|
0% { scale: 0.95; opacity: 0; }
|
||||||
|
100% { scale: 1.0; opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-out-scale-keys{
|
||||||
|
0% { scale: 1.0; opacity: 1; }
|
||||||
|
100% { scale: 0.95; opacity: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-in-keys{
|
||||||
|
0% { opacity: 0; }
|
||||||
|
100% { opacity: 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fade-out-keys{
|
||||||
|
0% { opacity: 1; }
|
||||||
|
100% { opacity: 0; }
|
||||||
|
}
|
101
assets/css/phoenix.css
Normal file
101
assets/css/phoenix.css
Normal file
File diff suppressed because one or more lines are too long
45
assets/js/app.js
Normal file
45
assets/js/app.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// We import the CSS which is extracted to its own file by esbuild.
|
||||||
|
// Remove this line if you add a your own CSS build pipeline (e.g postcss).
|
||||||
|
import "../css/app.css"
|
||||||
|
|
||||||
|
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
|
||||||
|
// to get started and then uncomment the line below.
|
||||||
|
// import "./user_socket.js"
|
||||||
|
|
||||||
|
// You can include dependencies in two ways.
|
||||||
|
//
|
||||||
|
// The simplest option is to put them in assets/vendor and
|
||||||
|
// import them using relative paths:
|
||||||
|
//
|
||||||
|
// import "../vendor/some-package.js"
|
||||||
|
//
|
||||||
|
// Alternatively, you can `npm install some-package --prefix assets` and import
|
||||||
|
// them using a path starting with the package name:
|
||||||
|
//
|
||||||
|
// import "some-package"
|
||||||
|
//
|
||||||
|
|
||||||
|
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
|
||||||
|
import "phoenix_html"
|
||||||
|
// Establish Phoenix Socket and LiveView configuration.
|
||||||
|
import {Socket} from "phoenix"
|
||||||
|
import {LiveSocket} from "phoenix_live_view"
|
||||||
|
import topbar from "../vendor/topbar"
|
||||||
|
|
||||||
|
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
|
||||||
|
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
|
||||||
|
|
||||||
|
// Show progress bar on live navigation and form submits
|
||||||
|
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
|
||||||
|
window.addEventListener("phx:page-loading-start", info => topbar.show())
|
||||||
|
window.addEventListener("phx:page-loading-stop", info => topbar.hide())
|
||||||
|
|
||||||
|
// connect if there are any LiveViews on the page
|
||||||
|
liveSocket.connect()
|
||||||
|
|
||||||
|
// expose liveSocket on window for web console debug logs and latency simulation:
|
||||||
|
// >> liveSocket.enableDebug()
|
||||||
|
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
|
||||||
|
// >> liveSocket.disableLatencySim()
|
||||||
|
window.liveSocket = liveSocket
|
||||||
|
|
157
assets/vendor/topbar.js
vendored
Normal file
157
assets/vendor/topbar.js
vendored
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
/**
|
||||||
|
* @license MIT
|
||||||
|
* topbar 1.0.0, 2021-01-06
|
||||||
|
* https://buunguyen.github.io/topbar
|
||||||
|
* Copyright (c) 2021 Buu Nguyen
|
||||||
|
*/
|
||||||
|
(function (window, document) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
// https://gist.github.com/paulirish/1579671
|
||||||
|
(function () {
|
||||||
|
var lastTime = 0;
|
||||||
|
var vendors = ["ms", "moz", "webkit", "o"];
|
||||||
|
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
||||||
|
window.requestAnimationFrame =
|
||||||
|
window[vendors[x] + "RequestAnimationFrame"];
|
||||||
|
window.cancelAnimationFrame =
|
||||||
|
window[vendors[x] + "CancelAnimationFrame"] ||
|
||||||
|
window[vendors[x] + "CancelRequestAnimationFrame"];
|
||||||
|
}
|
||||||
|
if (!window.requestAnimationFrame)
|
||||||
|
window.requestAnimationFrame = function (callback, element) {
|
||||||
|
var currTime = new Date().getTime();
|
||||||
|
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
||||||
|
var id = window.setTimeout(function () {
|
||||||
|
callback(currTime + timeToCall);
|
||||||
|
}, timeToCall);
|
||||||
|
lastTime = currTime + timeToCall;
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
if (!window.cancelAnimationFrame)
|
||||||
|
window.cancelAnimationFrame = function (id) {
|
||||||
|
clearTimeout(id);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
var canvas,
|
||||||
|
progressTimerId,
|
||||||
|
fadeTimerId,
|
||||||
|
currentProgress,
|
||||||
|
showing,
|
||||||
|
addEvent = function (elem, type, handler) {
|
||||||
|
if (elem.addEventListener) elem.addEventListener(type, handler, false);
|
||||||
|
else if (elem.attachEvent) elem.attachEvent("on" + type, handler);
|
||||||
|
else elem["on" + type] = handler;
|
||||||
|
},
|
||||||
|
options = {
|
||||||
|
autoRun: true,
|
||||||
|
barThickness: 3,
|
||||||
|
barColors: {
|
||||||
|
0: "rgba(26, 188, 156, .9)",
|
||||||
|
".25": "rgba(52, 152, 219, .9)",
|
||||||
|
".50": "rgba(241, 196, 15, .9)",
|
||||||
|
".75": "rgba(230, 126, 34, .9)",
|
||||||
|
"1.0": "rgba(211, 84, 0, .9)",
|
||||||
|
},
|
||||||
|
shadowBlur: 10,
|
||||||
|
shadowColor: "rgba(0, 0, 0, .6)",
|
||||||
|
className: null,
|
||||||
|
},
|
||||||
|
repaint = function () {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = options.barThickness * 5; // need space for shadow
|
||||||
|
|
||||||
|
var ctx = canvas.getContext("2d");
|
||||||
|
ctx.shadowBlur = options.shadowBlur;
|
||||||
|
ctx.shadowColor = options.shadowColor;
|
||||||
|
|
||||||
|
var lineGradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
|
||||||
|
for (var stop in options.barColors)
|
||||||
|
lineGradient.addColorStop(stop, options.barColors[stop]);
|
||||||
|
ctx.lineWidth = options.barThickness;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(0, options.barThickness / 2);
|
||||||
|
ctx.lineTo(
|
||||||
|
Math.ceil(currentProgress * canvas.width),
|
||||||
|
options.barThickness / 2
|
||||||
|
);
|
||||||
|
ctx.strokeStyle = lineGradient;
|
||||||
|
ctx.stroke();
|
||||||
|
},
|
||||||
|
createCanvas = function () {
|
||||||
|
canvas = document.createElement("canvas");
|
||||||
|
var style = canvas.style;
|
||||||
|
style.position = "fixed";
|
||||||
|
style.top = style.left = style.right = style.margin = style.padding = 0;
|
||||||
|
style.zIndex = 100001;
|
||||||
|
style.display = "none";
|
||||||
|
if (options.className) canvas.classList.add(options.className);
|
||||||
|
document.body.appendChild(canvas);
|
||||||
|
addEvent(window, "resize", repaint);
|
||||||
|
},
|
||||||
|
topbar = {
|
||||||
|
config: function (opts) {
|
||||||
|
for (var key in opts)
|
||||||
|
if (options.hasOwnProperty(key)) options[key] = opts[key];
|
||||||
|
},
|
||||||
|
show: function () {
|
||||||
|
if (showing) return;
|
||||||
|
showing = true;
|
||||||
|
if (fadeTimerId !== null) window.cancelAnimationFrame(fadeTimerId);
|
||||||
|
if (!canvas) createCanvas();
|
||||||
|
canvas.style.opacity = 1;
|
||||||
|
canvas.style.display = "block";
|
||||||
|
topbar.progress(0);
|
||||||
|
if (options.autoRun) {
|
||||||
|
(function loop() {
|
||||||
|
progressTimerId = window.requestAnimationFrame(loop);
|
||||||
|
topbar.progress(
|
||||||
|
"+" + 0.05 * Math.pow(1 - Math.sqrt(currentProgress), 2)
|
||||||
|
);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
progress: function (to) {
|
||||||
|
if (typeof to === "undefined") return currentProgress;
|
||||||
|
if (typeof to === "string") {
|
||||||
|
to =
|
||||||
|
(to.indexOf("+") >= 0 || to.indexOf("-") >= 0
|
||||||
|
? currentProgress
|
||||||
|
: 0) + parseFloat(to);
|
||||||
|
}
|
||||||
|
currentProgress = to > 1 ? 1 : to;
|
||||||
|
repaint();
|
||||||
|
return currentProgress;
|
||||||
|
},
|
||||||
|
hide: function () {
|
||||||
|
if (!showing) return;
|
||||||
|
showing = false;
|
||||||
|
if (progressTimerId != null) {
|
||||||
|
window.cancelAnimationFrame(progressTimerId);
|
||||||
|
progressTimerId = null;
|
||||||
|
}
|
||||||
|
(function loop() {
|
||||||
|
if (topbar.progress("+.1") >= 1) {
|
||||||
|
canvas.style.opacity -= 0.05;
|
||||||
|
if (canvas.style.opacity <= 0.05) {
|
||||||
|
canvas.style.display = "none";
|
||||||
|
fadeTimerId = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fadeTimerId = window.requestAnimationFrame(loop);
|
||||||
|
})();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof module === "object" && typeof module.exports === "object") {
|
||||||
|
module.exports = topbar;
|
||||||
|
} else if (typeof define === "function" && define.amd) {
|
||||||
|
define(function () {
|
||||||
|
return topbar;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.topbar = topbar;
|
||||||
|
}
|
||||||
|
}.call(this, window, document));
|
40
config/config.exs
Normal file
40
config/config.exs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
# This file is responsible for configuring your application
|
||||||
|
# and its dependencies with the aid of the Config module.
|
||||||
|
#
|
||||||
|
# This configuration file is loaded before any dependency and
|
||||||
|
# is restricted to this project.
|
||||||
|
|
||||||
|
# General application configuration
|
||||||
|
import Config
|
||||||
|
|
||||||
|
config :minisome,
|
||||||
|
ecto_repos: [Minisome.Storage.Repo]
|
||||||
|
|
||||||
|
# Configures the endpoint
|
||||||
|
config :minisome, Minisome.Web.Endpoint,
|
||||||
|
url: [host: "localhost"],
|
||||||
|
render_errors: [view: Minisome.Web.ErrorView, accepts: ~w(html json), layout: false],
|
||||||
|
pubsub_server: Minisome.PubSub,
|
||||||
|
live_view: [signing_salt: "vfAnu01K"]
|
||||||
|
|
||||||
|
# Configure esbuild (the version is required)
|
||||||
|
config :esbuild,
|
||||||
|
version: "0.14.0",
|
||||||
|
default: [
|
||||||
|
args:
|
||||||
|
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
|
||||||
|
cd: Path.expand("../assets", __DIR__),
|
||||||
|
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
|
||||||
|
]
|
||||||
|
|
||||||
|
# Configures Elixir's Logger
|
||||||
|
config :logger, :console,
|
||||||
|
format: "$time $metadata[$level] $message\n",
|
||||||
|
metadata: [:request_id]
|
||||||
|
|
||||||
|
# Use Jason for JSON parsing in Phoenix
|
||||||
|
config :phoenix, :json_library, Jason
|
||||||
|
|
||||||
|
# Import environment specific config. This must remain at the bottom
|
||||||
|
# of this file so it overrides the configuration defined above.
|
||||||
|
import_config "#{config_env()}.exs"
|
71
config/dev.exs
Normal file
71
config/dev.exs
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
import Config
|
||||||
|
|
||||||
|
# Configure your database
|
||||||
|
config :minisome, Minisome.Storage.Repo,
|
||||||
|
database: Path.expand("../minisome_dev.db", Path.dirname(__ENV__.file)),
|
||||||
|
pool_size: 5,
|
||||||
|
show_sensitive_data_on_connection_error: true
|
||||||
|
|
||||||
|
# For development, we disable any cache and enable
|
||||||
|
# debugging and code reloading.
|
||||||
|
#
|
||||||
|
# The watchers configuration can be used to run external
|
||||||
|
# watchers to your application. For example, we use it
|
||||||
|
# with esbuild to bundle .js and .css sources.
|
||||||
|
config :minisome, Minisome.Web.Endpoint,
|
||||||
|
# Binding to loopback ipv4 address prevents access from other machines.
|
||||||
|
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
|
||||||
|
http: [ip: {127, 0, 0, 1}, port: 4000],
|
||||||
|
check_origin: false,
|
||||||
|
code_reloader: true,
|
||||||
|
debug_errors: true,
|
||||||
|
secret_key_base: "MR3TEt40ApczckU3+IRzAi91t5iNhbiRt4l0ChL30DdADwAwtdfa++i+NX0ezfc1",
|
||||||
|
watchers: [
|
||||||
|
# Start the esbuild watcher by calling Esbuild.install_and_run(:default, args)
|
||||||
|
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]}
|
||||||
|
]
|
||||||
|
|
||||||
|
# ## SSL Support
|
||||||
|
#
|
||||||
|
# In order to use HTTPS in development, a self-signed
|
||||||
|
# certificate can be generated by running the following
|
||||||
|
# Mix task:
|
||||||
|
#
|
||||||
|
# mix phx.gen.cert
|
||||||
|
#
|
||||||
|
# Note that this task requires Erlang/OTP 20 or later.
|
||||||
|
# Run `mix help phx.gen.cert` for more information.
|
||||||
|
#
|
||||||
|
# The `http:` config above can be replaced with:
|
||||||
|
#
|
||||||
|
# https: [
|
||||||
|
# port: 4001,
|
||||||
|
# cipher_suite: :strong,
|
||||||
|
# keyfile: "priv/cert/selfsigned_key.pem",
|
||||||
|
# certfile: "priv/cert/selfsigned.pem"
|
||||||
|
# ],
|
||||||
|
#
|
||||||
|
# If desired, both `http:` and `https:` keys can be
|
||||||
|
# configured to run both http and https servers on
|
||||||
|
# different ports.
|
||||||
|
|
||||||
|
# Watch static and templates for browser reloading.
|
||||||
|
config :minisome, Minisome.Web.Endpoint,
|
||||||
|
live_reload: [
|
||||||
|
patterns: [
|
||||||
|
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
|
||||||
|
~r"priv/gettext/.*(po)$",
|
||||||
|
~r"lib/web/(live|views)/.*(ex)$",
|
||||||
|
~r"lib/web/templates/.*(eex)$"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
# Do not include metadata nor timestamps in development logs
|
||||||
|
config :logger, :console, format: "[$level] $message\n"
|
||||||
|
|
||||||
|
# Set a higher stacktrace during development. Avoid configuring such
|
||||||
|
# in production as building large stacktraces may be expensive.
|
||||||
|
config :phoenix, :stacktrace_depth, 20
|
||||||
|
|
||||||
|
# Initialize plugs at runtime for faster development compilation
|
||||||
|
config :phoenix, :plug_init_mode, :runtime
|
49
config/prod.exs
Normal file
49
config/prod.exs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import Config
|
||||||
|
|
||||||
|
# For production, don't forget to configure the url host
|
||||||
|
# to something meaningful, Phoenix uses this information
|
||||||
|
# when generating URLs.
|
||||||
|
#
|
||||||
|
# Note we also include the path to a cache manifest
|
||||||
|
# containing the digested version of static files. This
|
||||||
|
# manifest is generated by the `mix phx.digest` task,
|
||||||
|
# which you should run after static files are built and
|
||||||
|
# before starting your production server.
|
||||||
|
config :minisome, Minisome.Web.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
|
||||||
|
|
||||||
|
# Do not print debug messages in production
|
||||||
|
config :logger, level: :info
|
||||||
|
|
||||||
|
# ## SSL Support
|
||||||
|
#
|
||||||
|
# To get SSL working, you will need to add the `https` key
|
||||||
|
# to the previous section and set your `:url` port to 443:
|
||||||
|
#
|
||||||
|
# config :minisome, Minisome.Web.Endpoint,
|
||||||
|
# ...,
|
||||||
|
# url: [host: "example.com", port: 443],
|
||||||
|
# https: [
|
||||||
|
# ...,
|
||||||
|
# port: 443,
|
||||||
|
# cipher_suite: :strong,
|
||||||
|
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
|
||||||
|
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
|
||||||
|
# ]
|
||||||
|
#
|
||||||
|
# The `cipher_suite` is set to `:strong` to support only the
|
||||||
|
# latest and more secure SSL ciphers. This means old browsers
|
||||||
|
# and clients may not be supported. You can set it to
|
||||||
|
# `:compatible` for wider support.
|
||||||
|
#
|
||||||
|
# `:keyfile` and `:certfile` expect an absolute path to the key
|
||||||
|
# and cert in disk or a relative path inside priv, for example
|
||||||
|
# "priv/ssl/server.key". For all supported SSL configuration
|
||||||
|
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
|
||||||
|
#
|
||||||
|
# We also recommend setting `force_ssl` in your endpoint, ensuring
|
||||||
|
# no data is ever sent via http, always redirecting to https:
|
||||||
|
#
|
||||||
|
# config :minisome, Minisome.Web.Endpoint,
|
||||||
|
# force_ssl: [hsts: true]
|
||||||
|
#
|
||||||
|
# Check `Plug.SSL` for all available options in `force_ssl`.
|
63
config/runtime.exs
Normal file
63
config/runtime.exs
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
import Config
|
||||||
|
|
||||||
|
# config/runtime.exs is executed for all environments, including
|
||||||
|
# during releases. It is executed after compilation and before the
|
||||||
|
# system starts, so it is typically used to load production configuration
|
||||||
|
# and secrets from environment variables or elsewhere. Do not define
|
||||||
|
# any compile-time configuration in here, as it won't be applied.
|
||||||
|
# The block below contains prod specific runtime configuration.
|
||||||
|
|
||||||
|
# Start the phoenix server if environment is set and running in a release
|
||||||
|
if System.get_env("PHX_SERVER") && System.get_env("RELEASE_NAME") do
|
||||||
|
config :minisome, Minisome.Web.Endpoint, server: true
|
||||||
|
end
|
||||||
|
|
||||||
|
if config_env() == :prod do
|
||||||
|
database_path =
|
||||||
|
System.get_env("DATABASE_PATH") ||
|
||||||
|
raise """
|
||||||
|
environment variable DATABASE_PATH is missing.
|
||||||
|
For example: /etc/minisome/minisome.db
|
||||||
|
"""
|
||||||
|
|
||||||
|
config :minisome, Minisome.Storage.Repo,
|
||||||
|
database: database_path,
|
||||||
|
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "5")
|
||||||
|
|
||||||
|
# The secret key base is used to sign/encrypt cookies and other secrets.
|
||||||
|
# A default value is used in config/dev.exs and config/test.exs but you
|
||||||
|
# want to use a different value for prod and you most likely don't want
|
||||||
|
# to check this value into version control, so we use an environment
|
||||||
|
# variable instead.
|
||||||
|
secret_key_base =
|
||||||
|
System.get_env("SECRET_KEY_BASE") ||
|
||||||
|
raise """
|
||||||
|
environment variable SECRET_KEY_BASE is missing.
|
||||||
|
You can generate one by calling: mix phx.gen.secret
|
||||||
|
"""
|
||||||
|
|
||||||
|
host = System.get_env("PHX_HOST") || "example.com"
|
||||||
|
port = String.to_integer(System.get_env("PORT") || "4000")
|
||||||
|
|
||||||
|
config :minisome, Minisome.Web.Endpoint,
|
||||||
|
url: [host: host, port: 443],
|
||||||
|
http: [
|
||||||
|
# Enable IPv6 and bind on all interfaces.
|
||||||
|
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
|
||||||
|
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
|
||||||
|
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
|
||||||
|
ip: {0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
|
port: port
|
||||||
|
],
|
||||||
|
secret_key_base: secret_key_base
|
||||||
|
|
||||||
|
# ## Using releases
|
||||||
|
#
|
||||||
|
# If you are doing OTP releases, you need to instruct Phoenix
|
||||||
|
# to start each relevant endpoint:
|
||||||
|
#
|
||||||
|
# config :minisome, Minisome.Web.Endpoint, server: true
|
||||||
|
#
|
||||||
|
# Then you can assemble a release by calling `mix release`.
|
||||||
|
# See `mix help release` for more information.
|
||||||
|
end
|
24
config/test.exs
Normal file
24
config/test.exs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import Config
|
||||||
|
|
||||||
|
# Configure your database
|
||||||
|
#
|
||||||
|
# The MIX_TEST_PARTITION environment variable can be used
|
||||||
|
# to provide built-in test partitioning in CI environment.
|
||||||
|
# Run `mix help test` for more information.
|
||||||
|
config :minisome, Minisome.Storage.Repo,
|
||||||
|
database: Path.expand("../minisome_test.db", Path.dirname(__ENV__.file)),
|
||||||
|
pool_size: 5,
|
||||||
|
pool: Ecto.Adapters.SQL.Sandbox
|
||||||
|
|
||||||
|
# We don't run a server during test. If one is required,
|
||||||
|
# you can enable the server option below.
|
||||||
|
config :minisome, Minisome.Web.Endpoint,
|
||||||
|
http: [ip: {127, 0, 0, 1}, port: 4002],
|
||||||
|
secret_key_base: "nlj8uUOi1lhYBQz7cO87ICbxJSAOoKEEqmf0qWJs3Gs2h4XyJKqzBpM6MFmM2nkG",
|
||||||
|
server: false
|
||||||
|
|
||||||
|
# Print only warnings and errors during test
|
||||||
|
config :logger, level: :warn
|
||||||
|
|
||||||
|
# Initialize plugs at runtime for faster test compilation
|
||||||
|
config :phoenix, :plug_init_mode, :runtime
|
44
lib/api/client/message.ex
Normal file
44
lib/api/client/message.ex
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
defmodule Minisome.API.Client.Message do
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
import Minisome.Utils.TypedStruct
|
||||||
|
|
||||||
|
alias Minisome.Crypto.SSH
|
||||||
|
|
||||||
|
defmodule RawMessage do
|
||||||
|
deftypedstruct(%{
|
||||||
|
data: binary(),
|
||||||
|
signature: SSH.Signature.t()
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec parse_message(binary()) :: RawMessage.t() | nil
|
||||||
|
def parse_message(data) do
|
||||||
|
with {:split, [sig_part, data_part]} <- {:split, :binary.split(data, SSH.openssh_sig_end())},
|
||||||
|
sig_data = sig_part <> SSH.openssh_sig_end(),
|
||||||
|
{:ok, signature} <- SSH.parse_signature(sig_data),
|
||||||
|
{:ok, parsed_data} <- data_part |> String.trim() |> Base.decode64() do
|
||||||
|
%RawMessage{
|
||||||
|
data: parsed_data,
|
||||||
|
signature: signature
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{:error, error} ->
|
||||||
|
Logger.warning("Unable to parse message due to: #{inspect(error)}")
|
||||||
|
nil
|
||||||
|
|
||||||
|
{:split, _} ->
|
||||||
|
Logger.warning("Unable to parse message due to missing footer")
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec format_message(RawMessage.t()) :: String.t()
|
||||||
|
def format_message(%RawMessage{} = msg) do
|
||||||
|
"""
|
||||||
|
#{SSH.format_signature(msg.signature)}
|
||||||
|
|
||||||
|
#{Base.encode64(msg.data)}
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
end
|
36
lib/application.ex
Normal file
36
lib/application.ex
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
defmodule Minisome.Application do
|
||||||
|
# See https://hexdocs.pm/elixir/Application.html
|
||||||
|
# for more information on OTP Applications
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
use Application
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def start(_type, _args) do
|
||||||
|
children = [
|
||||||
|
# Start the Ecto repository
|
||||||
|
Minisome.Storage.Repo,
|
||||||
|
# Start the Telemetry supervisor
|
||||||
|
Minisome.Web.Telemetry,
|
||||||
|
# Start the PubSub system
|
||||||
|
{Phoenix.PubSub, name: Minisome.PubSub},
|
||||||
|
# Start the Endpoint (http/https)
|
||||||
|
Minisome.Web.Endpoint
|
||||||
|
# Start a worker by calling: Minisome.Worker.start_link(arg)
|
||||||
|
# {Minisome.Worker, arg}
|
||||||
|
]
|
||||||
|
|
||||||
|
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||||
|
# for other strategies and supported options
|
||||||
|
opts = [strategy: :one_for_one, name: Minisome.Supervisor]
|
||||||
|
Supervisor.start_link(children, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Tell Phoenix to update the endpoint configuration
|
||||||
|
# whenever the application is updated.
|
||||||
|
@impl true
|
||||||
|
def config_change(changed, _new, removed) do
|
||||||
|
Minisome.Web.Endpoint.config_change(changed, removed)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
273
lib/crypto/ssh.ex
Normal file
273
lib/crypto/ssh.ex
Normal file
|
@ -0,0 +1,273 @@
|
||||||
|
defmodule Minisome.Crypto.SSH do
|
||||||
|
@moduledoc """
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
import Minisome.Utils.TypedStruct
|
||||||
|
|
||||||
|
@default_namespace "minisome"
|
||||||
|
@default_hash :sha512
|
||||||
|
@reserved_data ""
|
||||||
|
@magic_preamble "SSHSIG"
|
||||||
|
@sig_version 1
|
||||||
|
|
||||||
|
@openssh_sig_start "-----BEGIN SSH SIGNATURE-----"
|
||||||
|
@openssh_sig_end "-----END SSH SIGNATURE-----"
|
||||||
|
@openssh_sig_line_length 76
|
||||||
|
|
||||||
|
@type hash_algo :: :sha256 | :sha512
|
||||||
|
|
||||||
|
defmodule PrivateKey do
|
||||||
|
deftypedstruct(%{
|
||||||
|
data: :public_key.private_key()
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
defmodule PublicKey do
|
||||||
|
deftypedstruct(%{
|
||||||
|
data: :public_key.public_key()
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
defmodule KeyPair do
|
||||||
|
deftypedstruct(%{
|
||||||
|
private: PrivateKey.t(),
|
||||||
|
public: PublicKey.t()
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
defmodule Signature do
|
||||||
|
deftypedstruct(%{
|
||||||
|
signature: binary(),
|
||||||
|
namespace: binary(),
|
||||||
|
hash: Minisome.Crypto.SSH.hash_algo(),
|
||||||
|
keys: [PublicKey.t()]
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec load_key_pair(binary()) :: {:ok, KeyPair.t()} | :error
|
||||||
|
def load_key_pair(data) do
|
||||||
|
case :ssh_file.decode(data, :public_key) do
|
||||||
|
[{privk, _priv_meta}, {pubk, _pub_meta}] ->
|
||||||
|
{:ok, %KeyPair{public: %PublicKey{data: pubk}, private: %PrivateKey{data: privk}}}
|
||||||
|
|
||||||
|
[] ->
|
||||||
|
:error
|
||||||
|
|
||||||
|
{:error, _} ->
|
||||||
|
:error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec sign(binary(), KeyPair.t(), binary(), hash_algo()) :: Signature.t()
|
||||||
|
def sign(data, %KeyPair{} = keys, namespace \\ @default_namespace, hash \\ @default_hash) do
|
||||||
|
payload = form_payload(data, namespace, hash)
|
||||||
|
signature = :public_key.sign(payload, hash, keys.private.data)
|
||||||
|
|
||||||
|
%Signature{
|
||||||
|
signature: signature,
|
||||||
|
namespace: namespace,
|
||||||
|
hash: hash,
|
||||||
|
keys: [keys.public.data]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec verify(binary(), Signature.t(), PublicKey.t()) :: boolean()
|
||||||
|
def verify(
|
||||||
|
data,
|
||||||
|
%Signature{signature: signature, namespace: namespace, hash: hash},
|
||||||
|
%PublicKey{data: key}
|
||||||
|
) do
|
||||||
|
payload = form_payload(data, namespace, hash)
|
||||||
|
:public_key.verify(payload, hash, signature, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec format_signature(Signature.t()) :: binary()
|
||||||
|
def format_signature(%Signature{
|
||||||
|
signature: signature,
|
||||||
|
namespace: namespace,
|
||||||
|
hash: hash,
|
||||||
|
keys: [key | _]
|
||||||
|
}) do
|
||||||
|
key_part = ssh_string(pub_key_to_ssh_name(key)) <> ssh_string(pub_key_extract(key))
|
||||||
|
sig_part = ssh_string(pub_key_to_ssh_name(key)) <> ssh_string(signature)
|
||||||
|
|
||||||
|
blob =
|
||||||
|
@magic_preamble <>
|
||||||
|
<<@sig_version::unsigned-integer-32>> <>
|
||||||
|
ssh_string(key_part) <>
|
||||||
|
ssh_string(namespace) <>
|
||||||
|
ssh_string(@reserved_data) <>
|
||||||
|
ssh_string(hash |> Atom.to_string()) <>
|
||||||
|
ssh_string(sig_part)
|
||||||
|
|
||||||
|
blob_str = Base.encode64(blob)
|
||||||
|
blob_size = byte_size(blob_str)
|
||||||
|
|
||||||
|
blob_split =
|
||||||
|
Enum.reduce_while(0..blob_size//@openssh_sig_line_length, "", fn index, acc ->
|
||||||
|
length = min(@openssh_sig_line_length, blob_size - index)
|
||||||
|
part = :binary.part(blob_str, index, length)
|
||||||
|
next_acc = acc <> part <> "\n"
|
||||||
|
|
||||||
|
if index + @openssh_sig_line_length < blob_size do
|
||||||
|
{:cont, next_acc}
|
||||||
|
else
|
||||||
|
{:halt, next_acc}
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
"#{@openssh_sig_start}\n" <>
|
||||||
|
blob_split <>
|
||||||
|
"#{@openssh_sig_end}\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec parse_signature(binary()) :: {:ok, Signature.t()} | {:error, atom()}
|
||||||
|
def parse_signature(signature) do
|
||||||
|
signature = :binary.replace(signature, "\n", "", [:global])
|
||||||
|
inner_start = byte_size(@openssh_sig_start)
|
||||||
|
inner_end = byte_size(signature) - byte_size(@openssh_sig_start) - byte_size(@openssh_sig_end)
|
||||||
|
data = :binary.part(signature, inner_start, inner_end)
|
||||||
|
|
||||||
|
with {:base64, {:ok, decoded}} <- {:base64, Base.decode64(data)},
|
||||||
|
{:ok, after_preamble} <- parse_preamble(decoded),
|
||||||
|
{:ok, public_keys, after_keys} <- parse_keys(after_preamble),
|
||||||
|
{:ok, namespace, after_namespace} <- parse_namespace(after_keys),
|
||||||
|
{:ok, after_reserved} <- parse_reserved(after_namespace),
|
||||||
|
{:ok, hash, after_hash} <- parse_hash(after_reserved),
|
||||||
|
{:ok, signature} <- parse_signature_part(after_hash) do
|
||||||
|
{:ok,
|
||||||
|
%Signature{
|
||||||
|
signature: signature,
|
||||||
|
namespace: namespace,
|
||||||
|
hash: hash,
|
||||||
|
keys: public_keys
|
||||||
|
}}
|
||||||
|
else
|
||||||
|
{:base64, _} -> {:error, :base64}
|
||||||
|
error -> error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec form_payload(binary(), binary(), hash_algo()) :: binary()
|
||||||
|
def form_payload(data, namespace, hash) do
|
||||||
|
digest = :crypto.hash(hash, data)
|
||||||
|
|
||||||
|
@magic_preamble <>
|
||||||
|
ssh_string(namespace) <>
|
||||||
|
ssh_string(@reserved_data) <>
|
||||||
|
ssh_string(hash |> Atom.to_string()) <>
|
||||||
|
ssh_string(digest)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec ssh_string(binary()) :: <<_::32, _::_*8>>
|
||||||
|
def ssh_string(data), do: <<byte_size(data)::unsigned-integer-32>> <> data
|
||||||
|
|
||||||
|
@spec pub_key_to_ssh_name(:public_key.public_key()) :: String.t()
|
||||||
|
def pub_key_to_ssh_name(key)
|
||||||
|
|
||||||
|
def pub_key_to_ssh_name({:ed_pub, :ed25519, _}), do: "ssh-ed25519"
|
||||||
|
def pub_key_to_ssh_name(key), do: raise("Unknown key type #{inspect(key)}")
|
||||||
|
|
||||||
|
@spec pub_key_extract(:public_key.public_key()) :: binary()
|
||||||
|
def pub_key_extract(key)
|
||||||
|
|
||||||
|
def pub_key_extract({:ed_pub, _, key}), do: key
|
||||||
|
def pub_key_extract(key), do: raise("Unknown key type #{inspect(key)}")
|
||||||
|
|
||||||
|
@spec openssh_sig_start() :: String.t()
|
||||||
|
def openssh_sig_start(), do: @openssh_sig_start
|
||||||
|
|
||||||
|
@spec openssh_sig_end() :: String.t()
|
||||||
|
def openssh_sig_end(), do: @openssh_sig_end
|
||||||
|
|
||||||
|
@spec parse_preamble(binary()) :: {:ok, binary()} | {:error, atom()}
|
||||||
|
defp parse_preamble(blob)
|
||||||
|
|
||||||
|
defp parse_preamble(<<
|
||||||
|
@magic_preamble,
|
||||||
|
sig_version::unsigned-integer-32,
|
||||||
|
rest::binary
|
||||||
|
>>)
|
||||||
|
when sig_version == @sig_version,
|
||||||
|
do: {:ok, rest}
|
||||||
|
|
||||||
|
defp parse_preamble(<<
|
||||||
|
@magic_preamble,
|
||||||
|
_sig_version::unsigned-integer-32,
|
||||||
|
_rest::binary
|
||||||
|
>>),
|
||||||
|
do: {:error, :version}
|
||||||
|
|
||||||
|
defp parse_preamble(_), do: {:error, :preamble}
|
||||||
|
|
||||||
|
@spec parse_keys(binary()) :: {:ok, [PublicKey.t()], binary()} | {:error, atom()}
|
||||||
|
defp parse_keys(blob)
|
||||||
|
|
||||||
|
defp parse_keys(
|
||||||
|
<<key_blob_len::unsigned-integer-32, key_blob::binary-size(key_blob_len), rest::binary>>
|
||||||
|
) do
|
||||||
|
case :ssh_file.decode(key_blob, :ssh2_pubkey) do
|
||||||
|
{:error, _} -> {:error, :keys}
|
||||||
|
keys when is_list(keys) -> {:ok, Enum.map(keys, &%PublicKey{data: &1}), rest}
|
||||||
|
single_key -> {:ok, [%PublicKey{data: single_key}], rest}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp parse_keys(_), do: {:error, :key}
|
||||||
|
|
||||||
|
@spec parse_namespace(binary()) :: {:ok, binary(), binary()} | {:error, atom()}
|
||||||
|
defp parse_namespace(blob)
|
||||||
|
|
||||||
|
defp parse_namespace(
|
||||||
|
<<namespace_len::unsigned-integer-32, namespace::binary-size(namespace_len),
|
||||||
|
rest::binary>>
|
||||||
|
),
|
||||||
|
do: {:ok, namespace, rest}
|
||||||
|
|
||||||
|
defp parse_namespace(_), do: {:error, :namespace}
|
||||||
|
|
||||||
|
@spec parse_reserved(binary()) :: {:ok, binary()} | {:error, atom()}
|
||||||
|
defp parse_reserved(blob)
|
||||||
|
|
||||||
|
defp parse_reserved(
|
||||||
|
<<reserved_len::unsigned-integer-32, _reserved::binary-size(reserved_len), rest::binary>>
|
||||||
|
),
|
||||||
|
do: {:ok, rest}
|
||||||
|
|
||||||
|
defp parse_reserved(_), do: {:error, :reserved}
|
||||||
|
|
||||||
|
@spec parse_hash(binary()) :: {:ok, hash_algo(), binary()} | {:error, atom()}
|
||||||
|
defp parse_hash(blob)
|
||||||
|
|
||||||
|
defp parse_hash(<<hash_len::unsigned-integer-32, hash::binary-size(hash_len), rest::binary>>)
|
||||||
|
when hash in ["sha256", "sha512"],
|
||||||
|
do: {:ok, String.to_existing_atom(hash), rest}
|
||||||
|
|
||||||
|
defp parse_hash(_), do: {:error, :hash}
|
||||||
|
|
||||||
|
@spec parse_signature_part(binary()) :: {:ok, binary()} | {:error, atom()}
|
||||||
|
defp parse_signature_part(blob)
|
||||||
|
|
||||||
|
defp parse_signature_part(<<
|
||||||
|
signature_blob_len::unsigned-integer-32,
|
||||||
|
signature_blob::binary-size(signature_blob_len)
|
||||||
|
>>) do
|
||||||
|
case signature_blob do
|
||||||
|
<<
|
||||||
|
key_type_len::unsigned-integer-32,
|
||||||
|
_key_type::binary-size(key_type_len),
|
||||||
|
signature_len::unsigned-integer-32,
|
||||||
|
signature::binary-size(signature_len)
|
||||||
|
>> ->
|
||||||
|
{:ok, signature}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
{:error, :signature}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp parse_signature_part(_), do: {:error, :signature}
|
||||||
|
end
|
5
lib/storage/repo.ex
Normal file
5
lib/storage/repo.ex
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
defmodule Minisome.Storage.Repo do
|
||||||
|
use Ecto.Repo,
|
||||||
|
otp_app: :minisome,
|
||||||
|
adapter: Ecto.Adapters.SQLite3
|
||||||
|
end
|
71
lib/utils/typed_struct.ex
Normal file
71
lib/utils/typed_struct.ex
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
defmodule Minisome.Utils.TypedStruct do
|
||||||
|
@doc """
|
||||||
|
Create typed struct with a type, default values, and enforced keys.
|
||||||
|
|
||||||
|
Input should be a map where the key names are names of the struct keys and values are the
|
||||||
|
field information. The value can be a typespec, in which case the field will be enforced, or
|
||||||
|
a 2-tuple of `{typespec, default_value}`, making the field unenforced.
|
||||||
|
|
||||||
|
To prevent ambiguity, a value of `{typespec, :ts_enforced}` will be interpreted as enforced,
|
||||||
|
this will allow you to typespec a 2-tuple.
|
||||||
|
|
||||||
|
NOTE: Due to the ambiguity removal technique above, `:ts_enforced` is not allowed as a default
|
||||||
|
value.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
deftypedstruct(%{
|
||||||
|
# Enforced with simple type
|
||||||
|
foo: integer(),
|
||||||
|
|
||||||
|
# Enforced 2-tuple typed field, written like this to remove ambiguity
|
||||||
|
bar: {{String.t(), integer()}, :ts_enforced},
|
||||||
|
|
||||||
|
# Non-enforced field with default value
|
||||||
|
baz: {any(), ""}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
defmacro deftypedstruct(fields) do
|
||||||
|
fields_list =
|
||||||
|
case fields do
|
||||||
|
{:%{}, _, flist} -> flist
|
||||||
|
_ -> raise ArgumentError, "Fields must be a map!"
|
||||||
|
end
|
||||||
|
|
||||||
|
enforced_list =
|
||||||
|
fields_list
|
||||||
|
|> Enum.filter(fn
|
||||||
|
{_, {_, :ts_enforced}} -> true
|
||||||
|
{_, {_, _}} -> false
|
||||||
|
{_, _} -> true
|
||||||
|
end)
|
||||||
|
|> Enum.map(&elem(&1, 0))
|
||||||
|
|
||||||
|
field_specs =
|
||||||
|
Enum.map(fields_list, fn
|
||||||
|
{field, {typespec, :ts_enforced}} ->
|
||||||
|
{field, typespec}
|
||||||
|
|
||||||
|
{field, {typespec, _}} ->
|
||||||
|
{field, typespec}
|
||||||
|
|
||||||
|
{field, typespec} ->
|
||||||
|
{field, typespec}
|
||||||
|
end)
|
||||||
|
|
||||||
|
field_vals =
|
||||||
|
Enum.map(fields_list, fn
|
||||||
|
{field, {_, :ts_enforced}} -> field
|
||||||
|
{field, {_, default}} -> {field, default}
|
||||||
|
{field, _} -> field
|
||||||
|
end)
|
||||||
|
|
||||||
|
quote do
|
||||||
|
@type t :: %__MODULE__{unquote_splicing(field_specs)}
|
||||||
|
@enforce_keys unquote(enforced_list)
|
||||||
|
defstruct unquote(field_vals)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
7
lib/web/controllers/page_controller.ex
Normal file
7
lib/web/controllers/page_controller.ex
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
defmodule Minisome.Web.PageController do
|
||||||
|
use Minisome.Web, :controller
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
render(conn, "index.html")
|
||||||
|
end
|
||||||
|
end
|
46
lib/web/endpoint.ex
Normal file
46
lib/web/endpoint.ex
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
defmodule Minisome.Web.Endpoint do
|
||||||
|
use Phoenix.Endpoint, otp_app: :minisome
|
||||||
|
|
||||||
|
# The session will be stored in the cookie and signed,
|
||||||
|
# this means its contents can be read but not tampered with.
|
||||||
|
# Set :encryption_salt if you would also like to encrypt it.
|
||||||
|
@session_options [
|
||||||
|
store: :cookie,
|
||||||
|
key: "_minisome_key",
|
||||||
|
signing_salt: "VhOEnuhn"
|
||||||
|
]
|
||||||
|
|
||||||
|
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
|
||||||
|
|
||||||
|
# Serve at "/" the static files from "priv/static" directory.
|
||||||
|
#
|
||||||
|
# You should set gzip to true if you are running phx.digest
|
||||||
|
# when deploying your static files in production.
|
||||||
|
plug Plug.Static,
|
||||||
|
at: "/",
|
||||||
|
from: :minisome,
|
||||||
|
gzip: false,
|
||||||
|
only: ~w(assets fonts images favicon.ico robots.txt)
|
||||||
|
|
||||||
|
# Code reloading can be explicitly enabled under the
|
||||||
|
# :code_reloader configuration of your endpoint.
|
||||||
|
if code_reloading? do
|
||||||
|
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
|
||||||
|
plug Phoenix.LiveReloader
|
||||||
|
plug Phoenix.CodeReloader
|
||||||
|
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :minisome
|
||||||
|
end
|
||||||
|
|
||||||
|
plug Plug.RequestId
|
||||||
|
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
|
||||||
|
|
||||||
|
plug Plug.Parsers,
|
||||||
|
parsers: [:urlencoded, :multipart, :json],
|
||||||
|
pass: ["*/*"],
|
||||||
|
json_decoder: Phoenix.json_library()
|
||||||
|
|
||||||
|
plug Plug.MethodOverride
|
||||||
|
plug Plug.Head
|
||||||
|
plug Plug.Session, @session_options
|
||||||
|
plug Minisome.Web.Router
|
||||||
|
end
|
24
lib/web/gettext.ex
Normal file
24
lib/web/gettext.ex
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
defmodule Minisome.Web.Gettext do
|
||||||
|
@moduledoc """
|
||||||
|
A module providing Internationalization with a gettext-based API.
|
||||||
|
|
||||||
|
By using [Gettext](https://hexdocs.pm/gettext),
|
||||||
|
your module gains a set of macros for translations, for example:
|
||||||
|
|
||||||
|
import Minisome.Web.Gettext
|
||||||
|
|
||||||
|
# Simple translation
|
||||||
|
gettext("Here is the string to translate")
|
||||||
|
|
||||||
|
# Plural translation
|
||||||
|
ngettext("Here is the string to translate",
|
||||||
|
"Here are the strings to translate",
|
||||||
|
3)
|
||||||
|
|
||||||
|
# Domain-based translation
|
||||||
|
dgettext("errors", "Here is the error message to translate")
|
||||||
|
|
||||||
|
See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage.
|
||||||
|
"""
|
||||||
|
use Gettext, otp_app: :minisome
|
||||||
|
end
|
3
lib/web/live/private_main.ex
Normal file
3
lib/web/live/private_main.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule Minisome.Web.Live.PrivateMain do
|
||||||
|
use Minisome.Web, :live_view
|
||||||
|
end
|
3
lib/web/live/private_main.html.heex
Normal file
3
lib/web/live/private_main.html.heex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Hey!
|
||||||
|
|
||||||
|
<%= live_redirect("Key testing", to: Routes.live_path(@socket, Minisome.Web.Live.Signing)) %>
|
59
lib/web/live/signing.ex
Normal file
59
lib/web/live/signing.ex
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
defmodule Minisome.Web.Live.Signing do
|
||||||
|
use Minisome.Web, :live_view
|
||||||
|
|
||||||
|
alias Minisome.Crypto.SSH
|
||||||
|
alias Minisome.API.Client.Message
|
||||||
|
|
||||||
|
@impl Phoenix.LiveView
|
||||||
|
def mount(_params, _session, socket) do
|
||||||
|
socket =
|
||||||
|
assign(socket,
|
||||||
|
keys: nil,
|
||||||
|
input: "",
|
||||||
|
signed: "",
|
||||||
|
verified: false,
|
||||||
|
verified_msg: ""
|
||||||
|
)
|
||||||
|
|
||||||
|
{:ok, socket}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl Phoenix.LiveView
|
||||||
|
def handle_event(event, value, socket)
|
||||||
|
|
||||||
|
def handle_event("set_key", %{"value" => key}, socket) do
|
||||||
|
case SSH.load_key_pair(key) do
|
||||||
|
{:ok, key_pair} ->
|
||||||
|
{:noreply, assign(socket, keys: key_pair)}
|
||||||
|
|
||||||
|
:error ->
|
||||||
|
{:noreply, assign(socket, keys: nil)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_event("set_input", %{"value" => input}, socket) do
|
||||||
|
full_message =
|
||||||
|
if not is_nil(socket.assigns.keys) do
|
||||||
|
signature = SSH.sign(input, socket.assigns.keys)
|
||||||
|
|
||||||
|
raw = %Message.RawMessage{data: input, signature: signature}
|
||||||
|
Message.format_message(raw)
|
||||||
|
else
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
|
parsed_message = Message.parse_message(full_message)
|
||||||
|
|
||||||
|
verified =
|
||||||
|
SSH.verify(parsed_message.data, parsed_message.signature, socket.assigns.keys.public) and
|
||||||
|
parsed_message.data == input
|
||||||
|
|
||||||
|
{:noreply,
|
||||||
|
assign(socket,
|
||||||
|
input: input,
|
||||||
|
signed: full_message,
|
||||||
|
verified: verified,
|
||||||
|
verified_msg: parsed_message.data
|
||||||
|
)}
|
||||||
|
end
|
||||||
|
end
|
23
lib/web/live/signing.html.heex
Normal file
23
lib/web/live/signing.html.heex
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<h1>Key tester</h1>
|
||||||
|
|
||||||
|
<textarea placeholder="Key…" phx-keyup="set_key" phx-update="ignore"></textarea>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Private key: <%= if not is_nil(@keys), do: "Obtained", else: "Missing" %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Public key: <%= if not is_nil(@keys), do: inspect(@keys.public.data), else: "Missing" %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<textarea placeholder="Input…" phx-keyup="set_input"><%= @input %></textarea>
|
||||||
|
|
||||||
|
<textarea readonly><%= @signed %></textarea>
|
||||||
|
|
||||||
|
<%= if @verified do %>
|
||||||
|
<h3>Verified!</h3>
|
||||||
|
<% else %>
|
||||||
|
<h3>Not verified!</h3>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<p><%= @verified_msg %></p>
|
110
lib/web/minisome_web.ex
Normal file
110
lib/web/minisome_web.ex
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
defmodule Minisome.Web do
|
||||||
|
@moduledoc """
|
||||||
|
The entrypoint for defining your web interface, such
|
||||||
|
as controllers, views, channels and so on.
|
||||||
|
|
||||||
|
This can be used in your application as:
|
||||||
|
|
||||||
|
use Minisome.Web, :controller
|
||||||
|
use Minisome.Web, :view
|
||||||
|
|
||||||
|
The definitions below will be executed for every view,
|
||||||
|
controller, etc, so keep them short and clean, focused
|
||||||
|
on imports, uses and aliases.
|
||||||
|
|
||||||
|
Do NOT define functions inside the quoted expressions
|
||||||
|
below. Instead, define any helper function in modules
|
||||||
|
and import those modules here.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def controller do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Controller, namespace: Minisome.Web
|
||||||
|
|
||||||
|
import Plug.Conn
|
||||||
|
import Minisome.Web.Gettext
|
||||||
|
alias Minisome.Web.Router.Helpers, as: Routes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def view do
|
||||||
|
quote do
|
||||||
|
use Phoenix.View,
|
||||||
|
root: "lib/web/templates",
|
||||||
|
namespace: Minisome.Web
|
||||||
|
|
||||||
|
# Import convenience functions from controllers
|
||||||
|
import Phoenix.Controller,
|
||||||
|
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
|
||||||
|
|
||||||
|
# Include shared imports and aliases for views
|
||||||
|
unquote(view_helpers())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def live_view do
|
||||||
|
quote do
|
||||||
|
use Phoenix.LiveView,
|
||||||
|
layout: {Minisome.Web.LayoutView, "live.html"}
|
||||||
|
|
||||||
|
unquote(view_helpers())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def live_component do
|
||||||
|
quote do
|
||||||
|
use Phoenix.LiveComponent
|
||||||
|
|
||||||
|
unquote(view_helpers())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def component do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Component
|
||||||
|
|
||||||
|
unquote(view_helpers())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def router do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Router
|
||||||
|
|
||||||
|
import Plug.Conn
|
||||||
|
import Phoenix.Controller
|
||||||
|
import Phoenix.LiveView.Router
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def channel do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Channel
|
||||||
|
import Minisome.Web.Gettext
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp view_helpers do
|
||||||
|
quote do
|
||||||
|
# Use all HTML functionality (forms, tags, etc)
|
||||||
|
use Phoenix.HTML
|
||||||
|
|
||||||
|
# Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)
|
||||||
|
import Phoenix.LiveView.Helpers
|
||||||
|
|
||||||
|
# Import basic rendering functionality (render, render_layout, etc)
|
||||||
|
import Phoenix.View
|
||||||
|
|
||||||
|
import Minisome.Web.ErrorHelpers
|
||||||
|
import Minisome.Web.Gettext
|
||||||
|
alias Minisome.Web.Router.Helpers, as: Routes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
When used, dispatch to the appropriate controller/view/etc.
|
||||||
|
"""
|
||||||
|
defmacro __using__(which) when is_atom(which) do
|
||||||
|
apply(__MODULE__, which, [])
|
||||||
|
end
|
||||||
|
end
|
34
lib/web/router.ex
Normal file
34
lib/web/router.ex
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
defmodule Minisome.Web.Router do
|
||||||
|
use Minisome.Web, :router
|
||||||
|
|
||||||
|
pipeline :browser do
|
||||||
|
plug :accepts, ["html"]
|
||||||
|
plug :fetch_session
|
||||||
|
plug :fetch_live_flash
|
||||||
|
plug :put_root_layout, {Minisome.Web.LayoutView, :root}
|
||||||
|
plug :protect_from_forgery
|
||||||
|
plug :put_secure_browser_headers
|
||||||
|
end
|
||||||
|
|
||||||
|
pipeline :api do
|
||||||
|
plug :accepts, ["json"]
|
||||||
|
end
|
||||||
|
|
||||||
|
scope "/", Minisome.Web do
|
||||||
|
pipe_through :browser
|
||||||
|
|
||||||
|
get "/", PageController, :index
|
||||||
|
end
|
||||||
|
|
||||||
|
scope "/private", Minisome.Web do
|
||||||
|
pipe_through :browser
|
||||||
|
|
||||||
|
live "/", Live.PrivateMain
|
||||||
|
live "/key-testing", Live.Signing
|
||||||
|
end
|
||||||
|
|
||||||
|
# Other scopes may use custom stacks.
|
||||||
|
# scope "/api", Minisome.Web do
|
||||||
|
# pipe_through :api
|
||||||
|
# end
|
||||||
|
end
|
71
lib/web/telemetry.ex
Normal file
71
lib/web/telemetry.ex
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
defmodule Minisome.Web.Telemetry do
|
||||||
|
use Supervisor
|
||||||
|
import Telemetry.Metrics
|
||||||
|
|
||||||
|
def start_link(arg) do
|
||||||
|
Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init(_arg) do
|
||||||
|
children = [
|
||||||
|
# Telemetry poller will execute the given period measurements
|
||||||
|
# every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics
|
||||||
|
{:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
|
||||||
|
# Add reporters as children of your supervision tree.
|
||||||
|
# {Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
|
||||||
|
]
|
||||||
|
|
||||||
|
Supervisor.init(children, strategy: :one_for_one)
|
||||||
|
end
|
||||||
|
|
||||||
|
def metrics do
|
||||||
|
[
|
||||||
|
# Phoenix Metrics
|
||||||
|
summary("phoenix.endpoint.stop.duration",
|
||||||
|
unit: {:native, :millisecond}
|
||||||
|
),
|
||||||
|
summary("phoenix.router_dispatch.stop.duration",
|
||||||
|
tags: [:route],
|
||||||
|
unit: {:native, :millisecond}
|
||||||
|
),
|
||||||
|
|
||||||
|
# Database Metrics
|
||||||
|
summary("minisome.repo.query.total_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description: "The sum of the other measurements"
|
||||||
|
),
|
||||||
|
summary("minisome.repo.query.decode_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description: "The time spent decoding the data received from the database"
|
||||||
|
),
|
||||||
|
summary("minisome.repo.query.query_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description: "The time spent executing the query"
|
||||||
|
),
|
||||||
|
summary("minisome.repo.query.queue_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description: "The time spent waiting for a database connection"
|
||||||
|
),
|
||||||
|
summary("minisome.repo.query.idle_time",
|
||||||
|
unit: {:native, :millisecond},
|
||||||
|
description:
|
||||||
|
"The time the connection spent waiting before being checked out for the query"
|
||||||
|
),
|
||||||
|
|
||||||
|
# VM Metrics
|
||||||
|
summary("vm.memory.total", unit: {:byte, :kilobyte}),
|
||||||
|
summary("vm.total_run_queue_lengths.total"),
|
||||||
|
summary("vm.total_run_queue_lengths.cpu"),
|
||||||
|
summary("vm.total_run_queue_lengths.io")
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
defp periodic_measurements do
|
||||||
|
[
|
||||||
|
# A module, function and arguments to be invoked periodically.
|
||||||
|
# This function must call :telemetry.execute/3 and a metric must be added above.
|
||||||
|
# {Minisome.Web, :count_users, []}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
5
lib/web/templates/layout/app.html.heex
Normal file
5
lib/web/templates/layout/app.html.heex
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<main class="container">
|
||||||
|
<p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
|
||||||
|
<p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>
|
||||||
|
<%= @inner_content %>
|
||||||
|
</main>
|
11
lib/web/templates/layout/live.html.heex
Normal file
11
lib/web/templates/layout/live.html.heex
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<main class="container">
|
||||||
|
<p class="alert alert-info" role="alert"
|
||||||
|
phx-click="lv:clear-flash"
|
||||||
|
phx-value-key="info"><%= live_flash(@flash, :info) %></p>
|
||||||
|
|
||||||
|
<p class="alert alert-danger" role="alert"
|
||||||
|
phx-click="lv:clear-flash"
|
||||||
|
phx-value-key="error"><%= live_flash(@flash, :error) %></p>
|
||||||
|
|
||||||
|
<%= @inner_content %>
|
||||||
|
</main>
|
28
lib/web/templates/layout/root.html.heex
Normal file
28
lib/web/templates/layout/root.html.heex
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<%= csrf_meta_tag() %>
|
||||||
|
<%= live_title_tag assigns[:page_title] || "Minisome", suffix: " · Phoenix Framework" %>
|
||||||
|
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")}/>
|
||||||
|
<script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/app.js")}></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<section class="container">
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://hexdocs.pm/phoenix/overview.html">Get Started</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<a href="https://phoenixframework.org/" class="phx-logo">
|
||||||
|
<img src={Routes.static_path(@conn, "/images/phoenix.png")} alt="Phoenix Framework Logo"/>
|
||||||
|
</a>
|
||||||
|
</section>
|
||||||
|
</header>
|
||||||
|
<%= @inner_content %>
|
||||||
|
</body>
|
||||||
|
</html>
|
41
lib/web/templates/page/index.html.heex
Normal file
41
lib/web/templates/page/index.html.heex
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<section class="phx-hero">
|
||||||
|
<h1><%= gettext "Welcome to %{name}!", name: "Phoenix" %></h1>
|
||||||
|
<p>Peace of mind from prototype to production</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="row">
|
||||||
|
<article class="column">
|
||||||
|
<h2>Resources</h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://hexdocs.pm/phoenix/overview.html">Guides & Docs</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://github.com/phoenixframework/phoenix">Source</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://github.com/phoenixframework/phoenix/blob/v1.6/CHANGELOG.md">v1.6 Changelog</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</article>
|
||||||
|
<article class="column">
|
||||||
|
<h2>Help</h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="https://elixirforum.com/c/phoenix-forum">Forum</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://web.libera.chat/#elixir">#elixir on Libera Chat (IRC)</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://twitter.com/elixirphoenix">Twitter @elixirphoenix</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://elixir-slackin.herokuapp.com/">Elixir on Slack</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="https://discord.gg/elixir">Elixir on Discord</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</article>
|
||||||
|
</section>
|
47
lib/web/views/error_helpers.ex
Normal file
47
lib/web/views/error_helpers.ex
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
defmodule Minisome.Web.ErrorHelpers do
|
||||||
|
@moduledoc """
|
||||||
|
Conveniences for translating and building error messages.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use Phoenix.HTML
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Generates tag for inlined form input errors.
|
||||||
|
"""
|
||||||
|
def error_tag(form, field) do
|
||||||
|
Enum.map(Keyword.get_values(form.errors, field), fn error ->
|
||||||
|
content_tag(:span, translate_error(error),
|
||||||
|
class: "invalid-feedback",
|
||||||
|
phx_feedback_for: input_name(form, field)
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Translates an error message using gettext.
|
||||||
|
"""
|
||||||
|
def translate_error({msg, opts}) do
|
||||||
|
# When using gettext, we typically pass the strings we want
|
||||||
|
# to translate as a static argument:
|
||||||
|
#
|
||||||
|
# # Translate "is invalid" in the "errors" domain
|
||||||
|
# dgettext("errors", "is invalid")
|
||||||
|
#
|
||||||
|
# # Translate the number of files with plural rules
|
||||||
|
# dngettext("errors", "1 file", "%{count} files", count)
|
||||||
|
#
|
||||||
|
# Because the error messages we show in our forms and APIs
|
||||||
|
# are defined inside Ecto, we need to translate them dynamically.
|
||||||
|
# This requires us to call the Gettext module passing our gettext
|
||||||
|
# backend as first argument.
|
||||||
|
#
|
||||||
|
# Note we use the "errors" domain, which means translations
|
||||||
|
# should be written to the errors.po file. The :count option is
|
||||||
|
# set by Ecto and indicates we should also apply plural rules.
|
||||||
|
if count = opts[:count] do
|
||||||
|
Gettext.dngettext(Minisome.Web.Gettext, "errors", msg, msg, count, opts)
|
||||||
|
else
|
||||||
|
Gettext.dgettext(Minisome.Web.Gettext, "errors", msg, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
16
lib/web/views/error_view.ex
Normal file
16
lib/web/views/error_view.ex
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
defmodule Minisome.Web.ErrorView do
|
||||||
|
use Minisome.Web, :view
|
||||||
|
|
||||||
|
# If you want to customize a particular status code
|
||||||
|
# for a certain format, you may uncomment below.
|
||||||
|
# def render("500.html", _assigns) do
|
||||||
|
# "Internal Server Error"
|
||||||
|
# end
|
||||||
|
|
||||||
|
# By default, Phoenix returns the status message from
|
||||||
|
# the template name. For example, "404.html" becomes
|
||||||
|
# "Not Found".
|
||||||
|
def template_not_found(template, _assigns) do
|
||||||
|
Phoenix.Controller.status_message_from_template(template)
|
||||||
|
end
|
||||||
|
end
|
7
lib/web/views/layout_view.ex
Normal file
7
lib/web/views/layout_view.ex
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
defmodule Minisome.Web.LayoutView do
|
||||||
|
use Minisome.Web, :view
|
||||||
|
|
||||||
|
# Phoenix LiveDashboard is available only in development by default,
|
||||||
|
# so we instruct Elixir to not warn if the dashboard route is missing.
|
||||||
|
@compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}}
|
||||||
|
end
|
3
lib/web/views/page_view.ex
Normal file
3
lib/web/views/page_view.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule Minisome.Web.PageView do
|
||||||
|
use Minisome.Web, :view
|
||||||
|
end
|
69
mix.exs
Normal file
69
mix.exs
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
defmodule Minisome.MixProject do
|
||||||
|
use Mix.Project
|
||||||
|
|
||||||
|
def project do
|
||||||
|
[
|
||||||
|
app: :minisome,
|
||||||
|
version: "0.1.0",
|
||||||
|
elixir: "~> 1.13",
|
||||||
|
elixirc_paths: elixirc_paths(Mix.env()),
|
||||||
|
compilers: [:gettext] ++ Mix.compilers(),
|
||||||
|
start_permanent: Mix.env() == :prod,
|
||||||
|
aliases: aliases(),
|
||||||
|
deps: deps(),
|
||||||
|
xref: [exclude: [:ssh_file]]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Configuration for the OTP application.
|
||||||
|
#
|
||||||
|
# Type `mix help compile.app` for more information.
|
||||||
|
def application do
|
||||||
|
[
|
||||||
|
mod: {Minisome.Application, []},
|
||||||
|
extra_applications: [:logger, :runtime_tools]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Specifies which paths to compile per environment.
|
||||||
|
defp elixirc_paths(:test), do: ["lib", "test/support"]
|
||||||
|
defp elixirc_paths(_), do: ["lib"]
|
||||||
|
|
||||||
|
# Specifies your project dependencies.
|
||||||
|
#
|
||||||
|
# Type `mix help deps` for examples and options.
|
||||||
|
defp deps do
|
||||||
|
[
|
||||||
|
{:phoenix, "~> 1.6.6"},
|
||||||
|
{:phoenix_ecto, "~> 4.4"},
|
||||||
|
{:ecto_sql, "~> 3.6"},
|
||||||
|
{:ecto_sqlite3, ">= 0.0.0"},
|
||||||
|
{:phoenix_html, "~> 3.0"},
|
||||||
|
{:phoenix_live_reload, "~> 1.2", only: :dev},
|
||||||
|
{:phoenix_live_view, "~> 0.17.5"},
|
||||||
|
{:floki, ">= 0.30.0", only: :test},
|
||||||
|
{:esbuild, "~> 0.3", runtime: Mix.env() == :dev},
|
||||||
|
{:telemetry_metrics, "~> 0.6"},
|
||||||
|
{:telemetry_poller, "~> 1.0"},
|
||||||
|
{:gettext, "~> 0.18"},
|
||||||
|
{:jason, "~> 1.2"},
|
||||||
|
{:plug_cowboy, "~> 2.5"}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
# Aliases are shortcuts or tasks specific to the current project.
|
||||||
|
# For example, to install project dependencies and perform other setup tasks, run:
|
||||||
|
#
|
||||||
|
# $ mix setup
|
||||||
|
#
|
||||||
|
# See the documentation for `Mix` for more info on aliases.
|
||||||
|
defp aliases do
|
||||||
|
[
|
||||||
|
setup: ["deps.get", "ecto.setup"],
|
||||||
|
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
|
||||||
|
"ecto.reset": ["ecto.drop", "ecto.setup"],
|
||||||
|
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
|
||||||
|
"assets.deploy": ["esbuild default --minify", "phx.digest"]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
35
mix.lock
Normal file
35
mix.lock
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
%{
|
||||||
|
"castore": {:hex, :castore, "0.1.15", "dbb300827d5a3ec48f396ca0b77ad47058578927e9ebe792abd99fcbc3324326", [:mix], [], "hexpm", "c69379b907673c7e6eb229f09a0a09b60bb27cfb9625bcb82ea4c04ba82a8442"},
|
||||||
|
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
|
||||||
|
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
|
||||||
|
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
|
||||||
|
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
|
||||||
|
"db_connection": {:hex, :db_connection, "2.4.1", "6411f6e23f1a8b68a82fa3a36366d4881f21f47fc79a9efb8c615e62050219da", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ea36d226ec5999781a9a8ad64e5d8c4454ecedc7a4d643e4832bf08efca01f00"},
|
||||||
|
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
|
||||||
|
"ecto": {:hex, :ecto, "3.7.1", "a20598862351b29f80f285b21ec5297da1181c0442687f9b8329f0445d228892", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d36e5b39fc479e654cffd4dbe1865d9716e4a9b6311faff799b6f90ab81b8638"},
|
||||||
|
"ecto_sql": {:hex, :ecto_sql, "3.7.2", "55c60aa3a06168912abf145c6df38b0295c34118c3624cf7a6977cd6ce043081", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0 or ~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c218ea62f305dcaef0b915fb56583195e7b91c91dcfb006ba1f669bfacbff2a"},
|
||||||
|
"ecto_sqlite3": {:hex, :ecto_sqlite3, "0.7.3", "119e5142f23b9868ac17449cd945557897c18f30c0b39e3eb96659729d38310e", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.7", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:exqlite, "~> 0.9", [hex: :exqlite, repo: "hexpm", optional: false]}], "hexpm", "5a149b96e6c2e2ebcca60d23cbcf89130f7fbbcdba62956a70aa3d6d002a8e54"},
|
||||||
|
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
|
||||||
|
"esbuild": {:hex, :esbuild, "0.4.0", "9f17db148aead4cf1e6e6a584214357287a93407b5fb51a031f122b61385d4c2", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "b61e4e6b92ffe45e4ee4755a22de6211a67c67987dc02afb35a425a0add1d447"},
|
||||||
|
"exqlite": {:hex, :exqlite, "0.9.3", "57c80e742584dc4486d717681956d4152c7d03fb34ddbfb269844b504824528d", [:make, :mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "5108f84bcc91fd7ae5b1b247e2be3860e449de5f8383ccaa1454278ffa1fc509"},
|
||||||
|
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
|
||||||
|
"floki": {:hex, :floki, "0.32.0", "f915dc15258bc997d49be1f5ef7d3992f8834d6f5695270acad17b41f5bcc8e2", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "1c5a91cae1fd8931c26a4826b5e2372c284813904c8bacb468b5de39c7ececbd"},
|
||||||
|
"gettext": {:hex, :gettext, "0.19.1", "564953fd21f29358e68b91634799d9d26989f8d039d7512622efb3c3b1c97892", [:mix], [], "hexpm", "10c656c0912b8299adba9b061c06947511e3f109ab0d18b44a866a4498e77222"},
|
||||||
|
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
|
||||||
|
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
|
||||||
|
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
|
||||||
|
"phoenix": {:hex, :phoenix, "1.6.6", "281c8ce8dccc9f60607346b72cdfc597c3dde134dd9df28dff08282f0b751754", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "807bd646e64cd9dc83db016199715faba72758e6db1de0707eef0a2da4924364"},
|
||||||
|
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"},
|
||||||
|
"phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"},
|
||||||
|
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"},
|
||||||
|
"phoenix_live_view": {:hex, :phoenix_live_view, "0.17.6", "3665f3ec426ac8d681cd7753ad4c85d2d247094dc4dc6add80dd6e3026045389", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.9 or ~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "62f06d4bbfc4dc5595070bc338119ab08e8e67a011e2923f9366419622149b9c"},
|
||||||
|
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
|
||||||
|
"phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"},
|
||||||
|
"plug": {:hex, :plug, "1.13.2", "33aba8e2b43ddd68d9d49b818ed2fb46da85f4ec3229bc4bcd0c981a640a4e71", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a95cdfe599e3524b98684376c3f3494cbfbc1f41fcddefc380cac3138dd7619d"},
|
||||||
|
"plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"},
|
||||||
|
"plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
|
||||||
|
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
|
||||||
|
"telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
|
||||||
|
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
|
||||||
|
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
|
||||||
|
}
|
112
priv/gettext/en/LC_MESSAGES/errors.po
Normal file
112
priv/gettext/en/LC_MESSAGES/errors.po
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
## `msgid`s in this file come from POT (.pot) files.
|
||||||
|
##
|
||||||
|
## Do not add, change, or remove `msgid`s manually here as
|
||||||
|
## they're tied to the ones in the corresponding POT file
|
||||||
|
## (with the same domain).
|
||||||
|
##
|
||||||
|
## Use `mix gettext.extract --merge` or `mix gettext.merge`
|
||||||
|
## to merge POT files into PO files.
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Language: en\n"
|
||||||
|
|
||||||
|
## From Ecto.Changeset.cast/4
|
||||||
|
msgid "can't be blank"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.unique_constraint/3
|
||||||
|
msgid "has already been taken"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.put_change/3
|
||||||
|
msgid "is invalid"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_acceptance/3
|
||||||
|
msgid "must be accepted"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_format/3
|
||||||
|
msgid "has invalid format"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_subset/3
|
||||||
|
msgid "has an invalid entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_exclusion/3
|
||||||
|
msgid "is reserved"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_confirmation/3
|
||||||
|
msgid "does not match confirmation"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.no_assoc_constraint/3
|
||||||
|
msgid "is still associated with this entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "are still associated with this entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_length/3
|
||||||
|
msgid "should have %{count} item(s)"
|
||||||
|
msgid_plural "should have %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be %{count} character(s)"
|
||||||
|
msgid_plural "should be %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be %{count} byte(s)"
|
||||||
|
msgid_plural "should be %{count} byte(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have at least %{count} item(s)"
|
||||||
|
msgid_plural "should have at least %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at least %{count} character(s)"
|
||||||
|
msgid_plural "should be at least %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at least %{count} byte(s)"
|
||||||
|
msgid_plural "should be at least %{count} byte(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have at most %{count} item(s)"
|
||||||
|
msgid_plural "should have at most %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at most %{count} character(s)"
|
||||||
|
msgid_plural "should be at most %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at most %{count} byte(s)"
|
||||||
|
msgid_plural "should be at most %{count} byte(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_number/3
|
||||||
|
msgid "must be less than %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be greater than %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be less than or equal to %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be greater than or equal to %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be equal to %{number}"
|
||||||
|
msgstr ""
|
95
priv/gettext/errors.pot
Normal file
95
priv/gettext/errors.pot
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
## This is a PO Template file.
|
||||||
|
##
|
||||||
|
## `msgid`s here are often extracted from source code.
|
||||||
|
## Add new translations manually only if they're dynamic
|
||||||
|
## translations that can't be statically extracted.
|
||||||
|
##
|
||||||
|
## Run `mix gettext.extract` to bring this file up to
|
||||||
|
## date. Leave `msgstr`s empty as changing them here has no
|
||||||
|
## effect: edit them in PO (`.po`) files instead.
|
||||||
|
|
||||||
|
## From Ecto.Changeset.cast/4
|
||||||
|
msgid "can't be blank"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.unique_constraint/3
|
||||||
|
msgid "has already been taken"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.put_change/3
|
||||||
|
msgid "is invalid"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_acceptance/3
|
||||||
|
msgid "must be accepted"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_format/3
|
||||||
|
msgid "has invalid format"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_subset/3
|
||||||
|
msgid "has an invalid entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_exclusion/3
|
||||||
|
msgid "is reserved"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_confirmation/3
|
||||||
|
msgid "does not match confirmation"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.no_assoc_constraint/3
|
||||||
|
msgid "is still associated with this entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "are still associated with this entry"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_length/3
|
||||||
|
msgid "should be %{count} character(s)"
|
||||||
|
msgid_plural "should be %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have %{count} item(s)"
|
||||||
|
msgid_plural "should have %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at least %{count} character(s)"
|
||||||
|
msgid_plural "should be at least %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have at least %{count} item(s)"
|
||||||
|
msgid_plural "should have at least %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should be at most %{count} character(s)"
|
||||||
|
msgid_plural "should be at most %{count} character(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
msgid "should have at most %{count} item(s)"
|
||||||
|
msgid_plural "should have at most %{count} item(s)"
|
||||||
|
msgstr[0] ""
|
||||||
|
msgstr[1] ""
|
||||||
|
|
||||||
|
## From Ecto.Changeset.validate_number/3
|
||||||
|
msgid "must be less than %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be greater than %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be less than or equal to %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be greater than or equal to %{number}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
msgid "must be equal to %{number}"
|
||||||
|
msgstr ""
|
4
priv/repo/migrations/.formatter.exs
Normal file
4
priv/repo/migrations/.formatter.exs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[
|
||||||
|
import_deps: [:ecto_sql],
|
||||||
|
inputs: ["*.exs"]
|
||||||
|
]
|
11
priv/repo/seeds.exs
Normal file
11
priv/repo/seeds.exs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Script for populating the database. You can run it as:
|
||||||
|
#
|
||||||
|
# mix run priv/repo/seeds.exs
|
||||||
|
#
|
||||||
|
# Inside the script, you can read and write to any of your
|
||||||
|
# repositories directly:
|
||||||
|
#
|
||||||
|
# Minisome.Repo.insert!(%Minisome.SomeSchema{})
|
||||||
|
#
|
||||||
|
# We recommend using the bang functions (`insert!`, `update!`
|
||||||
|
# and so on) as they will fail if something goes wrong.
|
BIN
priv/static/favicon.ico
Normal file
BIN
priv/static/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
priv/static/images/phoenix.png
Normal file
BIN
priv/static/images/phoenix.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
5
priv/static/robots.txt
Normal file
5
priv/static/robots.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
|
||||||
|
#
|
||||||
|
# To ban all spiders from the entire site uncomment the next two lines:
|
||||||
|
# User-agent: *
|
||||||
|
# Disallow: /
|
8
test/minisome_web/controllers/page_controller_test.exs
Normal file
8
test/minisome_web/controllers/page_controller_test.exs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule Minisome.Web.PageControllerTest do
|
||||||
|
use Minisome.Web.ConnCase
|
||||||
|
|
||||||
|
test "GET /", %{conn: conn} do
|
||||||
|
conn = get(conn, "/")
|
||||||
|
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
|
||||||
|
end
|
||||||
|
end
|
14
test/minisome_web/views/error_view_test.exs
Normal file
14
test/minisome_web/views/error_view_test.exs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule Minisome.Web.ErrorViewTest do
|
||||||
|
use Minisome.Web.ConnCase, async: true
|
||||||
|
|
||||||
|
# Bring render/3 and render_to_string/3 for testing custom views
|
||||||
|
import Phoenix.View
|
||||||
|
|
||||||
|
test "renders 404.html" do
|
||||||
|
assert render_to_string(Minisome.Web.ErrorView, "404.html", []) == "Not Found"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders 500.html" do
|
||||||
|
assert render_to_string(Minisome.Web.ErrorView, "500.html", []) == "Internal Server Error"
|
||||||
|
end
|
||||||
|
end
|
8
test/minisome_web/views/layout_view_test.exs
Normal file
8
test/minisome_web/views/layout_view_test.exs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
defmodule Minisome.Web.LayoutViewTest do
|
||||||
|
use Minisome.Web.ConnCase, async: true
|
||||||
|
|
||||||
|
# When testing helpers, you may want to import Phoenix.HTML and
|
||||||
|
# use functions such as safe_to_string() to convert the helper
|
||||||
|
# result into an HTML string.
|
||||||
|
# import Phoenix.HTML
|
||||||
|
end
|
3
test/minisome_web/views/page_view_test.exs
Normal file
3
test/minisome_web/views/page_view_test.exs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule Minisome.Web.PageViewTest do
|
||||||
|
use Minisome.Web.ConnCase, async: true
|
||||||
|
end
|
36
test/support/channel_case.ex
Normal file
36
test/support/channel_case.ex
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
defmodule Minisome.Web.ChannelCase do
|
||||||
|
@moduledoc """
|
||||||
|
This module defines the test case to be used by
|
||||||
|
channel tests.
|
||||||
|
|
||||||
|
Such tests rely on `Phoenix.ChannelTest` and also
|
||||||
|
import other functionality to make it easier
|
||||||
|
to build common data structures and query the data layer.
|
||||||
|
|
||||||
|
Finally, if the test case interacts with the database,
|
||||||
|
we enable the SQL sandbox, so changes done to the database
|
||||||
|
are reverted at the end of every test. If you are using
|
||||||
|
PostgreSQL, you can even run database tests asynchronously
|
||||||
|
by setting `use Minisome.Web.ChannelCase, async: true`, although
|
||||||
|
this option is not recommended for other databases.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use ExUnit.CaseTemplate
|
||||||
|
|
||||||
|
using do
|
||||||
|
quote do
|
||||||
|
# Import conveniences for testing with channels
|
||||||
|
import Phoenix.ChannelTest
|
||||||
|
import Minisome.Web.ChannelCase
|
||||||
|
|
||||||
|
# The default endpoint for testing
|
||||||
|
@endpoint Minisome.Web.Endpoint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setup tags do
|
||||||
|
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Minisome.Repo, shared: not tags[:async])
|
||||||
|
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
39
test/support/conn_case.ex
Normal file
39
test/support/conn_case.ex
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
defmodule Minisome.Web.ConnCase do
|
||||||
|
@moduledoc """
|
||||||
|
This module defines the test case to be used by
|
||||||
|
tests that require setting up a connection.
|
||||||
|
|
||||||
|
Such tests rely on `Phoenix.ConnTest` and also
|
||||||
|
import other functionality to make it easier
|
||||||
|
to build common data structures and query the data layer.
|
||||||
|
|
||||||
|
Finally, if the test case interacts with the database,
|
||||||
|
we enable the SQL sandbox, so changes done to the database
|
||||||
|
are reverted at the end of every test. If you are using
|
||||||
|
PostgreSQL, you can even run database tests asynchronously
|
||||||
|
by setting `use Minisome.Web.ConnCase, async: true`, although
|
||||||
|
this option is not recommended for other databases.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use ExUnit.CaseTemplate
|
||||||
|
|
||||||
|
using do
|
||||||
|
quote do
|
||||||
|
# Import conveniences for testing with connections
|
||||||
|
import Plug.Conn
|
||||||
|
import Phoenix.ConnTest
|
||||||
|
import Minisome.Web.ConnCase
|
||||||
|
|
||||||
|
alias Minisome.Web.Router.Helpers, as: Routes
|
||||||
|
|
||||||
|
# The default endpoint for testing
|
||||||
|
@endpoint Minisome.Web.Endpoint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setup tags do
|
||||||
|
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Minisome.Repo, shared: not tags[:async])
|
||||||
|
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
|
||||||
|
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
||||||
|
end
|
||||||
|
end
|
51
test/support/data_case.ex
Normal file
51
test/support/data_case.ex
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
defmodule Minisome.DataCase do
|
||||||
|
@moduledoc """
|
||||||
|
This module defines the setup for tests requiring
|
||||||
|
access to the application's data layer.
|
||||||
|
|
||||||
|
You may define functions here to be used as helpers in
|
||||||
|
your tests.
|
||||||
|
|
||||||
|
Finally, if the test case interacts with the database,
|
||||||
|
we enable the SQL sandbox, so changes done to the database
|
||||||
|
are reverted at the end of every test. If you are using
|
||||||
|
PostgreSQL, you can even run database tests asynchronously
|
||||||
|
by setting `use Minisome.DataCase, async: true`, although
|
||||||
|
this option is not recommended for other databases.
|
||||||
|
"""
|
||||||
|
|
||||||
|
use ExUnit.CaseTemplate
|
||||||
|
|
||||||
|
using do
|
||||||
|
quote do
|
||||||
|
alias Minisome.Repo
|
||||||
|
|
||||||
|
import Ecto
|
||||||
|
import Ecto.Changeset
|
||||||
|
import Ecto.Query
|
||||||
|
import Minisome.DataCase
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
setup tags do
|
||||||
|
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Minisome.Repo, shared: not tags[:async])
|
||||||
|
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
A helper that transforms changeset errors into a map of messages.
|
||||||
|
|
||||||
|
assert {:error, changeset} = Accounts.create_user(%{password: "short"})
|
||||||
|
assert "password is too short" in errors_on(changeset).password
|
||||||
|
assert %{password: ["password is too short"]} = errors_on(changeset)
|
||||||
|
|
||||||
|
"""
|
||||||
|
def errors_on(changeset) do
|
||||||
|
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
|
||||||
|
Regex.replace(~r"%{(\w+)}", message, fn _, key ->
|
||||||
|
opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
2
test/test_helper.exs
Normal file
2
test/test_helper.exs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ExUnit.start()
|
||||||
|
Ecto.Adapters.SQL.Sandbox.mode(Minisome.Repo, :manual)
|
Loading…
Reference in a new issue