Skip to content

Commit

Permalink
Guest login
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneclaes committed Oct 25, 2020
1 parent e99b2a2 commit 1261fae
Show file tree
Hide file tree
Showing 23 changed files with 359 additions and 59 deletions.
22 changes: 12 additions & 10 deletions docs/about/contribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@ Pull requests welcome!

See [issues](/about/#issues) for reporting bugs or problems.

## Development
## Documentation

See the [build from source](/installation/build-from-source/) section to get started.
These docs are located within the same Github repository that is home to Makerverse. You'll find them in the `docs/` folder, stored as `.md` (markdown) files. Therefore, the contribution process is the same as changing the Makerverse code...

## Localization
## How to Contribute

If you'd like to help contribute translations, you can fork the repository, update resource files in the `src/app/i18n` directory, and create a pull request to submit your changes.
As with contributing to most Github projects, the process is to (1) fork the repository, (2) make and push changes, and then (3) create a pull request. The pull request can then be reviewed and accepted into Makerverse.

### Fork the repository

To fork the makerverse repository, click the <b>Fork</b> button in the header of the repository.

![image](https://user-images.githubusercontent.com/447801/30472117-d757e742-9a2d-11e7-80f8-4ba9ffba97d8.png)

When it’s finished, you’ll be taken to your copy of the makerverse repository. Now you can update the resource files on GitHub, or clone it to your computer.

If you're using <b>GitHub for Desktop</b> application, navigate over to the toolbar, open the <b>Clone or download</b> dropdown, and click <b>Open in Desktop</b> to clone makermadecnc/makerverse to your computer and use it in GitHub Desktop.

![image](https://user-images.githubusercontent.com/447801/30471510-956b51fe-9a2b-11e7-9e43-c5e3fa19e0cb.png)
Expand Down Expand Up @@ -54,6 +48,14 @@ You can continue to make more changes and create new commits. When you’re read

4. That's done.

## Development

See the [build from source](/installation/build-from-source/) section to get started.

## Localization

If you'd like to help contribute translations, you can fork the repository, update resource files in the `src/app/i18n` directory, and create a pull request to submit your changes.

## Translation Validation

You can validate the translation by copying translated resource files to the installed directory. Note that your path may differ based on the Node installation path you have in place.
Expand Down
12 changes: 12 additions & 0 deletions docs/features/advanced.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
layout: default
title: Advanced
parent: Features
nav_order: 10
---

# Advanced

## Turn Off Login (Guest Mode)

To enable guest mode, edit the `~/.makerverse` to include the top-level `insecureDangerousGuestAccess` boolean key.
10 changes: 7 additions & 3 deletions src/app/containers/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { withRouter } from 'react-router-dom';
import without from 'lodash/without';
import Push from 'push.js';
import api from 'app/api';
import { deleteCookie } from 'app/lib/cookies';
import { Tooltip } from 'app/components/Tooltip';
import Anchor from 'app/components/Anchor';
import Space from 'app/components/Space';
Expand Down Expand Up @@ -319,10 +320,13 @@ class Header extends PureComponent {
</MenuItem>
<MenuItem
onClick={() => {
if (auth.isAuthenticated()) {
log.debug('Destroy and cleanup the WebSocket connection');
Workspaces.disconnect();
log.debug('Destroy and cleanup the WebSocket connection');
Workspaces.disconnect();
deleteCookie(auth.GUEST_COOKIE_NAME);

if (auth.isGuest()) {
window.location.replace('/#/login');
} else {
auth.signout();

// Remember current location
Expand Down
20 changes: 17 additions & 3 deletions src/app/containers/Home/CreateWorkspace/CreateWorkspacePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ class CreateWorkspacePanel extends PureComponent {
actions: PropTypes.object
};

state = { machineProfiles: null, isCustomMachine: false };
state = { machineProfiles: null, isCustomMachine: false, fetchBegan: false };

componentDidMount() {
fetchMachineProfiles() {
this.setState({ fetchBegan: true });
fetchMachineProfiles().then((res) => {
this.setState({ machineProfiles: res });
}).catch((err) => {
Expand Down Expand Up @@ -134,7 +135,7 @@ class CreateWorkspacePanel extends PureComponent {
}

render() {
const { isCustomMachine, machineProfiles } = this.state;
const { isCustomMachine, machineProfiles, fetchBegan } = this.state;
const { connectionStatus, alertMessage } = this.props;
const { firmware, customMachine, machineProfileId } = this.props.workspaceSettings;
const { baudRate, controllerType } = firmware || {};
Expand All @@ -155,6 +156,19 @@ class CreateWorkspacePanel extends PureComponent {
const sw2 = isCustomMachine ? 'Search for pre-configured machines'
: 'Switch to manual connection mode';

if (!fetchBegan) {
return (
<div className={styles.widgetEmpty} >
<button
className="btn btn-lg btn-primary"
onClick={() => this.fetchMachineProfiles()}
>
{i18n._('Connect to a New Machine')}
</button>
</div>
);
}

return (
<div className="container-fluid" style={{ padding: 0, margin: -10 }} >
<div className="row" style={{ padding: 0, margin: 0 }}>
Expand Down
84 changes: 78 additions & 6 deletions src/app/containers/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import cx from 'classnames';
import qs from 'qs';
import React, { PureComponent } from 'react';
import { withRouter, Redirect } from 'react-router-dom';
import Anchor from 'app/components/Anchor';
import Space from 'app/components/Space';
import i18n from 'app/lib/i18n';
import log from 'app/lib/log';
import { setCookie, deleteCookie } from 'app/lib/cookies';
import auth from 'app/lib/auth';
import settings from 'app/config/settings';
import analytics from 'app/lib/analytics';
Expand Down Expand Up @@ -42,7 +42,36 @@ class Login extends PureComponent {
authenticating: false,
});
});
}
},
handleGuest: (event) => {
event.preventDefault();

if (this.state.useCookies) {
setCookie(auth.GUEST_COOKIE_NAME, '1');
} else {
deleteCookie(auth.GUEST_COOKIE_NAME);
}

this.setState({
alertMessage: '',
authenticating: true,
redirectToReferrer: false,
});

auth.signin(null, true)
.then((r) => {
this.setState({
redirectToReferrer: true,
authenticating: false
});
})
.catch((e) => {
this.setState({
alertMessage: e.message,
authenticating: false
});
});
},
};

fields = {
Expand All @@ -61,7 +90,10 @@ class Login extends PureComponent {
authenticating: false,
redirectToReferrer: false,
registered: false,
guest: null,
useCookies: false,
errors: this.emptyErrors,
redirect: null,
};
}

Expand Down Expand Up @@ -148,13 +180,17 @@ class Login extends PureComponent {
);
}

componentDidMount() {
auth.guest().then((gm) => this.setState({ guest: !!gm }));
}

render() {
const error = decodeURIComponent(window.location.hash.split('error=')[1] || '');

const { from } = this.props.location.state || { from: { pathname: '/' } };
const state = { ...this.state };
// const actions = { ...this.actions };
const { alertMessage, authenticating, registering } = state;
const { alertMessage, authenticating, registering, guest, dangerous, useCookies } = state;
const docLink = 'http://www.makerverse.com/features/security/';
const showLogout = error && error.includes('Wrong user');
let enabled = !authenticating && this.fields.username && this.fields.username.value.length > 0 &&
Expand Down Expand Up @@ -268,9 +304,45 @@ class Login extends PureComponent {
</form>
</div>
<div className={styles.footer}>
<Anchor href={docLink}>
{i18n._('Why is it necessary to log in?')}
</Anchor>
{!guest && (
<analytics.OutboundLink
eventLabel="why_login"
to={docLink}
target="_blank"
>
{i18n._('Why is it necessary to log in?')}
</analytics.OutboundLink>
)}
{guest && (
<div>
<div className="checkbox">
<label>
<input
type="checkbox"
defaultChecked={useCookies}
onChange={() => this.setState({ useCookies: !useCookies })}
/>
{i18n._('Remember me (I consent to cookies)')}
</label>
<label>
<input
type="checkbox"
defaultChecked={dangerous}
onChange={() => this.setState({ dangerous: !dangerous })}
/>
{i18n._('I understand "guest mode" is hazardous. ')}
</label>
</div>
<br />
<button
className="btn btn-block btn-secondary"
onClick={(e) => this.actions.handleGuest(e)}
disabled={authenticating || !dangerous}
>
{i18n._('Continue as Guest')}
</button>
</div>
)}
</div>
</div>
<br />
Expand Down
12 changes: 10 additions & 2 deletions src/app/i18n/cs/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@
"Could not download machine profiles.": "",
"You will need to use \"manual connection mode,\" below.": "",
"{{ axis }}-Axis": "",
"Axis has no size.": "",
"Accuracy is unusual": "",
"Precision is unusual.": "",
"Axes have been set by your machine profile.": "",
Expand All @@ -592,5 +591,14 @@
"Required version: v{{ requiredVersion }}": "",
"Update available: v{{ suggestedVersion }}": "",
"You have the latest firmware.": "",
"Firmware": ""
"Firmware": "",
"Axis is very small (min and max close together).": "",
"Preparing Machine...": "",
"Applying Settings...": "",
"Refreshing Settings...": "",
"Other": "",
"Is this a new machine?": "",
"Or, have you installed new firmware?": "",
"Selecting \"yes\" will reset (erase) and apply reccomended settings.": "",
"Welcome": ""
}
12 changes: 10 additions & 2 deletions src/app/i18n/de/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@
"Could not download machine profiles.": "",
"You will need to use \"manual connection mode,\" below.": "",
"{{ axis }}-Axis": "",
"Axis has no size.": "",
"Accuracy is unusual": "",
"Precision is unusual.": "",
"Axes have been set by your machine profile.": "",
Expand All @@ -592,5 +591,14 @@
"Required version: v{{ requiredVersion }}": "",
"Update available: v{{ suggestedVersion }}": "",
"You have the latest firmware.": "",
"Firmware": ""
"Firmware": "",
"Axis is very small (min and max close together).": "",
"Preparing Machine...": "",
"Applying Settings...": "",
"Refreshing Settings...": "",
"Other": "",
"Is this a new machine?": "",
"Or, have you installed new firmware?": "",
"Selecting \"yes\" will reset (erase) and apply reccomended settings.": "",
"Welcome": ""
}
12 changes: 10 additions & 2 deletions src/app/i18n/en/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@
"Could not download machine profiles.": "Could not download machine profiles.",
"You will need to use \"manual connection mode,\" below.": "You will need to use \"manual connection mode,\" below.",
"{{ axis }}-Axis": "{{ axis }}-Axis",
"Axis has no size.": "Axis has no size.",
"Accuracy is unusual": "Accuracy is unusual",
"Precision is unusual.": "Precision is unusual.",
"Axes have been set by your machine profile.": "Axes have been set by your machine profile.",
Expand All @@ -592,5 +591,14 @@
"Required version: v{{ requiredVersion }}": "Required version: v{{ requiredVersion }}",
"Update available: v{{ suggestedVersion }}": "Update available: v{{ suggestedVersion }}",
"You have the latest firmware.": "You have the latest firmware.",
"Firmware": "Firmware"
"Firmware": "Firmware",
"Axis is very small (min and max close together).": "Axis is very small (min and max close together).",
"Preparing Machine...": "Preparing Machine...",
"Applying Settings...": "Applying Settings...",
"Refreshing Settings...": "Refreshing Settings...",
"Other": "Other",
"Is this a new machine?": "Is this a new machine?",
"Or, have you installed new firmware?": "Or, have you installed new firmware?",
"Selecting \"yes\" will reset (erase) and apply reccomended settings.": "Selecting \"yes\" will reset (erase) and apply reccomended settings.",
"Welcome": "Welcome"
}
12 changes: 10 additions & 2 deletions src/app/i18n/es/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@
"Could not download machine profiles.": "",
"You will need to use \"manual connection mode,\" below.": "",
"{{ axis }}-Axis": "",
"Axis has no size.": "",
"Accuracy is unusual": "",
"Precision is unusual.": "",
"Axes have been set by your machine profile.": "",
Expand All @@ -592,5 +591,14 @@
"Required version: v{{ requiredVersion }}": "",
"Update available: v{{ suggestedVersion }}": "",
"You have the latest firmware.": "",
"Firmware": ""
"Firmware": "",
"Axis is very small (min and max close together).": "",
"Preparing Machine...": "",
"Applying Settings...": "",
"Refreshing Settings...": "",
"Other": "",
"Is this a new machine?": "",
"Or, have you installed new firmware?": "",
"Selecting \"yes\" will reset (erase) and apply reccomended settings.": "",
"Welcome": ""
}
12 changes: 10 additions & 2 deletions src/app/i18n/fr/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@
"Could not download machine profiles.": "",
"You will need to use \"manual connection mode,\" below.": "",
"{{ axis }}-Axis": "",
"Axis has no size.": "",
"Accuracy is unusual": "",
"Precision is unusual.": "",
"Axes have been set by your machine profile.": "",
Expand All @@ -592,5 +591,14 @@
"Required version: v{{ requiredVersion }}": "",
"Update available: v{{ suggestedVersion }}": "",
"You have the latest firmware.": "",
"Firmware": ""
"Firmware": "",
"Axis is very small (min and max close together).": "",
"Preparing Machine...": "",
"Applying Settings...": "",
"Refreshing Settings...": "",
"Other": "",
"Is this a new machine?": "",
"Or, have you installed new firmware?": "",
"Selecting \"yes\" will reset (erase) and apply reccomended settings.": "",
"Welcome": ""
}
12 changes: 10 additions & 2 deletions src/app/i18n/hu/resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@
"Could not download machine profiles.": "",
"You will need to use \"manual connection mode,\" below.": "",
"{{ axis }}-Axis": "",
"Axis has no size.": "",
"Accuracy is unusual": "",
"Precision is unusual.": "",
"Axes have been set by your machine profile.": "",
Expand All @@ -592,5 +591,14 @@
"Required version: v{{ requiredVersion }}": "",
"Update available: v{{ suggestedVersion }}": "",
"You have the latest firmware.": "",
"Firmware": ""
"Firmware": "",
"Axis is very small (min and max close together).": "",
"Preparing Machine...": "",
"Applying Settings...": "",
"Refreshing Settings...": "",
"Other": "",
"Is this a new machine?": "",
"Or, have you installed new firmware?": "",
"Selecting \"yes\" will reset (erase) and apply reccomended settings.": "",
"Welcome": ""
}

0 comments on commit 1261fae

Please sign in to comment.