annotate src/invite.js.luan @ 60:3521166513b3

finish invite
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 04 Mar 2025 20:31:00 -0700
parents 8270106644db
children a47036fd0158
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()
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Http = require "luan:http/Http.luan"
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Io = require "luan:Io.luan"
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local User = require "site:/lib/User.luan"
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local get_user_by_email = User.get_by_email or error()
60
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
9 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
10 local current_user = User.current or error()
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
11 local Shared = require "site:/lib/Shared.luan"
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
12 local send_mail = Shared.send_mail or error()
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
13 local Utils = require "site:/lib/Utils.luan"
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
14 local base_url = Utils.base_url 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 %>
59
8270106644db add chat.luan
Franklin Schmidt <fschmidt@gmail.com>
parents: 56
diff changeset
23 location = 'chat?with=<%=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)
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
28 local password = invitee.password
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
29 local url = base_url().."/do_login.html?user="..invitee.id.."&password="..password.."&with="..user.email
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
30 local who = user.name or user.email
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
31 send_mail {
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
32 To = email
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
33 Subject = "Chat with "..who
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
34 body = `%>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
35 <%=who%> has invited you to chat on Luan Chat.
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
36
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
37 Here is the link to login:
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
38
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
39 <%= url %>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
40
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
41 Or login with your email and the password: <%=password%>
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
42 <% `
3521166513b3 finish invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 59
diff changeset
43 }
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 %>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 openInvite(<%=json_string(email)%>);
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 <%
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 end