Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[change] Allowed showing failure messages coming from captive portal … #833

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions client/components/login/captive-portal-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const getUrlParam = (paramName) => {
const searchRegex = new RegExp(
`[?&]${encodeURIComponent(paramName)}=([^&]*)`,
);
const match = searchRegex.exec(window.location.search);
if (match) {
return decodeURIComponent(match[1]);
}
return null;
};

export default function handleCaptivePortalLogin(
captivePortalLoginForm,
setCaptivePortalError,
) {
const res = getUrlParam("res");
const reply = getUrlParam("reply");

if (res === "failed" && reply) {
setCaptivePortalError({
type: "authError",
message: reply,
});
} else {
setCaptivePortalError(null);
}
}
21 changes: 20 additions & 1 deletion client/components/login/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React, {useState, useEffect} from "react";
import PropTypes from "prop-types";
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 +29,20 @@ export const mapDispatchToProps = (dispatch) => ({
setUserData: setUserData(dispatch),
setTitle: setTitle(dispatch),
});
export default connect(mapStateToProps, mapDispatchToProps)(Component);

export const Login = ({captivePortalLoginForm, ...props}) => {
const [captivePortalError, setCaptivePortalError] = useState(null);

useEffect(() => {
handleCaptivePortalLogin(captivePortalLoginForm, setCaptivePortalError);
}, [captivePortalLoginForm]);

return <Component {...props} captivePortalError={captivePortalError} />;
};

Login.propTypes = {
captivePortalLoginForm: PropTypes.shape({}).isRequired,
};

const ConnectedLogin = connect(mapStateToProps, mapDispatchToProps)(Login);
export default ConnectedLogin;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import LoadingContext from "../../utils/loading-context";
import Loader from "../../utils/loader";
import needsVerify from "../../utils/needs-verify";
import loadTranslation from "../../utils/load-translation";
import Login from "../login";
import LoginComponent from "../login";
import {
Registration,
Status,
Expand Down Expand Up @@ -219,7 +219,7 @@ export default class OrganizationWrapper extends React.Component {
isAuthenticated && is_active ? (
<Navigate to={`/${orgSlug}/status`} />
) : (
<Login navigate={navigate} />
<LoginComponent navigate={navigate} />
)
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Footer from "../footer";
import Header from "../header";
import Loader from "../../utils/loader";
import needsVerify from "../../utils/needs-verify";
import Login from "../login";
import LoginComponent from "../login";
import {
Registration,
Status,
Expand Down Expand Up @@ -404,7 +404,7 @@ describe("Test Organization Wrapper for unauthenticated users", () => {
),
);
element = pathMap["login/*"];
expect(JSON.stringify(element)).toEqual(JSON.stringify(<Login />));
expect(JSON.stringify(element)).toEqual(JSON.stringify(<LoginComponent />));
element = pathMap.status;
// userAutoLogin is true
expect(element).toEqual(<Navigate to="/default/logout" />);
Expand Down
Loading