Commits

Anonymous committed 26c8177

Support for multiple usage terms accept checkboxes
(including neccessary bugfix in member model)

Comments (0)

Files changed (4)

app/main/index/_action/register.lua

   return false
 end
 
-local use_terms_accepted = param.get("use_terms_accepted", atom.boolean)
-
-if login and use_terms_accepted == nil then
+if login and param.get("step") ~= "5" then
   request.redirect{
     mode   = "redirect",
     module = "index",
   return false
 end
 
-if use_terms_accepted ~= true then
-  slot.put_into("error", _"You have to accept the terms of use to complete registration.")
-  request.redirect{
-    mode   = "redirect",
-    module = "index",
-    view   = "register",
-    params = { 
-      code = invite_code.code,
-      notify_email = notify_email,
-      name = name,
-      login = login
-    }
-  }
-  return false
-end
+for i, checkbox in ipairs(config.use_terms_checkboxes) do
+  local accepted = param.get("use_terms_checkbox_" .. checkbox.name, atom.boolean)
+  if not accepted then
+    slot.put_into("error", checkbox.not_accepted_error)
+    return false
+  end
+end  
 
 local password1 = param.get("password1")
 local password2 = param.get("password2")
       login = login
     }
   }
+--]]
   return false
 end
 
 if password1 ~= password2 then
   slot.put_into("error", _"Passwords don't match!")
-  request.redirect{
-    mode   = "redirect",
-    module = "index",
-    view   = "register",
-    params = { 
-      code = invite_code.code,
-      notify_email = notify_email,
-      name = name,
-      login = login
-    }
-  }
   return false
 end
 
 if #password1 < 8 then
   slot.put_into("error", _"Passwords must consist of at least 8 characters!")
-  request.redirect{
-    mode   = "redirect",
-    module = "index",
-    view   = "register",
-    params = { 
-      code = invite_code.code,
-      notify_email = notify_email,
-      name = name,
-      login = login
-    }
-  }
   return false
 end
 
 local success = member:set_notify_email(notify_email)
 if not success then
   slot.put_into("error", _"Can't send confirmation email")
-  request.redirect{
-    mode   = "redirect",
-    module = "index",
-    view   = "register",
-    params = { 
-      code = invite_code.code,
-      notify_email = notify_email,
-      name = name,
-      login = login
-    }
-  }
   return
 end
 
 member:set_password(password1)
 member:save()
 
+for i, checkbox in ipairs(config.use_terms_checkboxes) do
+  local accepted = param.get("use_terms_checkbox_" .. checkbox.name, atom.boolean)
+  member:set_setting("use_terms_checkbox_" .. checkbox.name, "accepted")
+end
+
 invite_code.member_id = member.id
 invite_code.used = "now"
 invite_code:save()

app/main/index/register.lua

       }
 
     else
+      ui.field.hidden{ name = "step", value = "5" }
       slot.put_into("title", _"Step 5/5: Terms of use and password")
       slot.select("actions", function()
         ui.link{
       ui.container{
         attr = { class = "wiki use_terms" },
         content = function()
-          slot.put(format.wiki_text(config.use_terms))
+          if config.use_terms_html then
+            slot.put(config.use_terms_html)
+          else
+            slot.put(format.wiki_text(config.use_terms))
+          end
         end
       }
+
+      for i, checkbox in ipairs(config.use_terms_checkboxes) do
+        slot.put("<br />")
+        ui.tag{
+          tag = "div",
+          content = function()
+            ui.tag{
+              tag = "input",
+              attr = {
+                type = "checkbox",
+                name = "use_terms_checkbox_" .. checkbox.name,
+                value = "1",
+                style = "float: left;",
+                checked = param.get("use_terms_checkbox_" .. checkbox.name, atom.boolean) and "checked" or nil
+              }
+            }
+            slot.put("&nbsp;")
+            slot.put(checkbox.html)
+          end
+        }
+      end
+
       slot.put("<br />")
+
       ui.field.text{
         label     = _'Email address',
         value     = param.get("notify_email"),
 
       ui.tag{
         tag = "p",
-        content = _"I accept the terms of use by checking the following checkbox:"
-      }
-      ui.field.boolean{
-        label     = _"Terms accepted",
-        name      = "use_terms_accepted",
-      }
-
-      ui.tag{
-        tag = "p",
         content = _"Please choose a password and enter it twice. The password is case sensitive."
       }
       ui.field.password{

config/default.lua

 config.app_name = "LiquidFeedback"
-config.app_version = "beta20"
+config.app_version = "beta21"
 
 config.app_title = config.app_name .. " (" .. request.get_config_name() .. " environment)"
 
 config.app_service_provider = "Snake Oil<br/>10000 Berlin<br/>Germany"
 
 config.use_terms = "=== Nutzungsbedingungen ===\nAlles ist verboten"
+--config.use_terms_html = ""
+
+config.use_terms_checkboxes = {
+  {
+    name = "nutzungsbedingungen_v1",
+    html = "Ich akzeptiere die Bedingungen.",
+    not_accepted_error = "Du musst die Bedingungen akzeptieren, um dich zu registrieren."
+  }
+}
+
 
 config.member_image_content_type = "image/jpeg"
 config.member_image_convert_func = {
 end
 
 function Member.object:get_setting(key)
-  return Setting:by_pk(app.session.member.id, key)
+  return Setting:by_pk(self.id, key)
 end
 
 function Member.object:get_setting_value(key)
-  local setting = Setting:by_pk(app.session.member.id, key)
+  local setting = Setting:by_pk(self.id, key)
   if setting then
     return setting.value
   end
   local setting = self:get_setting(key)
   if not setting then
     setting = Setting:new()
-    setting.member_id = app.session.member_id
+    setting.member_id = self.id
     setting.key = key
   end
   setting.value = value