liquid_feedback_frontend

view 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 source
1 local member = Member:by_login_and_password(param.get('login'), param.get('password'))
3 function do_etherpad_auth(member)
4 local result = net.curl(
5 config.etherpad.api_base
6 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
7 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
8 )
10 if not result then
11 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
12 return false
13 end
15 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
17 if not etherpad_author_id then
18 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
19 return false
20 end
22 local time_in_24h = os.time() + 24 * 60 * 60
24 local result = net.curl(
25 config.etherpad.api_base
26 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
27 .. "&groupID=" .. config.etherpad.group_id
28 .. "&authorID=" .. etherpad_author_id
29 .. "&validUntil=" .. time_in_24h
30 )
32 if not result then
33 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
34 return false
35 end
37 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
39 if not etherpad_sesion_id then
40 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
41 return false
42 end
44 request.set_cookie{
45 path = config.etherpad.cookie_path,
46 name = "sessionID",
47 value = etherpad_sesion_id
48 }
50 end
53 if member then
54 member.last_login = "now"
55 member.last_activity = "now"
56 member.active = true
57 member:save()
58 app.session.member = member
59 app.session:save()
60 slot.select("notice", function()
61 ui.tag{ content = _'Login successful!' }
62 end)
63 trace.debug('User authenticated')
64 if config.etherpad then
65 do_etherpad_auth(member)
66 end
67 else
68 slot.select("error", function()
69 ui.tag{ content = _'Invalid username or password!' }
70 end)
71 trace.debug('User NOT authenticated')
72 return false
73 end

Impressum / About Us