liquid_feedback_frontend

diff app/main/index/_action/login.lua @ 286:c587d8762e62

Registration process updated for Core 2.0, lockable member fields, notification settings
author bsw
date Sat Feb 25 11:51:37 2012 +0100 (2012-02-25)
parents 65a1f7a01e7b
children 44f9a09ea51c
line diff
     1.1 --- a/app/main/index/_action/login.lua	Fri Feb 17 15:16:02 2012 +0100
     1.2 +++ b/app/main/index/_action/login.lua	Sat Feb 25 11:51:37 2012 +0100
     1.3 @@ -1,5 +1,55 @@
     1.4  local member = Member:by_login_and_password(param.get('login'), param.get('password'))
     1.5  
     1.6 +function do_etherpad_auth(member)
     1.7 +  local result = net.curl(
     1.8 +    config.etherpad.api_base
     1.9 +    .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
    1.10 +    .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
    1.11 +  )
    1.12 +  
    1.13 +  if not result then
    1.14 +    slot.put_into("error", _"Etherpad authentication failed" .. " 1")
    1.15 +    return false
    1.16 +  end
    1.17 +  
    1.18 +  local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
    1.19 +  
    1.20 +  if not etherpad_author_id then
    1.21 +    slot.put_into("error", _"Etherpad authentication failed" .. " 2")
    1.22 +    return false
    1.23 +  end
    1.24 +  
    1.25 +  local time_in_24h = os.time() + 24 * 60 * 60
    1.26 +  
    1.27 +  local result = net.curl(
    1.28 +    config.etherpad.api_base 
    1.29 +    .. "api/1/createSession?apikey=" .. config.etherpad.api_key
    1.30 +    .. "&groupID=" .. config.etherpad.group_id
    1.31 +    .. "&authorID=" .. etherpad_author_id
    1.32 +    .. "&validUntil=" .. time_in_24h
    1.33 +  )
    1.34 +
    1.35 +  if not result then
    1.36 +    slot.put_into("error", _"Etherpad authentication failed" .. " 3")
    1.37 +    return false
    1.38 +  end
    1.39 +  
    1.40 +  local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
    1.41 +
    1.42 +  if not etherpad_sesion_id then
    1.43 +    slot.put_into("error", _"Etherpad authentication failed" .. " 4")
    1.44 +    return false
    1.45 +  end
    1.46 +
    1.47 +  request.set_cookie{
    1.48 +    path = config.etherpad.cookie_path,
    1.49 +    name = "sessionID",
    1.50 +    value = etherpad_sesion_id
    1.51 +  }
    1.52 +
    1.53 +end
    1.54 +
    1.55 +
    1.56  if member then
    1.57    member.last_login = "now"
    1.58    member.last_activity = "now"
    1.59 @@ -11,6 +61,9 @@
    1.60      ui.tag{ content = _'Login successful!' }
    1.61    end)
    1.62    trace.debug('User authenticated')
    1.63 +  if config.etherpad then
    1.64 +    do_etherpad_auth(member)
    1.65 +  end
    1.66  else
    1.67    slot.select("error", function()
    1.68      ui.tag{ content = _'Invalid username or password!' }

Impressum / About Us