liquid_feedback_frontend

view app/main/index/_action/login.lua @ 1071:58f48a8a202a

Imported and merged LDAP patch
author bsw
date Fri Jul 18 21:42:59 2014 +0200 (2014-07-18)
parents 701a5cf6b067
children aefef1556d55
line source
1 local login = param.get("login")
2 local password = param.get("password")
4 local member, err, uid = Member:by_login_and_password(login, password)
6 if err == "ldap_credentials_valid_but_no_member" then
7 app.session.authority = "ldap"
8 app.session.authority_data = encode.pg_hstore{
9 login = login,
10 uid = uid
11 }
12 app.session:save()
13 request.redirect{
14 module = "index", view = "register", params = {
15 ldap_login = login
16 }
17 }
18 return
19 end
21 function do_etherpad_auth(member)
22 local result = net.curl(
23 config.etherpad.api_base
24 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
25 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
26 )
28 if not result then
29 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
30 return false
31 end
33 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
35 if not etherpad_author_id then
36 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
37 return false
38 end
40 local time_in_24h = os.time() + 24 * 60 * 60
42 local result = net.curl(
43 config.etherpad.api_base
44 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
45 .. "&groupID=" .. config.etherpad.group_id
46 .. "&authorID=" .. etherpad_author_id
47 .. "&validUntil=" .. time_in_24h
48 )
50 if not result then
51 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
52 return false
53 end
55 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
57 if not etherpad_sesion_id then
58 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
59 return false
60 end
62 request.set_cookie{
63 path = config.etherpad.cookie_path,
64 name = "sessionID",
65 value = etherpad_sesion_id
66 }
67 end
69 if member then
70 member.last_login = "now"
72 local delegations = Delegation:delegations_to_check_for_member_id(member.id)
74 if config.check_delegations_interval_hard
75 and member.needs_delegation_check_hard
76 and #delegations > 0 then
78 app.session.needs_delegation_check = true
80 else
82 if #delegations == 0 then
83 member.last_delegation_check = "now"
84 end
86 member.last_activity = "now"
87 member.active = true
89 end
91 if member.lang == nil then
92 member.lang = app.session.lang
93 else
94 app.session.lang = member.lang
95 end
97 if member.password_hash_needs_update then
98 member:set_password(password)
99 end
101 member:save()
102 app.session.member = member
103 app.session:save()
104 trace.debug('User authenticated')
105 if config.etherpad then
106 do_etherpad_auth(member)
107 end
108 slot.select("script", function()
109 ui.script{ script = [[
110 $('#swiper_info').addClass('active');
111 ]] }
112 end)
113 slot.select("swiper_info", function()
114 ui.tag { content = _"select tabs" }
115 slot.put(" ↑ ")
116 ui.tag { content = _"or swipe" }
117 slot.put(" &leftarrow;<br />")
118 ui.tag { content = _"to show more info and learn what you can do" }
119 end )
120 else
121 slot.select("error", function()
122 ui.tag{ content = _'Invalid login name or password!' }
123 end)
124 trace.debug('User NOT authenticated')
125 return false
126 end

Impressum / About Us