56
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Parsers = require "luan:Parsers.luan"
|
|
4 local json_string = Parsers.json_string or error()
|
83
|
5 local Html = require "luan:Html.luan"
|
|
6 local url_encode = Html.url_encode or error()
|
|
7 local Io = require "luan:Io.luan"
|
56
|
8 local Http = require "luan:http/Http.luan"
|
|
9 local User = require "site:/lib/User.luan"
|
|
10 local get_user_by_email = User.get_by_email or error()
|
60
|
11 local get_or_create_user_by_email = User.get_or_create_by_email or error()
|
|
12 local current_user = User.current or error()
|
|
13 local Shared = require "site:/lib/Shared.luan"
|
|
14 local send_mail = Shared.send_mail or error()
|
56
|
15
|
|
16
|
|
17 return function()
|
60
|
18 local user = current_user() or error()
|
56
|
19 local email = Http.request.parameters.email or error()
|
|
20 Io.stdout = Http.response.text_writer()
|
|
21 if get_user_by_email(email) ~= nil then
|
|
22 %>
|
83
|
23 location = 'chat?with=<%=url_encode(email)%>';
|
56
|
24 <%
|
|
25 return
|
|
26 end
|
60
|
27 local invitee = get_or_create_user_by_email(email)
|
88
|
28 local url = invitee.login_url().."&with="..url_encode(user.email)
|
60
|
29 local who = user.name or user.email
|
|
30 send_mail {
|
|
31 To = email
|
|
32 Subject = "Chat with "..who
|
|
33 body = `%>
|
|
34 <%=who%> has invited you to chat on Luan Chat.
|
|
35
|
|
36 Here is the link to login:
|
|
37
|
|
38 <%= url %>
|
|
39
|
88
|
40 Or login with your email and the password: <%=invitee.password%>
|
60
|
41 <% `
|
|
42 }
|
56
|
43 %>
|
|
44 openInvite(<%=json_string(email)%>);
|
|
45 <%
|
|
46 end
|