Mercurial Hosting > freedit
changeset 55:c57b84f461ae
login and registration work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 28 Nov 2022 20:33:47 -0700 |
parents | 260abd8f8565 |
children | 7ce54f6d93f2 |
files | src/lib/User.luan src/login.html.luan src/register.html.luan |
diffstat | 3 files changed, 21 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/User.luan Sun Nov 27 23:46:27 2022 -0700 +++ b/src/lib/User.luan Mon Nov 28 20:33:47 2022 -0700 @@ -18,6 +18,7 @@ local lucene_quote = Lucene.quote or 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 = {} @@ -136,11 +137,17 @@ return concat(t) end -function User.get_or_create_by_email(email) +function User.get_or_create_by_email(email,change_password) local user = User.get_by_email(email) if user == nil then user = User.new{ email=email, password=new_password() } user.save() + elseif change_password then + run_in_transaction( function() + user = user.reload() + user.password = new_password() + user.save() + end ) end return user end
--- a/src/login.html.luan Sun Nov 27 23:46:27 2022 -0700 +++ b/src/login.html.luan Mon Nov 28 20:33:47 2022 -0700 @@ -77,11 +77,12 @@ </p> <p> <label>Password</label> - <input type="password" name="password" value="<%= password or "" %>"> + <input type="password" name="password" value="<%= password or "" %>" required> <label clickable><input type=checkbox onclick="show(this)">Show</label> </p> <p><input type="submit" value="Login"></p> </form> + <p><a href="/register.html">Get or change password</a></p> <% end) end
--- a/src/register.html.luan Sun Nov 27 23:46:27 2022 -0700 +++ b/src/register.html.luan Mon Nov 28 20:33:47 2022 -0700 @@ -20,12 +20,13 @@ <html> <head> <% head() %> - <title><%=forum_title%> - Register or Get Password</title> + <title><%=forum_title%> - Register</title> </head> <body> <% header() %> <div content> - <h1>Register or Get Password</h1> + <h1>Register</h1> + <h3>Or Get or Change Password</h3> <% contents() %> @@ -42,14 +43,18 @@ page(function() %> <form> - <label>Email address</label> - <input type="email" name="email" autofocus required> - <input type="submit" value="Register or Get Password"> + <p> + <label>Email address</label> + <input type="email" name="email" autofocus required> + </p> + <p><label clickable><input type=checkbox name=change> change password</label></p> + <p><input type="submit"></p> </form> <% end) else - local user = User.get_or_create_by_email(email) + local change = Http.request.parameters.change ~= nil + local user = User.get_or_create_by_email(email,change) local result = call_mail_api( "login_email", { base_url = base_url() from = forum_title.." <support@freedit.org>"