liquid_feedback_frontend

annotate app/main/index/_action/login.lua @ 756:c2022db9f64c

Text updated
author bsw
date Thu Jun 28 22:49:57 2012 +0200 (2012-06-28)
parents 93a40d1c66f4
children e3887fea39fa
rev   line source
bsw/jbe@0 1 local member = Member:by_login_and_password(param.get('login'), param.get('password'))
bsw/jbe@0 2
bsw@286 3 function do_etherpad_auth(member)
bsw@286 4 local result = net.curl(
bsw@286 5 config.etherpad.api_base
bsw@286 6 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
bsw@286 7 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
bsw@286 8 )
bsw@286 9
bsw@286 10 if not result then
bsw@286 11 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
bsw@286 12 return false
bsw@286 13 end
bsw@286 14
bsw@286 15 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
bsw@286 16
bsw@286 17 if not etherpad_author_id then
bsw@286 18 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
bsw@286 19 return false
bsw@286 20 end
bsw@286 21
bsw@286 22 local time_in_24h = os.time() + 24 * 60 * 60
bsw@286 23
bsw@286 24 local result = net.curl(
bsw@286 25 config.etherpad.api_base
bsw@286 26 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
bsw@286 27 .. "&groupID=" .. config.etherpad.group_id
bsw@286 28 .. "&authorID=" .. etherpad_author_id
bsw@286 29 .. "&validUntil=" .. time_in_24h
bsw@286 30 )
bsw@286 31
bsw@286 32 if not result then
bsw@286 33 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
bsw@286 34 return false
bsw@286 35 end
bsw@286 36
bsw@286 37 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
bsw@286 38
bsw@286 39 if not etherpad_sesion_id then
bsw@286 40 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
bsw@286 41 return false
bsw@286 42 end
bsw@286 43
bsw@286 44 request.set_cookie{
bsw@286 45 path = config.etherpad.cookie_path,
bsw@286 46 name = "sessionID",
bsw@286 47 value = etherpad_sesion_id
bsw@286 48 }
bsw@286 49
bsw@286 50 end
bsw@286 51
bsw@286 52
bsw/jbe@0 53 if member then
bsw@203 54 member.last_login = "now"
bsw@272 55 member.last_activity = "now"
bsw@203 56 member.active = true
bsw@292 57 if member.lang == nil then
bsw@292 58 member.lang = app.session.lang
bsw@292 59 else
bsw@292 60 app.session.lang = member.lang
bsw@292 61 end
bsw@203 62 member:save()
bsw/jbe@0 63 app.session.member = member
bsw/jbe@0 64 app.session:save()
bsw/jbe@0 65 trace.debug('User authenticated')
bsw@286 66 if config.etherpad then
bsw@286 67 do_etherpad_auth(member)
bsw@286 68 end
bsw/jbe@0 69 else
bsw@3 70 slot.select("error", function()
bsw@756 71 ui.tag{ content = _'Invalid login name or password!' }
bsw/jbe@0 72 end)
bsw/jbe@0 73 trace.debug('User NOT authenticated')
bsw/jbe@0 74 return false
bsw/jbe@0 75 end

Impressum / About Us