crystal-gauntlet/src/template_endpoints/create_session.cr

27 lines
731 B
Crystal
Raw Normal View History

2023-01-08 08:10:27 +01:00
require "uri"
require "compress/gzip"
include CrystalGauntlet
2023-05-23 10:46:31 +02:00
CrystalGauntlet.template_endpoints[{
name: "create_session",
path: "/tools/create_session",
methods: ["get", "post"]
}] = ->(context : HTTP::Server::Context, params : Hash(String, String?)) {
2023-01-08 08:10:27 +01:00
disabled = !config_get("sessions.allow").as(Bool | Nil)
result = nil
body = context.request.body
if body && !disabled
begin
params = URI::Params.parse(body.gets_to_end)
result = Accounts.new_session(context.request, params["username"], params["password"])
rescue error
LOG.error {"whar.... #{error}"}
end
end
context.response.content_type = "text/html"
ECR.embed("./public/template/create_session.ecr", context.response)
}