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()
|
|
5 local Http = require "luan:http/Http.luan"
|
|
6 local Io = require "luan:Io.luan"
|
|
7 local User = require "site:/lib/User.luan"
|
|
8 local get_user_by_email = User.get_by_email or error()
|
60
|
9 local get_or_create_user_by_email = User.get_or_create_by_email or error()
|
|
10 local current_user = User.current or error()
|
|
11 local Shared = require "site:/lib/Shared.luan"
|
|
12 local send_mail = Shared.send_mail or error()
|
|
13 local Utils = require "site:/lib/Utils.luan"
|
|
14 local base_url = Utils.base_url 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 %>
|
59
|
23 location = 'chat?with=<%=email%>';
|
56
|
24 <%
|
|
25 return
|
|
26 end
|
60
|
27 local invitee = get_or_create_user_by_email(email)
|
|
28 local password = invitee.password
|
|
29 local url = base_url().."/do_login.html?user="..invitee.id.."&password="..password.."&with="..user.email
|
|
30 local who = user.name or user.email
|
|
31 send_mail {
|
|
32 To = email
|
|
33 Subject = "Chat with "..who
|
|
34 body = `%>
|
|
35 <%=who%> has invited you to chat on Luan Chat.
|
|
36
|
|
37 Here is the link to login:
|
|
38
|
|
39 <%= url %>
|
|
40
|
|
41 Or login with your email and the password: <%=password%>
|
|
42 <% `
|
|
43 }
|
56
|
44 %>
|
|
45 openInvite(<%=json_string(email)%>);
|
|
46 <%
|
|
47 end
|