view src/save_username.js.luan @ 51:38c209714df9

rename to Luan Chat
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 03 Mar 2025 12:13:40 -0700
parents 42b741a1d5c6
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Http = require "luan:http/Http.luan"
local Db = require "site:/lib/Db.luan"
local run_in_transaction = Db.run_in_transaction or error()
local User = require "site:/lib/User.luan"
local current_user = User.current or error()


return function()
	local username = Http.request.parameters.username or error()
	if username == "" then
		username = nil
	end
	run_in_transaction( function()
		local user = current_user() or error()
		user.name = username
		user.save()
	end )
end