Commit 557e4038 authored by Bat's avatar Bat
Browse files

Change config page to configure the instance

parent e60be7b2
......@@ -8,6 +8,7 @@ require "../src/activity_pub"
require "../src/controllers/application_controller"
require "../src/controllers/**"
require "../src/pipes/**"
# About Application.cr File
#
......
......@@ -11,6 +11,8 @@ Amber::Server.configure do |app|
plug Amber::Pipe::CSRF.new
# Reload clients browsers (development only)
# plug Amber::Pipe::Reload.new if Amber.env.development?
plug ConfigurationPipe.new
end
# All static content will run these transformations
......@@ -29,6 +31,7 @@ Amber::Server.configure do |app|
routes :web do
get "/", HomeController, :index
get "/configure", HomeController, :show_configure
post "/configure", HomeController, :configure
get "/blog", ActivityPub::BlogController, :show
......
......@@ -3,13 +3,4 @@ require "jasper_helpers"
class ApplicationController < Amber::Controller::Base
include JasperHelpers
LAYOUT = "application.ecr"
macro template (file, title, layout = true, partial = nil, path = "src/views", folder = __FILE__)
title = {{ title }}
if Repo.all(Blog).size == 0
render("initial_config.ecr", folder: "home")
else
render({{file}}, layout: {{layout}}, partial: {{partial}}, path: {{path}}, folder: {{folder}})
end
end
end
class HomeController < ApplicationController
def index
blog = Blog.get
template("index.ecr", "Home")
instance = Instance.get
title = "Home"
render("index.ecr")
end
def show_configure
title = "Configuration"
render("initial_config.ecr")
end
def configure
puts "Configuring !"
instance = Instance.new
instance.name = params["name"]
Repo.insert(instance)
puts "INSTANCE :"
puts Instance.get
redirect_to(controller: :home, action: :index, status: 302)
end
end
......@@ -4,6 +4,6 @@ class Account < Crecto::Model
field :display_name, String
field :bio, String
has_many :posts, Post, dependent: :destroy
belongs_to :instance
belongs_to :instance, Instance
end
end
......@@ -6,6 +6,7 @@ class Instance < Crecto::Model
end
def self.get
puts Repo.all(Instance).size
Repo.all(Instance, Query.limit(1))[0]
end
......
class ConfigurationPipe
include HTTP::Handler
def call(context : HTTP::Server::Context)
if Instance.initialized? || context.request.path == "/configure/"
call_next(context)
else
context.response.status_code = 302
context.response.headers.add "Location", "/configure/"
end
end
end
\ No newline at end of file
<h1><%= blog.title %></h1>
<h2><%= blog.subtitle %></h2>
\ No newline at end of file
<h1><%= instance.name %></h1>
<main>
<h1>Welcome to Plume</h1>
<p>
We need a few information before you can start using your blog.
Your setup seems to be working well so far! Good job!
</p>
<form method="POST" action="/configure">
<label for="title">Blog title</label>
<input name="title">
<label for="subtitle">Blog subtitle</label>
<input name="subtitle">
<label for="description">Description</label>
<textarea name="description"></textarea>
<p>
We just need a few information before you can start using your instance.
</p>
<form method="POST" action="/configure/">
<label for="name">Instance name</label>
<input name="name">
<%= csrf_tag %>
<input type="submit" value="Create Blog">
<input type="submit" value="Finalize instance creation">
</form>
</main>
\ No newline at end of file
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<title><%= title %>Plume</title>
<title><%= title %> &mdash; Plume</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment