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()
|
|
15 local Utils = require "site:/lib/Utils.luan"
|
|
16 local base_url = Utils.base_url or error()
|
56
|
17
|
|
18
|
|
19 return function()
|
60
|
20 local user = current_user() or error()
|
56
|
21 local email = Http.request.parameters.email or error()
|
|
22 Io.stdout = Http.response.text_writer()
|
|
23 if get_user_by_email(email) ~= nil then
|
|
24 %>
|
83
|
25 location = 'chat?with=<%=url_encode(email)%>';
|
56
|
26 <%
|
|
27 return
|
|
28 end
|
60
|
29 local invitee = get_or_create_user_by_email(email)
|
|
30 local password = invitee.password
|
83
|
31 local url = base_url().."/do_login.html?user="..invitee.id.."&password="..password.."&with="..url_encode(user.email)
|
60
|
32 local who = user.name or user.email
|
|
33 send_mail {
|
|
34 To = email
|
|
35 Subject = "Chat with "..who
|
|
36 body = `%>
|
|
37 <%=who%> has invited you to chat on Luan Chat.
|
|
38
|
|
39 Here is the link to login:
|
|
40
|
|
41 <%= url %>
|
|
42
|
|
43 Or login with your email and the password: <%=password%>
|
|
44 <% `
|
|
45 }
|
56
|
46 %>
|
|
47 openInvite(<%=json_string(email)%>);
|
|
48 <%
|
|
49 end
|