Last active
January 17, 2020 12:00
-
-
Save wookay/fed24f2334d3be3524661b83f98fde30 to your computer and use it in GitHub Desktop.
bukdu auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/wookay/Bukdu.jl/tree/master | |
using Bukdu | |
struct Authorization <: Plug.AbstractPlug | |
end | |
function user_authorized(conn::Conn) | |
conn.params[:pass] == "1" | |
end | |
function plug(::Type{Authorization}, conn::Conn) | |
req = conn.request | |
conn.private[:auth] = user_authorized(conn) | |
end | |
pipeline(:auth) do conn::Conn | |
plug(Authorization, conn) | |
end | |
struct IndexController <: ApplicationController | |
conn::Conn | |
end | |
function authorized_index(::IndexController) | |
render(Text, "authorized_index") | |
end | |
function login(::IndexController) | |
render(Text, "login") | |
end | |
function authorized(conn::Conn)::Bool | |
get(conn.private, :auth, false) | |
end | |
function index(c::IndexController) | |
!authorized(c.conn) && return redirect_to(c.conn, "/login") | |
render(Text, "index") | |
end | |
routes(:auth) do | |
get("/authorized_zone", IndexController, authorized_index) | |
get("/", IndexController, index) | |
end | |
routes() do | |
get("/login", IndexController, login) | |
end | |
Bukdu.start(8080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment