liquid_feedback_frontend
view app/main/index/_action/login.lua @ 383:380730df98ed
Fixed layout of voting privileges info text when not beeing member of any area of an unit
| author | bsw |
|---|---|
| date | Mon Mar 05 11:41:29 2012 +0100 (2012-03-05) |
| parents | 44f9a09ea51c |
| children | 93a40d1c66f4 |
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 if member.lang == nil then
58 member.lang = app.session.lang
59 else
60 app.session.lang = member.lang
61 end
62 member:save()
63 app.session.member = member
64 app.session:save()
65 slot.select("notice", function()
66 ui.tag{ content = _'Login successful!' }
67 end)
68 trace.debug('User authenticated')
69 if config.etherpad then
70 do_etherpad_auth(member)
71 end
72 else
73 slot.select("error", function()
74 ui.tag{ content = _'Invalid username or password!' }
75 end)
76 trace.debug('User NOT authenticated')
77 return false
78 end
