annotate src/invite.js.luan @ 88:7b339b1ccd11

add tools/users.html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Mar 2025 16:18:39 -0600
parents a47036fd0158
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Parsers = require "luan:Parsers.luan"
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local json_string = Parsers.json_string or error()
83
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 60
diff changeset
5 local Html = require "luan:Html.luan"
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 60
diff changeset
6 local url_encode = Html.url_encode or error()
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 60
diff changeset
7 local Io = require "luan:Io.luan"
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Http = require "luan:http/Http.luan"
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local User = require "site:/lib/User.luan"
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local get_user_by_email = User.get_by_email or error()
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
11 local get_or_create_user_by_email = User.get_or_create_by_email or error()
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
12 local current_user = User.current or error()
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
13 local Shared = require "site:/lib/Shared.luan"
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
14 local send_mail = Shared.send_mail or error()
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 return function()
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
18 local user = current_user() or error()
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local email = Http.request.parameters.email or error()
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 Io.stdout = Http.response.text_writer()
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 if get_user_by_email(email) ~= nil then
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 %>
83
a47036fd0158 group chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 60
diff changeset
23 location = 'chat?with=<%=url_encode(email)%>';
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 <%
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 return
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
27 local invitee = get_or_create_user_by_email(email)
88
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 83
diff changeset
28 local url = invitee.login_url().."&with="..url_encode(user.email)
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
29 local who = user.name or user.email
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
30 send_mail {
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
31 To = email
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
32 Subject = "Chat with "..who
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
33 body = `%>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
34 <%=who%> has invited you to chat on Luan Chat.
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
35
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
36 Here is the link to login:
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
37
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
38 <%= url %>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
39
88
7b339b1ccd11 add tools/users.html
Franklin Schmidt <fschmidt@gmail.com>
parents: 83
diff changeset
40 Or login with your email and the password: <%=invitee.password%>
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
41 <% `
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
42 }
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 %>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 openInvite(<%=json_string(email)%>);
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <%
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 end