Skip to content

Commit

Permalink
[change] Allowed showing failure messages coming from captive portal #…
Browse files Browse the repository at this point in the history
…604

Closes #604
  • Loading branch information
praptisharma28 committed Nov 6, 2024
1 parent 47b500b commit d1f2772
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions client/components/login/captive-portal-handler.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 16 additions & 1 deletion client/components/login/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 (
<Component
{...props}
captivePortalError={captivePortalError}
/>
);
};
export default connect(mapStateToProps, mapDispatchToProps)(Login);

0 comments on commit d1f2772

Please sign in to comment.