annotate src/account.html.luan @ 41:818697418dbe

add voice link
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 27 Feb 2025 19:05:57 -0700
parents 7ea33179592a
children 89d3ddd302c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
3 local Parsers = require "luan:Parsers.luan"
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
4 local json_string = Parsers.json_string or error()
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Http = require "luan:http/Http.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Shared = require "site:/lib/Shared.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local head = Shared.head or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local header = Shared.header or error()
5
a49866b52cc2 login to chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
10 local Utils = require "site:/lib/Utils.luan"
a49866b52cc2 login to chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
11 local base_url = Utils.base_url or error()
a49866b52cc2 login to chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
12 local User = require "site:/lib/User.luan"
a49866b52cc2 login to chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
13 local current_user = User.current_required or error()
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 return function()
5
a49866b52cc2 login to chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
17 local user = current_user()
a49866b52cc2 login to chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
18 if user == nil then return end
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 Io.stdout = Http.response.text_writer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 <!doctype html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 <html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 <head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 <% head() %>
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
25 <script>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
26 'use strict';
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
27
41
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
28 let notifyEmail = <%= json_string(user.notify_email or "") %>;
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
29 let multiNotify = <%= user.multi_notify %>;
41
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
30 let voice = <%= json_string(user.voice_url or "") %>;
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
31
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
32 function showNotify() {
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
33 let span = document.querySelector('span[notify]');
41
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
34 span.textContent = notifyEmail ? `Send notifications to ${notifyEmail}` : 'No notifications';
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
35 }
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
36
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
37 function editNotify() {
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
38 let dialog = document.querySelector('dialog[edit_notify]');
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
39 let input = dialog.querySelector('input[name=notify_email]');
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
40 input.value = notifyEmail;
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
41 let radio = dialog.querySelector(`input[type=radio][value=${multiNotify}]`);
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
42 radio.checked = true;
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
43 openModal(dialog);
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
44 }
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
45
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
46 function saveNotify() {
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
47 let dialog = document.querySelector('dialog[edit_notify]');
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
48 let input = dialog.querySelector('input[name=notify_email]');
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
49 notifyEmail = input.value;
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
50 let radio = dialog.querySelector('input[type=radio]:checked');
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
51 multiNotify = radio.value === 'true';
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
52 closeModal(input);
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
53 showNotify();
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
54 ajax(`save_notify.js?email=${encodeURIComponent(notifyEmail)}&multi=${multiNotify}`);
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
55 }
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
56
41
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
57 function showVoice() {
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
58 let span = document.querySelector('span[voice]');
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
59 span.textContent = voice ? `Your voice URL: ${voice}` : 'No voice URL';
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
60 }
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
61
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
62 function editVoice() {
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
63 let dialog = document.querySelector('dialog[edit_voice]');
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
64 let input = dialog.querySelector('input[name=voice]');
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
65 input.value = voice;
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
66 openModal(dialog);
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
67 }
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
68
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
69 function saveVoice() {
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
70 let dialog = document.querySelector('dialog[edit_voice]');
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
71 let input = dialog.querySelector('input[name=voice]');
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
72 voice = input.value;
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
73 closeModal(input);
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
74 showVoice();
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
75 ajax(`save_voice.js?url=${encodeURIComponent(voice)}`);
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
76 }
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
77
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
78 function deleteUser() {
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
79 let dialog = document.querySelector('dialog[delete_user]');
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
80 openModal(dialog);
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
81 }
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
82
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
83 function doDeleteUser(el) {
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
84 closeModal(el);
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
85 ajax('delete_user.js');
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
86 }
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
87
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
88 function init() {
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
89 showNotify();
41
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
90 showVoice();
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
91 }
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
92 </script>
34
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
93 <style>
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
94 div[content] {
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
95 margin-left: auto;
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
96 margin-right: auto;
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
97 width: fit-content;
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
98 }
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
99 h1 {
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
100 text-align: center;
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
101 }
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
102 input[name=notify_email] {
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
103 width: 300px;
41
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
104 max-width: 100%;
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
105 }
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
106 input[name=voice] {
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
107 width: 500px;
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
108 max-width: 100%;
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
109 }
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
110 span[note] {
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
111 font-size: small;
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
112 }
34
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
113 </style>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 </head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 <body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 <% header() %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 <div content>
3
2c63b10781e1 add login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
118 <h1>Your Account</h1>
21
5a56297713a3 move chat to home
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
119 <p><a href="about.html">About Web Chat</a></p>
5a56297713a3 move chat to home
Franklin Schmidt <fschmidt@gmail.com>
parents: 20
diff changeset
120 <p>Your URL: <%= base_url() %>/?with=<%=user.email%></p>
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
121 <p><span notify></span> <a href="javascript:editNotify()">Edit</a></p>
41
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
122 <p><span voice></span> <a href="javascript:editVoice()">Edit</a></p>
34
Franklin Schmidt <fschmidt@gmail.com>
parents: 21
diff changeset
123 <p><a href="javascript:logout()">Logout</a></p>
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
124 <p><a href="javascript:deleteUser()">Delete account</a></p>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 </div>
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
126 <dialog edit_notify>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
127 <h2>Edit Notification</h2>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
128 <form action="javascript:saveNotify()">
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
129 <p>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
130 <label>Send notifications to</label><br>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
131 <input type=email name=notify_email><br>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
132 <span note>Leave blank for no notifications</span>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
133 </p>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
134 <p>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
135 <label clickable>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
136 <input type=radio name=multi_notify value=false>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
137 Notify only for first message
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
138 </label><br>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
139 <label clickable>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
140 <input type=radio name=multi_notify value=true>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
141 Notify for all messages
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
142 </label>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
143 </p>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
144 <div buttons>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
145 <button type=button cancel onclick="closeModal(this)">Cancel</button>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
146 <button type=submit go>Save</button>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
147 </div>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
148 </form>
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
149 </dialog>
41
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
150 <dialog edit_voice>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
151 <h2>Edit Voice URL</h2>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
152 <form action="javascript:saveVoice()">
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
153 <p>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
154 <label>URL for receiving voice calls</label><br>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
155 <input type=url name=voice><br>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
156 <span note>Leave blank for no voice URL</span>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
157 </p>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
158 <div buttons>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
159 <button type=button cancel onclick="closeModal(this)">Cancel</button>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
160 <button type=submit go>Save</button>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
161 </div>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
162 </form>
818697418dbe add voice link
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
163 </dialog>
20
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
164 <dialog delete_user>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
165 <h2>Delete Account</h2>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
166 <p>Are you sure that you want to delete your account?</p>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
167 <div buttons>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
168 <button cancel onclick="closeModal(this)">Cancel</button>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
169 <button go onclick="doDeleteUser(this)">Delete</button>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
170 </div>
dade6a560494 add dialogs
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
171 </dialog>
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents: 34
diff changeset
172 <script> init(); </script>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 </body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 </html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 end