Mercurial Hosting > freedit
comparison src/lib/Shared.luan @ 6:9166f6a14021
add email api
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 23 Jun 2022 23:05:28 -0600 |
parents | 2f20b11affdd |
children | 0472897e790d |
comparison
equal
deleted
inserted
replaced
5:2f20b11affdd | 6:9166f6a14021 |
---|---|
1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | 2 local error = Luan.error |
3 local Http = require "luan:http/Http.luan" | 3 local Http = require "luan:http/Http.luan" |
4 local Io = require "luan:Io.luan" | |
5 local uri = Io.uri or error() | |
6 local Parsers = require "luan:Parsers.luan" | |
7 local json_parse = Parsers.json_parse or error() | |
4 local Forum = require "site:/lib/Forum.luan" | 8 local Forum = require "site:/lib/Forum.luan" |
9 local forum_title = Forum.title or error() | |
10 local mailer_url = Forum.mailer_url or error() | |
5 local User = require "site:/lib/User.luan" | 11 local User = require "site:/lib/User.luan" |
6 local Logging = require "luan:logging/Logging.luan" | 12 local Logging = require "luan:logging/Logging.luan" |
7 local logger = Logging.logger "Shared" | 13 local logger = Logging.logger "Shared" |
8 | 14 |
9 | 15 |
20 | 26 |
21 function Shared.header() | 27 function Shared.header() |
22 local user = User.current() | 28 local user = User.current() |
23 %> | 29 %> |
24 <div header> | 30 <div header> |
25 <a href="/"><%=Forum.title%></a> | 31 <a href="/"><%=forum_title%></a> |
26 <% if user == nil then %> | 32 <% if user == nil then %> |
27 <a href="/login.html">login</a> | 33 <a href="/login.html">login</a> |
28 <% else %> | 34 <% else %> |
29 <a href="/account.html"><%=user.name_html%></a> | 35 <a href="/account.html"><%=user.name_html%></a> |
30 <% end %> | 36 <% end %> |
50 | 56 |
51 function Shared.base_url() | 57 function Shared.base_url() |
52 return Http.request.scheme.."://"..Http.request.headers["host"] | 58 return Http.request.scheme.."://"..Http.request.headers["host"] |
53 end | 59 end |
54 | 60 |
61 function Shared.call_mail_api(cmd,parameters) | |
62 local url = mailer_url.."/api/"..cmd..".json" | |
63 local options = { | |
64 parameters = parameters | |
65 } | |
66 local response = uri(url,options).read_text() | |
67 return json_parse(response) | |
68 end | |
69 | |
55 return Shared | 70 return Shared |