liquid_feedback_frontend

view app/main/index/_action/login.lua @ 1309:32cc544d5a5b

Cumulative patch for upcoming frontend version 4
author bsw/jbe
date Sun Jul 15 14:07:29 2018 +0200 (2018-07-15)
parents 904f6807f7fa
children 71232f776a62
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_uid = uid
9 app.session.authority_login = login
10 app.session:save()
11 request.redirect{
12 module = "index", view = "register", params = {
13 ldap_login = login
14 }
15 }
16 return
17 end
19 local function do_etherpad_auth(member)
20 local result = net.curl(
21 config.etherpad.api_base
22 .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key
23 .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id)
24 )
26 if not result then
27 slot.put_into("error", _"Etherpad authentication failed" .. " 1")
28 return false
29 end
31 local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"')
33 if not etherpad_author_id then
34 slot.put_into("error", _"Etherpad authentication failed" .. " 2")
35 return false
36 end
38 local time_in_24h = os.time() + 24 * 60 * 60
40 local result = net.curl(
41 config.etherpad.api_base
42 .. "api/1/createSession?apikey=" .. config.etherpad.api_key
43 .. "&groupID=" .. config.etherpad.group_id
44 .. "&authorID=" .. etherpad_author_id
45 .. "&validUntil=" .. time_in_24h
46 )
48 if not result then
49 slot.put_into("error", _"Etherpad authentication failed" .. " 3")
50 return false
51 end
53 local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"')
55 if not etherpad_sesion_id then
56 slot.put_into("error", _"Etherpad authentication failed" .. " 4")
57 return false
58 end
60 request.set_cookie{
61 path = config.etherpad.cookie_path,
62 name = "sessionID",
63 value = etherpad_sesion_id
64 }
65 end
67 if member then
68 member.last_login = "now"
70 local delegations = Delegation:delegations_to_check_for_member_id(member.id)
72 if config.check_delegations_interval_hard
73 and member.needs_delegation_check_hard
74 and #delegations > 0 then
76 app.session.needs_delegation_check = true
78 else
80 if #delegations == 0 then
81 member.last_delegation_check = "now"
82 end
84 member.last_activity = "now"
85 member.active = true
87 end
89 if member.lang == nil then
90 member.lang = app.session.lang
91 else
92 app.session.lang = member.lang
93 end
95 if member.password_hash_needs_update then
96 member:set_password(password)
97 end
99 member:save()
100 app.session.member = member
101 app.session:save()
103 trace.debug('User authenticated')
104 if config.etherpad then
105 do_etherpad_auth(member)
106 end
107 slot.select("script", function()
108 ui.script{ script = [[
109 $('#swiper_info').addClass('active');
110 ]] }
111 end)
112 slot.select("swiper_info", function()
113 ui.tag { content = _"select tabs" }
114 slot.put(" ↑ ")
115 ui.tag { content = _"or swipe" }
116 slot.put(" &leftarrow;<br />")
117 ui.tag { content = _"to show more info and learn what you can do" }
118 end )
119 else
120 slot.put_into("error_code", "invalid_credentials")
121 trace.debug('User NOT authenticated')
122 return false
123 end

Impressum / About Us