comparison src/login.html.luan @ 29:a1db5223ced1

luan changes
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 25 Jul 2022 21:28:10 -0600
parents 7d0c96408abf
children 260abd8f8565
comparison
equal deleted inserted replaced
28:d9d7aa2a79db 29:a1db5223ced1
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local String = require "luan:String.luan" 3 local String = require "luan:String.luan"
4 local trim = String.trim or error() 4 local trim = String.trim or error()
5 local matches = String.matches or error() 5 local regex = String.regex or error()
6 local Html = require "luan:Html.luan" 6 local Html = require "luan:Html.luan"
7 local url_encode = Html.url_encode or error() 7 local url_encode = Html.url_encode or error()
8 local Io = require "luan:Io.luan" 8 local Io = require "luan:Io.luan"
9 local output_of = Io.output_of or error() 9 local output_of = Io.output_of or error()
10 local Http = require "luan:http/Http.luan" 10 local Http = require "luan:http/Http.luan"
18 local forum_title = Forum.title or error() 18 local forum_title = Forum.title or error()
19 local User = require "site:/lib/User.luan" 19 local User = require "site:/lib/User.luan"
20 local Db = require "site:/lib/Db.luan" 20 local Db = require "site:/lib/Db.luan"
21 local run_in_transaction = Db.run_in_transaction or error() 21 local run_in_transaction = Db.run_in_transaction or error()
22 22
23
24 local name_regex = regex "^[a-zA-Z0-9_-]+$"
23 25
24 local function get_user(email,password) 26 local function get_user(email,password)
25 local user = User.get_by_email(email) 27 local user = User.get_by_email(email)
26 user or error "email not found" 28 user or error "email not found"
27 user.password == password or error "wrong password" 29 user.password == password or error "wrong password"
114 <% 116 <%
115 end) 117 end)
116 end 118 end
117 else 119 else
118 name = trim(name) 120 name = trim(name)
119 matches( name, "^[a-zA-Z0-9_-]+$" ) or error "invalid name" 121 name_regex.matches(name) or error "invalid name"
120 local error_message = nil 122 local error_message = nil
121 local user 123 local user
122 run_in_transaction( function() 124 run_in_transaction( function()
123 user = get_user(email,password) 125 user = get_user(email,password)
124 if user.name ~= name and User.get_by_name(name) ~= nil then 126 if user.name ~= name and User.get_by_name(name) ~= nil then