Mercurial Hosting > chat
comparison 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 |
comparison
equal
deleted
inserted
replaced
59:8270106644db | 60:3521166513b3 |
---|---|
4 local json_string = Parsers.json_string or error() | 4 local json_string = Parsers.json_string or error() |
5 local Http = require "luan:http/Http.luan" | 5 local Http = require "luan:http/Http.luan" |
6 local Io = require "luan:Io.luan" | 6 local Io = require "luan:Io.luan" |
7 local User = require "site:/lib/User.luan" | 7 local User = require "site:/lib/User.luan" |
8 local get_user_by_email = User.get_by_email or error() | 8 local get_user_by_email = User.get_by_email or error() |
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() | |
9 | 15 |
10 | 16 |
11 return function() | 17 return function() |
18 local user = current_user() or error() | |
12 local email = Http.request.parameters.email or error() | 19 local email = Http.request.parameters.email or error() |
13 Io.stdout = Http.response.text_writer() | 20 Io.stdout = Http.response.text_writer() |
14 if get_user_by_email(email) ~= nil then | 21 if get_user_by_email(email) ~= nil then |
15 %> | 22 %> |
16 location = 'chat?with=<%=email%>'; | 23 location = 'chat?with=<%=email%>'; |
17 <% | 24 <% |
18 return | 25 return |
19 end | 26 end |
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 } | |
20 %> | 44 %> |
21 openInvite(<%=json_string(email)%>); | 45 openInvite(<%=json_string(email)%>); |
22 <% | 46 <% |
23 end | 47 end |