annotate src/save_notify.js.luan @ 40:7ea33179592a

email notification
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 27 Feb 2025 16:44:20 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Http = require "luan:http/Http.luan"
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Db = require "site:/lib/Db.luan"
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local run_in_transaction = Db.run_in_transaction or error()
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local User = require "site:/lib/User.luan"
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local current_user = User.current or error()
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 return function()
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local email = Http.request.parameters.email or error()
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local multi = Http.request.parameters.multi or error()
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 run_in_transaction( function()
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local user = current_user() or error()
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 user.notify_email = email ~= "" and email or nil
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 user.multi_notify = multi == "true"
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 user.save()
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 end )
7ea33179592a email notification
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 end