bsw@905: local login = param.get("login") bsw@905: local password = param.get("password") bsw@905: bsw@1071: local member, err, uid = Member:by_login_and_password(login, password) bsw@1071: bsw@1071: if err == "ldap_credentials_valid_but_no_member" then bsw@1071: app.session.authority = "ldap" bsw@1074: app.session.authority_uid = uid bsw@1074: app.session.authority_login = login bsw@1071: app.session:save() bsw@1071: request.redirect{ bsw@1071: module = "index", view = "register", params = { bsw@1071: ldap_login = login bsw@1071: } bsw@1071: } bsw@1071: return bsw@1071: end bsw/jbe@0: bsw@1145: local function do_etherpad_auth(member) bsw@286: local result = net.curl( bsw@286: config.etherpad.api_base bsw@286: .. "api/1/createAuthorIfNotExistsFor?apikey=" .. config.etherpad.api_key bsw@286: .. "&name=" .. encode.url_part(member.name) .. "&authorMapper=" .. tostring(member.id) bsw@286: ) bsw@286: bsw@286: if not result then bsw@286: slot.put_into("error", _"Etherpad authentication failed" .. " 1") bsw@286: return false bsw@286: end bsw@286: bsw@286: local etherpad_author_id = string.match(result, '"authorID"%s*:%s*"([^"]+)"') bsw@286: bsw@286: if not etherpad_author_id then bsw@286: slot.put_into("error", _"Etherpad authentication failed" .. " 2") bsw@286: return false bsw@286: end bsw@286: bsw@286: local time_in_24h = os.time() + 24 * 60 * 60 bsw@286: bsw@286: local result = net.curl( bsw@286: config.etherpad.api_base bsw@286: .. "api/1/createSession?apikey=" .. config.etherpad.api_key bsw@286: .. "&groupID=" .. config.etherpad.group_id bsw@286: .. "&authorID=" .. etherpad_author_id bsw@286: .. "&validUntil=" .. time_in_24h bsw@286: ) bsw@286: bsw@286: if not result then bsw@286: slot.put_into("error", _"Etherpad authentication failed" .. " 3") bsw@286: return false bsw@286: end bsw@286: bsw@286: local etherpad_sesion_id = string.match(result, '"sessionID"%s*:%s*"([^"]+)"') bsw@286: bsw@286: if not etherpad_sesion_id then bsw@286: slot.put_into("error", _"Etherpad authentication failed" .. " 4") bsw@286: return false bsw@286: end bsw@286: bsw@286: request.set_cookie{ bsw@286: path = config.etherpad.cookie_path, bsw@286: name = "sessionID", bsw@286: value = etherpad_sesion_id bsw@286: } bsw@286: end bsw@286: bsw/jbe@0: if member then bsw@203: member.last_login = "now" bsw@990: bsw@990: local delegations = Delegation:delegations_to_check_for_member_id(member.id) bsw@990: bsw@990: if config.check_delegations_interval_hard bsw@990: and member.needs_delegation_check_hard bsw@990: and #delegations > 0 then bsw@990: bsw@988: app.session.needs_delegation_check = true bsw@990: bsw@988: else bsw@990: bsw@990: if #delegations == 0 then bsw@990: member.last_delegation_check = "now" bsw@990: end bsw@990: bsw@988: member.last_activity = "now" bsw@988: member.active = true bsw@990: bsw@988: end bsw@990: bsw@292: if member.lang == nil then bsw@292: member.lang = app.session.lang bsw@292: else bsw@292: app.session.lang = member.lang bsw@292: end bsw@905: bsw@905: if member.password_hash_needs_update then bsw@905: member:set_password(password) bsw@905: end bsw@905: bsw@203: member:save() bsw/jbe@0: app.session.member = member bsw/jbe@0: app.session:save() bsw/jbe@1309: bsw/jbe@0: trace.debug('User authenticated') bsw@286: if config.etherpad then bsw@286: do_etherpad_auth(member) bsw@286: end bsw@1045: slot.select("script", function() bsw@1045: ui.script{ script = [[ bsw@1045: $('#swiper_info').addClass('active'); bsw@1045: ]] } bsw@1045: end) bsw@1045: slot.select("swiper_info", function() bsw@1045: ui.tag { content = _"select tabs" } bsw@1045: slot.put(" ↑ ") bsw@1045: ui.tag { content = _"or swipe" } bsw@1045: slot.put(" ←
") bsw@1045: ui.tag { content = _"to show more info and learn what you can do" } bsw@1045: end ) bsw/jbe@0: else bsw/jbe@1309: slot.put_into("error_code", "invalid_credentials") bsw/jbe@0: trace.debug('User NOT authenticated') bsw/jbe@0: return false bsw/jbe@0: end