liquid_feedback_frontend

view app/main/index/_action/login.lua @ 905:e3887fea39fa

Added support for SHA-2 based password hashing
author bsw
date Sun Sep 23 14:35:20 2012 +0200 (2012-09-23)
parents c2022db9f64c
children 81bde33c2256
line source
1 local login = param.get("login")
2 local password = param.get("password")
4 local member = Member:by_login_and_password(login, password)
6 function do_etherpad_auth(member)
7 local result = net.curl(
8 config.etherpad.api_base
9 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
10 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
11 )
13 if not result then
14 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
15 return false
16 end
18 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
20 if not etherpad_author_id then
21 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
22 return false
23 end
25 local time_in_24h = os.time() + 24 * 60 * 60
27 local result = net.curl(
28 config.etherpad.api_base
29 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
30 .. "&groupID=" .. config.etherpad.group_id
31 .. "&authorID=" .. etherpad_author_id
32 .. "&validUntil=" .. time_in_24h
33 )
35 if not result then
36 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
37 return false
38 end
40 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
42 if not etherpad_sesion_id then
43 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
44 return false
45 end
47 request.set_cookie{
48 path = config.etherpad.cookie_path,
49 name = "sessionID",
50 value = etherpad_sesion_id
51 }
53 end
56 if member then
57 member.last_login = "now"
58 member.last_activity = "now"
59 member.active = true
60 if member.lang == nil then
61 member.lang = app.session.lang
62 else
63 app.session.lang = member.lang
64 end
66 if member.password_hash_needs_update then
67 member:set_password(password)
68 end
70 member:save()
71 app.session.member = member
72 app.session:save()
73 trace.debug('User authenticated')
74 if config.etherpad then
75 do_etherpad_auth(member)
76 end
77 else
78 slot.select("error", function()
79 ui.tag{ content = _'Invalid login name or password!' }
80 end)
81 trace.debug('User NOT authenticated')
82 return false
83 end

Impressum / About Us