Add a logout button

Add a button that only shows when users are logged in, allowing
them to log out.
This commit is contained in:
Robin Malley 2021-09-12 01:47:40 +00:00
parent 4e0a23ee95
commit 6398e97498
3 changed files with 19 additions and 6 deletions

View File

@ -43,7 +43,7 @@ local function get_site_home(req, loggedin)
loggedin = loggedin
}
end
local function get_author_home(req)
local function get_author_home(req, loggedin)
--print("Looking at author home...")
local host = http_request_get_host(req)
local subdomain = host:match("([^\\.]+)")
@ -120,11 +120,11 @@ local function index_get(req)
--author home page
local cachepath = string.format("%s.%s",subdomain,config.domain)
text = cache.render(cachepath, function()
return get_author_home(req)
return get_author_home(req, author ~= nil)
end)
elseif host ~= config.domain and author == subdomain then
--author's home page for the author, don't cache, display unlisted
text = get_author_home(req)
text = get_author_home(req, author ~= nil)
end
assert(text)
http_response(req,200,text)

View File

@ -5,7 +5,19 @@
<a href="https://<%= author %>.<%= domain %>"><%= author %></a>.<a href="https://<%= domain %>"><%= domain %></a>
</h1>
<div class="container">
<a href="/_paste" class="button">New paste</a>
<div class="row">
<a href="/_paste" class="button column column-0">New paste</a>
<% if not loggedin then %>
<a href="/_login" class="button column column-0">Log in</a>
<% else %>
<a href="/_logout" class="button column column-0">Log out</a>
<% end %>
<span class="column column-0"></span>
<form action="https://<%= domain %>/_search" method="get" class="search column row">
<input class="column" type="text" name="q" placeholder="+greentext -dotr +hits>20"/>
<input class="column column-0 button button-clear" type="submit" value="&#x1F50E;"/>
</form>
</div>
</div>
<div class="content">
<%= bio %>

View File

@ -8,12 +8,13 @@
<div class="container">
<div class="row">
<a href="/_paste" class="button column column-0">New paste</a>
<% if loggedin then %>
<% if not loggedin then %>
<a href="/_login" class="button column column-0">Log in</a>
<a href="/_claim" class="button column column-0">Register</a>
<% else %>
<a href="/_logout" class="button column column-0">Log out</a>
<span class="column column-0"></span>
<% end %>
<a href="/_claim" class="button column column-0">Register</a>
<form action="https://<%= domain %>/_search" method="get" class="search column row">
<input class="column" type="text" name="q" placeholder="+greentext -dotr +hits>20"/>
<input class="column column-0 button button-clear" type="submit" value="&#x1F50E;"/>