liquid_feedback_frontend
view app/main/index/_action/reset_password.lua @ 124:f740026b1518
add initiator support in delegation
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Mon Sep 20 20:32:04 2010 +0200 (2010-09-20) |
parents | 8d91bccab0bf |
children | bf735d8095aa |
line source
1 local secret = param.get("secret")
3 if not secret then
5 local member = Member:new_selector()
6 :add_where{ "login = ?", param.get("login") }
7 :add_where("password_reset_secret ISNULL OR password_reset_secret_expiry < now()")
8 :optional_object_mode()
9 :exec()
11 if member then
12 if not member.notify_email then
13 slot.put_into("error", _"Sorry, but there is not confirmed email address for your account. Please contact the administrator or support.")
14 return false
15 end
16 member.password_reset_secret = multirand.string( 24, "23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" )
17 local expiry = db:query("SELECT now() + '1 days'::interval as expiry", "object").expiry
18 member.password_reset_secret_expiry = expiry
19 member:save()
20 local content = slot.use_temporary(function()
21 slot.put(_"Hello " .. member.name .. ",\n\n")
22 slot.put(_"to reset your password please click on the following link:\n\n")
23 slot.put(config.absolute_base_url .. "index/reset_password.html?secret=" .. member.password_reset_secret .. "\n\n")
24 slot.put(_"If this link is not working, please open following url in your web browser:\n\n")
25 slot.put(config.absolute_base_url .. "index/reset_password.html\n\n")
26 slot.put(_"On that page please enter the reset code:\n\n")
27 slot.put(member.password_reset_secret .. "\n\n")
28 end)
29 local success = net.send_mail{
30 envelope_from = config.mail_envelope_from,
31 from = config.mail_from,
32 reply_to = config.mail_reply_to,
33 to = member.notify_email,
34 subject = config.mail_subject_prefix .. _"Password reset request",
35 content_type = "text/plain; charset=UTF-8",
36 content = content
37 }
38 end
40 slot.put_into("notice", _"Reset link has been send for this member")
42 else
43 local member = Member:new_selector()
44 :add_where{ "password_reset_secret = ?", secret }
45 :add_where{ "password_reset_secret_expiry > now()" }
46 :optional_object_mode()
47 :exec()
49 if not member then
50 slot.put_into("error", _"Reset code is invalid!")
51 return false
52 end
54 local password1 = param.get("password1")
55 local password2 = param.get("password2")
57 if password1 ~= password2 then
58 slot.put_into("error", _"Passwords don't match!")
59 return false
60 end
62 if #password1 < 8 then
63 slot.put_into("error", _"Passwords must consist of at least 8 characters!")
64 return false
65 end
67 member:set_password(password1)
68 member.password_reset_secret = nil
69 member.password_reset_secret_expiry = nil
70 member:save()
72 slot.put_into("notice", _"Password has been reset successfully")
74 end