comparison src/save_username.js.luan @ 46:42b741a1d5c6

add username
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 28 Feb 2025 19:25:12 -0700
parents src/save_voice.js.luan@818697418dbe
children
comparison
equal deleted inserted replaced
45:e138343b2c76 46:42b741a1d5c6
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local Http = require "luan:http/Http.luan"
4 local Db = require "site:/lib/Db.luan"
5 local run_in_transaction = Db.run_in_transaction or error()
6 local User = require "site:/lib/User.luan"
7 local current_user = User.current or error()
8
9
10 return function()
11 local username = Http.request.parameters.username or error()
12 if username == "" then
13 username = nil
14 end
15 run_in_transaction( function()
16 local user = current_user() or error()
17 user.name = username
18 user.save()
19 end )
20 end