# HG changeset patch # User bsw # Date 1366476688 -7200 # Node ID 5a712ec1a7f19d0a09586f79aa701c8f9d1afd65 # Parent 81bde33c22568f715045a2bda9a88bdd1256dfa5 Added support for login name recovery by email address diff -r 81bde33c2256 -r 5a712ec1a7f1 app/main/_filter/21_auth.lua --- a/app/main/_filter/21_auth.lua Sat Apr 20 18:40:34 2013 +0200 +++ b/app/main/_filter/21_auth.lua Sat Apr 20 18:51:28 2013 +0200 @@ -13,6 +13,8 @@ or view == "about" or view == "reset_password" or action == "reset_password" + or view == "send_login" + or action == "send_login" or view == "confirm_notify_email" or action == "confirm_notify_email" or view == "menu" diff -r 81bde33c2256 -r 5a712ec1a7f1 app/main/_filter_view/30_navigation.lua --- a/app/main/_filter_view/30_navigation.lua Sat Apr 20 18:40:34 2013 +0200 +++ b/app/main/_filter_view/30_navigation.lua Sat Apr 20 18:51:28 2013 +0200 @@ -39,11 +39,6 @@ module = 'index', view = 'register' } - ui.link{ - text = _"Reset password", - module = 'index', - view = 'reset_password' - } end end) diff -r 81bde33c2256 -r 5a712ec1a7f1 app/main/index/_action/send_login.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/main/index/_action/send_login.lua Sat Apr 20 18:51:28 2013 +0200 @@ -0,0 +1,42 @@ +--trace.disable() + +local email = param.get("email") + +local members = Member:new_selector() + :add_where{ "notify_email = ? OR notify_email_unconfirmed = ?", email, email } + :add_where("login_recovery_expiry ISNULL OR login_recovery_expiry < now()") + :exec() + +if #members < 1 then + return +end + +local logins = {} + +for i, member in ipairs(members) do + local expiry = db:query("SELECT now() + '7 days'::interval as expiry", "object").expiry + member.login_recovery_expiry = expiry + member:save() + logins[#logins+1] = member.login +end + +local content = slot.use_temporary(function() + slot.put(_"Hello,\n\n") + slot.put(_"the following login is connected to this email address:\n\n") + for i, login in ipairs(logins) do + slot.put(_"Login-Name: " .. login .. "\n") + end +end) + +trace.debug(content) +if true then return end + +local success = net.send_mail{ + envelope_from = config.mail_envelope_from, + from = config.mail_from, + reply_to = config.mail_reply_to, + to = email, + subject = config.mail_subject_prefix .. _"Login name request", + content_type = "text/plain; charset=UTF-8", + content = content +} diff -r 81bde33c2256 -r 5a712ec1a7f1 app/main/index/login.lua --- a/app/main/index/login.lua Sat Apr 20 18:40:34 2013 +0200 +++ b/app/main/index/login.lua Sat Apr 20 18:51:28 2013 +0200 @@ -5,7 +5,7 @@ end } -execute.view{ module = "index", view = "_lang_chooser" } +ui.actions() ui.title(_"Login") app.html_title.title = _"Login" @@ -62,5 +62,7 @@ ui.submit{ text = _'Login' } + slot.put("  ") + ui.link{ module = "index", view = "reset_password", text = _"Forgot password?" } end } diff -r 81bde33c2256 -r 5a712ec1a7f1 app/main/index/reset_password.lua --- a/app/main/index/reset_password.lua Sat Apr 20 18:40:34 2013 +0200 +++ b/app/main/index/reset_password.lua Sat Apr 20 18:51:28 2013 +0200 @@ -1,15 +1,14 @@ execute.view{ module = "index", view = "_lang_chooser" } -slot.put_into("title", _"Reset password") +ui.title(_"Reset password") -slot.select("actions", function() +ui.actions(function() ui.link{ content = function() - ui.image{ static = "icons/16/cancel.png" } - slot.put(_"Cancel password reset") + slot.put(_"Cancel") end, module = "index", - view = "index" + view = "login" } end) @@ -34,10 +33,12 @@ }, content = function() ui.field.text{ - label = "Login", + label = _"login name", name = "login" } ui.submit{ text = _"Request password reset link" } + slot.put("  ") + ui.link{ module = "index", view = "send_login", text = _"Forgot login name?" } end } diff -r 81bde33c2256 -r 5a712ec1a7f1 app/main/index/send_login.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/main/index/send_login.lua Sat Apr 20 18:51:28 2013 +0200 @@ -0,0 +1,35 @@ +ui.title(_"Request email with login name") + +ui.actions(function() + ui.link{ + content = function() + slot.put(_"Cancel") + end, + module = "index", + view = "login" + } +end) + +ui.tag{ + tag = 'p', + content = _'Please enter your email address. You will receive an email with your login name.' +} +ui.form{ + attr = { class = "vertical" }, + module = "index", + action = "send_login", + routing = { + ok = { + mode = "redirect", + module = "index", + view = "index" + } + }, + content = function() + ui.field.text{ + label = _"Email address", + name = "email" + } + ui.submit{ text = _"Request email with login name" } + end +}