comparison src/login.html.luan @ 14:7d0c96408abf

restrict name
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Jul 2022 17:04:14 -0600
parents 9166f6a14021
children a1db5223ced1
comparison
equal deleted inserted replaced
13:24668255cede 14:7d0c96408abf
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 Html = require "luan:Html.luan" 6 local Html = require "luan:Html.luan"
6 local url_encode = Html.url_encode or error() 7 local url_encode = Html.url_encode or error()
7 local Io = require "luan:Io.luan" 8 local Io = require "luan:Io.luan"
8 local output_of = Io.output_of or error() 9 local output_of = Io.output_of or error()
9 local Http = require "luan:http/Http.luan" 10 local Http = require "luan:http/Http.luan"
40 <% end %> 41 <% end %>
41 <form> 42 <form>
42 <input type="hidden" name="email" value="<%= user.email %>" > 43 <input type="hidden" name="email" value="<%= user.email %>" >
43 <input type="hidden" name="password" value="<%= user.password %>" > 44 <input type="hidden" name="password" value="<%= user.password %>" >
44 <label>User name for <%= user.email %></label> 45 <label>User name for <%= user.email %></label>
45 <input type="text" name="name" value="<%= name or "" %>" autofocus required> 46 <input type="text" name="name" value="<%= name or "" %>" autofocus required pattern="[a-zA-Z0-9_-]+">
46 <input type="submit" value="Register"> 47 <input type="submit" value="Register">
47 </form> 48 </form>
48 <% 49 <%
49 end 50 end
50 51
113 <% 114 <%
114 end) 115 end)
115 end 116 end
116 else 117 else
117 name = trim(name) 118 name = trim(name)
118 #name > 0 or error "empty name" 119 matches( name, "^[a-zA-Z0-9_-]+$" ) or error "invalid name"
119 local error_message = nil 120 local error_message = nil
120 local user 121 local user
121 run_in_transaction( function() 122 run_in_transaction( function()
122 user = get_user(email,password) 123 user = get_user(email,password)
123 if user.name ~= name and User.get_by_name(name) ~= nil then 124 if user.name ~= name and User.get_by_name(name) ~= nil then