Mercurial Hosting > freedit
diff src/lib/User.luan @ 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 |
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