0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
40
|
3 local Parsers = require "luan:Parsers.luan"
|
|
4 local json_string = Parsers.json_string or error()
|
46
|
5 local Html = require "luan:Html.luan"
|
|
6 local html_encode = Html.encode or error()
|
0
|
7 local Io = require "luan:Io.luan"
|
|
8 local Http = require "luan:http/Http.luan"
|
|
9 local Shared = require "site:/lib/Shared.luan"
|
|
10 local head = Shared.head or error()
|
|
11 local header = Shared.header or error()
|
5
|
12 local Utils = require "site:/lib/Utils.luan"
|
|
13 local base_url = Utils.base_url or error()
|
|
14 local User = require "site:/lib/User.luan"
|
|
15 local current_user = User.current_required or error()
|
0
|
16
|
|
17
|
|
18 return function()
|
5
|
19 local user = current_user()
|
|
20 if user == nil then return end
|
0
|
21 Io.stdout = Http.response.text_writer()
|
|
22 %>
|
|
23 <!doctype html>
|
|
24 <html>
|
|
25 <head>
|
|
26 <% head() %>
|
20
|
27 <script>
|
|
28 'use strict';
|
|
29
|
46
|
30 let email = <%= json_string(user.email) %>;
|
|
31 let username = <%= json_string(user.name) or "" %>;
|
41
|
32 let notifyEmail = <%= json_string(user.notify_email or "") %>;
|
40
|
33 let multiNotify = <%= user.multi_notify %>;
|
41
|
34 let voice = <%= json_string(user.voice_url or "") %>;
|
40
|
35
|
46
|
36 function showUsername() {
|
|
37 let span = document.querySelector('span[username]');
|
|
38 span.textContent = username || email;
|
|
39 }
|
|
40
|
|
41 function editUsername() {
|
|
42 let dialog = document.querySelector('dialog[edit_username]');
|
|
43 let input = dialog.querySelector('input[name=username]');
|
|
44 input.value = username;
|
|
45 openModal(dialog);
|
|
46 }
|
|
47
|
|
48 function saveUsername() {
|
|
49 let dialog = document.querySelector('dialog[edit_username]');
|
83
|
50 closeModal(dialog);
|
|
51 username = dialog.querySelector('input[name=username]').value;
|
46
|
52 showUsername();
|
|
53 ajax(`save_username.js?username=${encodeURIComponent(username)}`);
|
|
54 }
|
|
55
|
40
|
56 function showNotify() {
|
|
57 let span = document.querySelector('span[notify]');
|
41
|
58 span.textContent = notifyEmail ? `Send notifications to ${notifyEmail}` : 'No notifications';
|
40
|
59 }
|
|
60
|
|
61 function editNotify() {
|
|
62 let dialog = document.querySelector('dialog[edit_notify]');
|
|
63 let input = dialog.querySelector('input[name=notify_email]');
|
|
64 input.value = notifyEmail;
|
|
65 let radio = dialog.querySelector(`input[type=radio][value=${multiNotify}]`);
|
|
66 radio.checked = true;
|
|
67 openModal(dialog);
|
|
68 }
|
|
69
|
|
70 function saveNotify() {
|
|
71 let dialog = document.querySelector('dialog[edit_notify]');
|
83
|
72 closeModal(dialog);
|
|
73 notifyEmail = dialog.querySelector('input[name=notify_email]').value;
|
40
|
74 let radio = dialog.querySelector('input[type=radio]:checked');
|
|
75 multiNotify = radio.value === 'true';
|
|
76 showNotify();
|
|
77 ajax(`save_notify.js?email=${encodeURIComponent(notifyEmail)}&multi=${multiNotify}`);
|
|
78 }
|
|
79
|
41
|
80 function showVoice() {
|
|
81 let span = document.querySelector('span[voice]');
|
61
|
82 span.textContent = voice ? `Your voice URL is ${voice}` : 'No voice URL';
|
41
|
83 }
|
|
84
|
|
85 function editVoice() {
|
|
86 let dialog = document.querySelector('dialog[edit_voice]');
|
|
87 let input = dialog.querySelector('input[name=voice]');
|
|
88 input.value = voice;
|
|
89 openModal(dialog);
|
|
90 }
|
|
91
|
|
92 function saveVoice() {
|
|
93 let dialog = document.querySelector('dialog[edit_voice]');
|
83
|
94 closeModal(dialog);
|
|
95 voice = dialog.querySelector('input[name=voice]').value;
|
41
|
96 showVoice();
|
|
97 ajax(`save_voice.js?url=${encodeURIComponent(voice)}`);
|
|
98 }
|
|
99
|
20
|
100 function deleteUser() {
|
|
101 let dialog = document.querySelector('dialog[delete_user]');
|
|
102 openModal(dialog);
|
|
103 }
|
|
104
|
|
105 function doDeleteUser(el) {
|
|
106 closeModal(el);
|
|
107 ajax('delete_user.js');
|
|
108 }
|
40
|
109
|
67
|
110 function openUrl() {
|
|
111 let dialog = document.querySelector('dialog[url]');
|
|
112 openModal(dialog);
|
|
113 }
|
|
114
|
40
|
115 function init() {
|
46
|
116 showUsername();
|
40
|
117 showNotify();
|
41
|
118 showVoice();
|
40
|
119 }
|
20
|
120 </script>
|
34
|
121 <style>
|
|
122 h1 {
|
|
123 text-align: center;
|
|
124 }
|
52
|
125 input[name] {
|
|
126 max-width: 100%;
|
|
127 }
|
|
128 input[name=username] {
|
|
129 width: 300px;
|
|
130 }
|
40
|
131 input[name=notify_email] {
|
52
|
132 width: 500px;
|
41
|
133 }
|
|
134 input[name=voice] {
|
|
135 width: 500px;
|
40
|
136 }
|
67
|
137 dialog[url] {
|
|
138 width: 600px;
|
|
139 }
|
40
|
140 span[note] {
|
|
141 font-size: small;
|
|
142 }
|
34
|
143 </style>
|
0
|
144 </head>
|
|
145 <body>
|
|
146 <% header() %>
|
|
147 <div content>
|
3
|
148 <h1>Your Account</h1>
|
61
|
149 <p>Your username is <span username></span> <a href="javascript:editUsername()">Edit</a></p>
|
40
|
150 <p><span notify></span> <a href="javascript:editNotify()">Edit</a></p>
|
41
|
151 <p><span voice></span> <a href="javascript:editVoice()">Edit</a></p>
|
67
|
152 <p><a href="javascript:openUrl()">Your chat URL</a></p>
|
34
|
153 <p><a href="javascript:logout()">Logout</a></p>
|
20
|
154 <p><a href="javascript:deleteUser()">Delete account</a></p>
|
66
|
155 <p> </p>
|
|
156 <p><a href="about.html">About Luan Chat</a></p>
|
0
|
157 </div>
|
46
|
158 <dialog edit_username>
|
|
159 <h2>Edit Username</h2>
|
|
160 <form action="javascript:saveUsername()">
|
|
161 <p>
|
|
162 <label>Username</label><br>
|
|
163 <input type=text name=username placeholder="<%=html_encode(user.email)%>"><br>
|
|
164 </p>
|
|
165 <div buttons>
|
60
|
166 <button type=button onclick="closeModal(this)">Cancel</button>
|
|
167 <button type=submit>Save</button>
|
46
|
168 </div>
|
|
169 </form>
|
|
170 </dialog>
|
40
|
171 <dialog edit_notify>
|
|
172 <h2>Edit Notification</h2>
|
|
173 <form action="javascript:saveNotify()">
|
|
174 <p>
|
86
|
175 <label>Email addresses to send notifications to</label><br>
|
52
|
176 <input type=email multiple name=notify_email><br>
|
|
177 <span note>Leave blank for no notifications. Use <a href="https://pushover.net/">Pushover</a> for app notification.</span>
|
40
|
178 </p>
|
|
179 <p>
|
|
180 <label clickable>
|
|
181 <input type=radio name=multi_notify value=false>
|
|
182 Notify only for first message
|
|
183 </label><br>
|
|
184 <label clickable>
|
|
185 <input type=radio name=multi_notify value=true>
|
|
186 Notify for all messages
|
|
187 </label>
|
|
188 </p>
|
|
189 <div buttons>
|
60
|
190 <button type=button onclick="closeModal(this)">Cancel</button>
|
|
191 <button type=submit>Save</button>
|
40
|
192 </div>
|
|
193 </form>
|
|
194 </dialog>
|
41
|
195 <dialog edit_voice>
|
|
196 <h2>Edit Voice URL</h2>
|
|
197 <form action="javascript:saveVoice()">
|
|
198 <p>
|
|
199 <label>URL for receiving voice calls</label><br>
|
|
200 <input type=url name=voice><br>
|
67
|
201 <span note>Leave blank for no voice URL. We recommend <a href="https://whereby.com/">Whereby</a>.</span>
|
41
|
202 </p>
|
|
203 <div buttons>
|
60
|
204 <button type=button onclick="closeModal(this)">Cancel</button>
|
|
205 <button type=submit>Save</button>
|
41
|
206 </div>
|
|
207 </form>
|
|
208 </dialog>
|
20
|
209 <dialog delete_user>
|
|
210 <h2>Delete Account</h2>
|
|
211 <p>Are you sure that you want to delete your account?</p>
|
|
212 <div buttons>
|
60
|
213 <button onclick="closeModal(this)">Cancel</button>
|
|
214 <button onclick="doDeleteUser(this)">Delete</button>
|
20
|
215 </div>
|
|
216 </dialog>
|
67
|
217 <dialog url>
|
|
218 <h2>Your chat URL</h2>
|
83
|
219 <p><%= base_url() %>/chat?with=<%=html_encode(user.email)%></p>
|
67
|
220 <p>Use this URL to link to your chat so that other people can chat with you by clicking on the link.</p>
|
|
221 <div buttons>
|
|
222 <button onclick="closeModal(this)">Close</button>
|
|
223 </div>
|
|
224 </dialog>
|
40
|
225 <script> init(); </script>
|
45
|
226 <!-- ID = <%=user.id%> -->
|
0
|
227 </body>
|
|
228 </html>
|
|
229 <%
|
|
230 end
|