Skip to content

Commit

Permalink
Merge 8b39c0e into 8eec6f6
Browse files Browse the repository at this point in the history
  • Loading branch information
codesankalp committed Jun 8, 2021
2 parents 8eec6f6 + 8b39c0e commit 0690de5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ There are certain environment variables used to configure server logging. The de

All the **HTTP requests** get logged by default in the console during development.

#### Mocking captive portal login and logout

The captive portal login and logout operations can be mocked by using the endpoints
mentioned in [openwisp-radius captive portal mock docs](https://openwisp-radius.readthedocs.io/en/latest/developer/captive_portal_mock.html).

These URLs from OpenWISP RADIUS will be used by default in the development environment.
The captive portal login and logout URLs and their parameters can be changed by
editing the YAML configuration file of the respective organization.

### License

See [LICENSE](https://github.com/openwisp/openwisp-wifi-login-pages/blob/master/LICENSE).
11 changes: 4 additions & 7 deletions client/components/status/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class Status extends React.Component {
loggedOut: false,
userInfo: {},
currentPage: 1,
hasMoreSessions: true,
hasMoreSessions: false,
intervalId: null,
screenWidth: window.innerWidth,
loadSpinner: true,
Expand Down Expand Up @@ -140,6 +140,7 @@ export default class Status extends React.Component {
url,
params,
});
const {headers} = response;
if (params.is_open) {
options.activeSessions = response.data;
options.sessionsToLogout = response.data;
Expand All @@ -148,12 +149,8 @@ export default class Status extends React.Component {
options.pastSessions = pastSessions.concat(response.data);
options.currentPage = params.page;
}
if (
"link" in response.headers &&
!response.headers.link.includes("next")
) {
options.hasMoreSessions = false;
}
options.hasMoreSessions =
"link" in headers && headers.link.includes("next");
this.setState(options);
} catch (error) {
logout(cookies, orgSlug);
Expand Down
24 changes: 24 additions & 0 deletions client/components/status/status.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,4 +677,28 @@ describe("<Status /> interactions", () => {
wrapper.find(".modal-buttons button:last-child").simulate("click", {});
expect(handleLogout).toHaveBeenCalledWith(false);
});
it("should set hasMoreSessions to false if link is not in response headers", async () => {
axios.mockImplementationOnce(() => {
return Promise.resolve({
status: 200,
statusText: "OK",
data: [
{
session_id: 1,
start_time: "2020-09-08T00:22:28-04:00",
stop_time: "2020-09-08T00:22:29-04:00",
},
],
headers: {},
});
});
const prop = createTestProps();
wrapper = shallow(<Status {...prop} />, {
context: {setLoading: jest.fn()},
disableLifecycleMethods: true,
});
wrapper.instance().getUserPassedRadiusSessions();
await tick();
expect(wrapper.instance().state.hasMoreSessions).toEqual(false);
});
});
4 changes: 2 additions & 2 deletions internals/generators/organization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = {
{
type: "input",
name: "login_action_url",
default: "http://127.0.0.1:8080/login",
default: "http://localhost:8000/captive-portal-mock/login/",
message: "What is the captive portal login action URL?",
validate: (value) => {
if (/.+/.test(value)) {
Expand All @@ -70,7 +70,7 @@ module.exports = {
{
type: "input",
name: "logout_action_url",
default: "http://127.0.0.1:8080/logout",
default: "http://localhost:8000/captive-portal-mock/logout/",
message: "What is the captive portal logout action URL?",
validate: (value) => {
if (/.+/.test(value)) {
Expand Down
4 changes: 2 additions & 2 deletions org-configurations/default-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ client:

captive_portal_login_form:
method: post
action: http://localhost/
action: http://localhost:8000/captive-portal-mock/login/
fields:
username: auth_user
password: auth_pass
Expand All @@ -435,7 +435,7 @@ client:

captive_portal_logout_form:
method: post
action: http://localhost:8081
action: http://localhost:8000/captive-portal-mock/logout/
fields:
id: logout_id
additional_fields: []
Expand Down

0 comments on commit 0690de5

Please sign in to comment.