Mercurial Hosting > freedit
comparison 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 |
comparison
equal
deleted
inserted
replaced
54:260abd8f8565 | 55:c57b84f461ae |
---|---|
16 local html_encode = Html.encode or error() | 16 local html_encode = Html.encode or error() |
17 local Lucene = require "luan:lucene/Lucene.luan" | 17 local Lucene = require "luan:lucene/Lucene.luan" |
18 local lucene_quote = Lucene.quote or error() | 18 local lucene_quote = Lucene.quote or error() |
19 local Http = require "luan:http/Http.luan" | 19 local Http = require "luan:http/Http.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 | 22 |
22 | 23 |
23 local User = {} | 24 local User = {} |
24 | 25 |
25 local users_by_name = {} | 26 local users_by_name = {} |
134 t[#t+1] = password_chars[random(n)] | 135 t[#t+1] = password_chars[random(n)] |
135 end | 136 end |
136 return concat(t) | 137 return concat(t) |
137 end | 138 end |
138 | 139 |
139 function User.get_or_create_by_email(email) | 140 function User.get_or_create_by_email(email,change_password) |
140 local user = User.get_by_email(email) | 141 local user = User.get_by_email(email) |
141 if user == nil then | 142 if user == nil then |
142 user = User.new{ email=email, password=new_password() } | 143 user = User.new{ email=email, password=new_password() } |
143 user.save() | 144 user.save() |
145 elseif change_password then | |
146 run_in_transaction( function() | |
147 user = user.reload() | |
148 user.password = new_password() | |
149 user.save() | |
150 end ) | |
144 end | 151 end |
145 return user | 152 return user |
146 end | 153 end |
147 | 154 |
148 return User | 155 return User |