liquid_feedback_frontend

annotate 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
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@203 57 member:save()
bsw/jbe@0 58 app.session.member = member
bsw/jbe@0 59 app.session:save()
bsw/jbe@0 60 slot.select("notice", function()
bsw/jbe@0 61 ui.tag{ content = _'Login successful!' }
bsw/jbe@0 62 end)
bsw/jbe@0 63 trace.debug('User authenticated')
bsw@286 64 if config.etherpad then
bsw@286 65 do_etherpad_auth(member)
bsw@286 66 end
bsw/jbe@0 67 else
bsw@3 68 slot.select("error", function()
bsw/jbe@0 69 ui.tag{ content = _'Invalid username or password!' }
bsw/jbe@0 70 end)
bsw/jbe@0 71 trace.debug('User NOT authenticated')
bsw/jbe@0 72 return false
bsw/jbe@0 73 end

Impressum / About Us