diff --git a/client/components/login/captive-portal-handler.js b/client/components/login/captive-portal-handler.js new file mode 100644 index 00000000..3383557c --- /dev/null +++ b/client/components/login/captive-portal-handler.js @@ -0,0 +1,16 @@ +function _getParam(name) { + if (name = (new RegExp("[?&]" + encodeURIComponent(name) + "=([^&]*)")).exec(location.search)) + return decodeURIComponent(name[1]); + } + export default function handleCaptivePortalLogin(captivePortalLoginForm, setCaptivePortalError) { + const res = _getParam("res"); + const reply = _getParam("reply"); + if (res === "failed" && reply) { + setCaptivePortalError({ + type: "authError", + message: reply, + }); + } else { + setCaptivePortalError(null); + } + } diff --git a/client/components/login/index.js b/client/components/login/index.js index 64a3b0ec..4d136c7e 100644 --- a/client/components/login/index.js +++ b/client/components/login/index.js @@ -1,7 +1,9 @@ +import React, { useState, useEffect } from 'react'; import {connect} from "react-redux"; import {authenticate, setUserData, setTitle} from "../../actions/dispatchers"; import Component from "./login"; +import handleCaptivePortalLogin from './captive-portal-handler'; export const mapStateToProps = (state) => { const conf = state.organization.configuration; @@ -26,4 +28,17 @@ export const mapDispatchToProps = (dispatch) => ({ setUserData: setUserData(dispatch), setTitle: setTitle(dispatch), }); -export default connect(mapStateToProps, mapDispatchToProps)(Component); + +export const Login = (props) => { + const [captivePortalError, setCaptivePortalError] = useState(null); + useEffect(() => { + handleCaptivePortalLogin(props.captivePortalLoginForm, setCaptivePortalError); + }, [props.captivePortalLoginForm]); + return ( + + ); +}; +export default connect(mapStateToProps, mapDispatchToProps)(Login);