annotate app/main/index/_action/send_login.lua @ 989:5a712ec1a7f1
Added support for login name recovery by email address
| author |
bsw |
| date |
Sat Apr 20 18:51:28 2013 +0200 (2013-04-20) |
| parents |
|
| children |
77873f08d94f |
| rev |
line source |
|
bsw@989
|
1 --trace.disable()
|
|
bsw@989
|
2
|
|
bsw@989
|
3 local email = param.get("email")
|
|
bsw@989
|
4
|
|
bsw@989
|
5 local members = Member:new_selector()
|
|
bsw@989
|
6 :add_where{ "notify_email = ? OR notify_email_unconfirmed = ?", email, email }
|
|
bsw@989
|
7 :add_where("login_recovery_expiry ISNULL OR login_recovery_expiry < now()")
|
|
bsw@989
|
8 :exec()
|
|
bsw@989
|
9
|
|
bsw@989
|
10 if #members < 1 then
|
|
bsw@989
|
11 return
|
|
bsw@989
|
12 end
|
|
bsw@989
|
13
|
|
bsw@989
|
14 local logins = {}
|
|
bsw@989
|
15
|
|
bsw@989
|
16 for i, member in ipairs(members) do
|
|
bsw@989
|
17 local expiry = db:query("SELECT now() + '7 days'::interval as expiry", "object").expiry
|
|
bsw@989
|
18 member.login_recovery_expiry = expiry
|
|
bsw@989
|
19 member:save()
|
|
bsw@989
|
20 logins[#logins+1] = member.login
|
|
bsw@989
|
21 end
|
|
bsw@989
|
22
|
|
bsw@989
|
23 local content = slot.use_temporary(function()
|
|
bsw@989
|
24 slot.put(_"Hello,\n\n")
|
|
bsw@989
|
25 slot.put(_"the following login is connected to this email address:\n\n")
|
|
bsw@989
|
26 for i, login in ipairs(logins) do
|
|
bsw@989
|
27 slot.put(_"Login-Name: " .. login .. "\n")
|
|
bsw@989
|
28 end
|
|
bsw@989
|
29 end)
|
|
bsw@989
|
30
|
|
bsw@989
|
31 trace.debug(content)
|
|
bsw@989
|
32 if true then return end
|
|
bsw@989
|
33
|
|
bsw@989
|
34 local success = net.send_mail{
|
|
bsw@989
|
35 envelope_from = config.mail_envelope_from,
|
|
bsw@989
|
36 from = config.mail_from,
|
|
bsw@989
|
37 reply_to = config.mail_reply_to,
|
|
bsw@989
|
38 to = email,
|
|
bsw@989
|
39 subject = config.mail_subject_prefix .. _"Login name request",
|
|
bsw@989
|
40 content_type = "text/plain; charset=UTF-8",
|
|
bsw@989
|
41 content = content
|
|
bsw@989
|
42 }
|