mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-09 15:27:30 -05:00
First Commit
This commit is contained in:
42
README.md
42
README.md
@@ -1,2 +1,40 @@
|
||||
# trunk-server
|
||||
Listen to Trunk Record and explore archived calls. This is the software behind
|
||||
trunk-server-docker
|
||||
|
||||
## For Local Testing:
|
||||
- In root dir, run: `./docker-test.sh build`
|
||||
- `./docker-test.sh up -d`
|
||||
|
||||
You can then browser to:
|
||||
- openmhz.test
|
||||
- admin.openmhz.test
|
||||
|
||||
Make sure the following is in: */etc/hosts*
|
||||
|
||||
````
|
||||
##
|
||||
# Host Database
|
||||
#
|
||||
# localhost is used to configure the loopback interface
|
||||
# when the system is booting. Do not change this entry.
|
||||
##
|
||||
127.0.0.1 localhost
|
||||
127.0.0.1 openmhz.test api.openmhz.test admin.openmhz.test media.openmhz.test
|
||||
````
|
||||
|
||||
## Default user name:
|
||||
|
||||
- test@test.com
|
||||
- password: password
|
||||
|
||||
|
||||
## DNS Entries
|
||||
|
||||
CNAMEs need to be created for the various services. Create the CNAMEs below with your DNS host:
|
||||
- api
|
||||
- account
|
||||
- media
|
||||
- admin
|
||||
|
||||
After doing this, you should have the following domains: api.domain.com, account.domain.com, media.domain.com, admin.domain.compose
|
||||
|
||||
## Mailjet
|
||||
|
||||
12
account/.babelrc
Normal file
12
account/.babelrc
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"presets":
|
||||
["@babel/preset-env",
|
||||
"@babel/react"],
|
||||
"plugins": [
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
["@babel/plugin-transform-runtime", {
|
||||
"regenerator": true
|
||||
}],
|
||||
["lodash", { "id": ["lodash", "semantic-ui-react"] }]
|
||||
]
|
||||
}
|
||||
3
account/.dockerignore
Normal file
3
account/.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
lib
|
||||
public
|
||||
37
account/.gitignore
vendored
Normal file
37
account/.gitignore
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
lib/
|
||||
uploads/
|
||||
|
||||
# Dependency directory
|
||||
node_modules
|
||||
assets
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
8
account/.storybook/config.js
Normal file
8
account/.storybook/config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { configure } from '@storybook/react';
|
||||
|
||||
function loadStories() {
|
||||
require('../src/client/stories/index.js');
|
||||
// You can require as many stories as you need.
|
||||
}
|
||||
|
||||
configure(loadStories, module);
|
||||
21
account/Dockerfile
Normal file
21
account/Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
||||
# docker build -t trunk-server-frontend .
|
||||
# do a `git pull` in trunk-server-frontend to update
|
||||
|
||||
FROM node:8.11
|
||||
|
||||
|
||||
ENV HOME=/home/app
|
||||
|
||||
RUN mkdir -p /home/app
|
||||
COPY ./package.json /tmp
|
||||
RUN cd /tmp && npm install
|
||||
RUN cp -a /tmp/node_modules /home/app
|
||||
|
||||
# add `/usr/src/app/node_modules/.bin` to $PATH
|
||||
ENV PATH /usr/app/node_modules/.bin:$PATH
|
||||
|
||||
WORKDIR $HOME
|
||||
COPY . $HOME/
|
||||
RUN npm run build
|
||||
|
||||
CMD ["npm", "run", "start"]
|
||||
21
account/LICENSE
Normal file
21
account/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Frank Kilkelly
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
10
account/devStart.js
Normal file
10
account/devStart.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
Called during development only. Allows us to use ES6 and JSX in our server code.
|
||||
*/
|
||||
|
||||
require('@babel/register')({
|
||||
presets: ["@babel/preset-env",
|
||||
"@babel/react"]
|
||||
});
|
||||
|
||||
require("./src/server/index")
|
||||
16716
account/package-lock.json
generated
Normal file
16716
account/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
90
account/package.json
Normal file
90
account/package.json
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"name": "react-passport-redux-example",
|
||||
"version": "1.0.0",
|
||||
"description": "Demonstration of PassportJS authentication in React w/ Redux.",
|
||||
"main": "devStart.js",
|
||||
"scripts": {
|
||||
"build:lib": "babel src/server --out-dir lib/server",
|
||||
"build:umd": "webpack --config webpack/webpack.config.dev.js",
|
||||
"build:umd:min": "webpack --config webpack/webpack.config.prod.js",
|
||||
"build": "npm run clean && npm run build:lib && npm run build:umd && npm run build:umd:min",
|
||||
"postinstall": "npm run build",
|
||||
"clean": "rimraf lib public/assets",
|
||||
"server": "better-npm-run server",
|
||||
"server:dev": "better-npm-run server:dev",
|
||||
"start": "npm run server",
|
||||
"start:dev": "npm run server:dev",
|
||||
"storybook": "start-storybook -p 9001 -c .storybook"
|
||||
},
|
||||
"betterScripts": {
|
||||
"server": {
|
||||
"command": "node lib/server/index.js",
|
||||
"env": {
|
||||
"NODE_ENV": "production",
|
||||
"MIN_EXT": ".min"
|
||||
}
|
||||
},
|
||||
"server:dev": {
|
||||
"command": "node devStart.js",
|
||||
"env": {
|
||||
"NODE_ENV": "development"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "7.3.1",
|
||||
"axios": "0.18.0",
|
||||
"bcrypt-nodejs": "0.0.3",
|
||||
"better-npm-run": "0.1.1",
|
||||
"body-parser": "1.18.3",
|
||||
"connect-mongo": "2.0.3",
|
||||
"connected-react-router": "6.3.1",
|
||||
"csv-parse": "4.3.3",
|
||||
"d3-time-format": "2.1.3",
|
||||
"express": "4.16.4",
|
||||
"express-session": "1.15.6",
|
||||
"fs-extra": "7.0.1",
|
||||
"lodash": "4.17.11",
|
||||
"mongoose": "5.4.15",
|
||||
"multer": "1.4.1",
|
||||
"node-mailjet": "3.3.1",
|
||||
"node-uuid": "1.4.8",
|
||||
"passport": "0.4.0",
|
||||
"passport-local": "1.0.0",
|
||||
"react": "16.8.3",
|
||||
"react-dom": "16.8.3",
|
||||
"react-redux": "6.0.1",
|
||||
"react-router": "4.3.1",
|
||||
"react-router-dom": "4.3.1",
|
||||
"react-router-redux": "5.0.0-alpha.9",
|
||||
"react-stripe-elements": "2.0.3",
|
||||
"redux": "4.0.1",
|
||||
"redux-thunk": "2.3.0",
|
||||
"semantic-ui-css": "2.4.1",
|
||||
"semantic-ui-react": "0.85.0",
|
||||
"storybook": "1.0.0",
|
||||
"stripe": "6.25.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.2.3",
|
||||
"@babel/core": "7.3.3",
|
||||
"@babel/plugin-proposal-class-properties": "^7.3.0",
|
||||
"@babel/plugin-proposal-export-default-from": "7.2.0",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.3.1",
|
||||
"@babel/plugin-transform-runtime": "7.2.0",
|
||||
"@babel/preset-env": "^7.3.1",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@babel/preset-stage-1": "^7.0.0",
|
||||
"@babel/register": "^7.0.0",
|
||||
"@storybook/react": "4.1.13",
|
||||
"babel-loader": "8.0.5",
|
||||
"babel-plugin-lodash": "3.3.4",
|
||||
"detect-node": "^2.0.4",
|
||||
"redux-logger": "3.0.6",
|
||||
"rimraf": "2.6.3",
|
||||
"webpack": "4.29.5",
|
||||
"webpack-cli": "3.2.3",
|
||||
"webpack-dev-middleware": "^3.5.1",
|
||||
"webpack-hot-middleware": "^2.24.3"
|
||||
}
|
||||
}
|
||||
86
account/src/client/Billing/Billing.js
Normal file
86
account/src/client/Billing/Billing.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import React, { Component } from "react";
|
||||
import { Elements, StripeProvider} from 'react-stripe-elements';
|
||||
import { Container, Header, Segment, Icon, Divider, Button, Message } from 'semantic-ui-react'
|
||||
import PaymentSource from "./PaymentSource"
|
||||
import InvoiceList from "./InvoiceList"
|
||||
// ----------------------------------------------------
|
||||
class Billing extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleShowAddSource = this.handleShowAddSource.bind(this);
|
||||
this.handleNewSource = this.handleNewSource.bind(this);
|
||||
this.state = {showAddSource: false};
|
||||
}
|
||||
|
||||
|
||||
componentDidMount() {
|
||||
this.props.fetchBilling();
|
||||
this.props.fetchInvoices();
|
||||
}
|
||||
handleShowAddSource() {
|
||||
this.setState({
|
||||
showAddSource: !this.state.showAddSource
|
||||
});
|
||||
}
|
||||
handleNewSource(newSource) {
|
||||
this.setState({
|
||||
showAddSource: false
|
||||
});
|
||||
this.props.updateCard(newSource);
|
||||
}
|
||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
||||
render() {
|
||||
var name = this.props.user.firstName + " " + this.props.user.lastName;
|
||||
var section=<div/>;
|
||||
if (!this.props.billing || this.state.showAddSource) {
|
||||
section = (<div>
|
||||
<StripeProvider apiKey="">
|
||||
<Elements>
|
||||
<PaymentSource name={name} email={this.props.user.email} onCancel={this.handleShowAddSource} onSubmit={this.handleNewSource}/>
|
||||
</Elements>
|
||||
</StripeProvider>
|
||||
</div>)
|
||||
} else {
|
||||
section = (<Segment padded='very'>
|
||||
<Divider horizontal>
|
||||
<Header as='h3'>
|
||||
<Icon name='credit card outline' />
|
||||
Card on File
|
||||
</Header>
|
||||
</Divider>
|
||||
<Header as='h3'>
|
||||
<Header.Content>
|
||||
{this.props.billing.source.name} xxxx-{this.props.billing.source.last4}
|
||||
<Header.Subheader>Expires {this.props.billing.source.exp_month} / {this.props.billing.source.exp_year}</Header.Subheader>
|
||||
</Header.Content>
|
||||
</Header>
|
||||
<Button onClick={this.handleShowAddSource}>Change Card</Button>
|
||||
</Segment>)
|
||||
}
|
||||
|
||||
return (
|
||||
<Container text>
|
||||
<Header as='h2'>
|
||||
Payment Method</Header>
|
||||
<p>It is free to use OpenMHz. Add payment in order to upgrade features.</p>
|
||||
{section}
|
||||
<Header as='h2'>
|
||||
Payment History</Header>
|
||||
{this.props.billing.invoices.length > 0 ? (
|
||||
<InvoiceList invoices={this.props.billing.invoices}/>
|
||||
) : (
|
||||
<Message>
|
||||
<Message.Header>Changes in Service</Message.Header>
|
||||
<p>
|
||||
We updated our privacy policy here to better service our customers. We recommend reviewing the
|
||||
changes.
|
||||
</p>
|
||||
</Message>
|
||||
)}
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Billing;
|
||||
17
account/src/client/Billing/BillingContainer.js
Normal file
17
account/src/client/Billing/BillingContainer.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as billingActions from "./billing-actions"
|
||||
import Billing from "./Billing"
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
user: state.user,
|
||||
billing: state.billing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
billingActions
|
||||
)(Billing)
|
||||
43
account/src/client/Billing/InvoiceList.js
Normal file
43
account/src/client/Billing/InvoiceList.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import React, { Component } from "react";
|
||||
|
||||
import {
|
||||
Container,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
class InvoiceList extends Component {
|
||||
|
||||
|
||||
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
const DATE_OPTIONS = { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric' };
|
||||
return (
|
||||
<Table singleLine>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Date</Table.HeaderCell>
|
||||
<Table.HeaderCell>Amount</Table.HeaderCell>
|
||||
<Table.HeaderCell>Status</Table.HeaderCell>
|
||||
<Table.HeaderCell></Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{this.props.invoices.map((invoice, index) => {
|
||||
return( <Table.Row>
|
||||
<Table.Cell>{(new Date(invoice.date*1000)).toLocaleDateString('en-US', DATE_OPTIONS)}</Table.Cell>
|
||||
<Table.Cell>${invoice.amount_due/100}</Table.Cell>
|
||||
<Table.Cell>{invoice.status} </Table.Cell>
|
||||
<Table.Cell><a href={invoice.invoice_pdf}>View Invoice</a> </Table.Cell>
|
||||
</Table.Row>)
|
||||
} )}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
)
|
||||
}
|
||||
}
|
||||
export default InvoiceList;
|
||||
52
account/src/client/Billing/PaymentSource.js
Normal file
52
account/src/client/Billing/PaymentSource.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import React, {Component} from 'react';
|
||||
import { Header, Button, Segment, Form, Icon, Divider } from 'semantic-ui-react'
|
||||
import {CardElement, injectStripe} from 'react-stripe-elements';
|
||||
|
||||
class PaymentSource extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.submit = this.submit.bind(this);
|
||||
this.handleInputChange = this.handleInputChange.bind(this);
|
||||
this.state = {name: this.props.name ? this.props.name : ""};
|
||||
}
|
||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||
async submit(ev) {
|
||||
console.log("here");
|
||||
this.props.stripe.createSource({type: 'card', owner: {
|
||||
name: this.state.name, email: this.props.email
|
||||
}}).then(({source}) => {
|
||||
this.props.onSubmit({sourceId: source.id })
|
||||
console.log('Received Stripe token:', source);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="checkout">
|
||||
<Segment padded='very'>
|
||||
<Form>
|
||||
<Divider horizontal>
|
||||
<Header as='h3'>
|
||||
<Icon name='credit card outline' />
|
||||
Credit or Debit Card
|
||||
</Header>
|
||||
</Divider>
|
||||
<Form.Input fluid label='Name on card' placeholder='Name'
|
||||
name="name"
|
||||
defaultValue={this.state.name}
|
||||
onChange={this.handleInputChange}/>
|
||||
<Form.Field>
|
||||
<CardElement />
|
||||
</Form.Field>
|
||||
<Divider hidden />
|
||||
<Button onClick={this.submit}>Submit</Button>
|
||||
</Form>
|
||||
<img src="../../resources/powered_by_stripe.png" />
|
||||
</Segment>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default injectStripe(PaymentSource);
|
||||
145
account/src/client/Billing/billing-actions.js
Normal file
145
account/src/client/Billing/billing-actions.js
Normal file
@@ -0,0 +1,145 @@
|
||||
import axios from "axios";
|
||||
import * as types from "./billing-constants";
|
||||
import { push } from 'connected-react-router';
|
||||
|
||||
|
||||
function beginUpdateCard() {
|
||||
return { type: types.UPDATE_CARD };
|
||||
}
|
||||
|
||||
function updateCardSuccess(data) {
|
||||
return { type: types.UPDATE_CARD_SUCCESS, data };
|
||||
}
|
||||
|
||||
function updateCardError(data) {
|
||||
return { type: types.UPDATE_CARD_ERROR, data };
|
||||
}
|
||||
|
||||
|
||||
function beginFetchBilling() {
|
||||
return { type: types.FETCH_BILLING };
|
||||
}
|
||||
|
||||
function fetchBillingSuccess(data) {
|
||||
return { type: types.FETCH_BILLING_SUCCESS,
|
||||
data };
|
||||
}
|
||||
|
||||
|
||||
function fetchBillingError(data) {
|
||||
return { type: types.FETCH_BILLING_ERROR,
|
||||
data };
|
||||
}
|
||||
|
||||
function beginFetchInvoice() {
|
||||
return { type: types.FETCH_INVOICE };
|
||||
}
|
||||
|
||||
function fetchInvoiceSuccess(data) {
|
||||
return { type: types.FETCH_INVOICE_SUCCESS,
|
||||
data };
|
||||
}
|
||||
|
||||
|
||||
function fetchInvoiceError(data) {
|
||||
return { type: types.FETCH_INVOICE_ERROR,
|
||||
data };
|
||||
}
|
||||
|
||||
function makeUserRequest(method, data, api = "/login") {
|
||||
// returns a Promise
|
||||
return axios({
|
||||
method: method,
|
||||
url: api,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
|
||||
export function changeUrl(url) {
|
||||
return dispatch => {
|
||||
dispatch(push(url));
|
||||
};
|
||||
}
|
||||
|
||||
// Example of an Async Action Creator
|
||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
||||
|
||||
export function updateCard(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginUpdateCard());
|
||||
|
||||
return makeUserRequest("post", data, "/api/customer/", {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
|
||||
|
||||
dispatch(updateCardSuccess(response.data));
|
||||
} else {
|
||||
dispatch(updateCardError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export function fetchBilling() {
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch(beginFetchBilling());
|
||||
|
||||
return axios
|
||||
.get("/api/billing", {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(fetchBillingSuccess(response.data));
|
||||
} else {
|
||||
dispatch(fetchBillingError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchInvoices() {
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch(beginFetchInvoice());
|
||||
|
||||
return axios
|
||||
.get("/api/invoices", {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(fetchInvoiceSuccess(response.data));
|
||||
} else {
|
||||
dispatch(fetchInvoiceError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
11
account/src/client/Billing/billing-constants.js
Normal file
11
account/src/client/Billing/billing-constants.js
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
export const UPDATE_CARD = "UPDATE_CARD"
|
||||
export const UPDATE_CARD_SUCCESS = "UPDATE_CARD_SUCCESS"
|
||||
export const UPDATE_CARD_ERROR = "UPDATE_CARD_ERROR"
|
||||
export const FETCH_BILLING = "FETCH_BILLING"
|
||||
export const FETCH_BILLING_SUCCESS = "FETCH_BILLING_SUCCESS"
|
||||
export const FETCH_BILLING_ERROR = "FETCH_BILLING_ERROR"
|
||||
export const FETCH_INVOICE = "FETCH_INVOICE"
|
||||
export const FETCH_INVOICE_SUCCESS = "FETCH_INVOICE_SUCCESS"
|
||||
export const FETCH_INVOICE_ERROR = "FETCH_INVOICE_ERROR"
|
||||
|
||||
71
account/src/client/Billing/billing-reducer.js
Normal file
71
account/src/client/Billing/billing-reducer.js
Normal file
@@ -0,0 +1,71 @@
|
||||
import {
|
||||
UPDATE_CARD,
|
||||
UPDATE_CARD_SUCCESS,
|
||||
UPDATE_CARD_ERROR,
|
||||
FETCH_BILLING,
|
||||
FETCH_BILLING_SUCCESS,
|
||||
FETCH_BILLING_ERROR,
|
||||
FETCH_INVOICE,
|
||||
FETCH_INVOICE_SUCCESS,
|
||||
FETCH_INVOICE_ERROR
|
||||
} from "./billing-constants";
|
||||
|
||||
function updateObject(oldObject, newValues) {
|
||||
// Encapsulate the idea of passing a new object as the first parameter
|
||||
// to Object.assign to ensure we correctly copy data instead of mutating
|
||||
return Object.assign({}, oldObject, newValues);
|
||||
}
|
||||
|
||||
function updateObjectInArray(array, shortName, updatedItem) {
|
||||
return array.map( item => {
|
||||
if(item.shortName !== shortName) {
|
||||
// This isn't the item we care about - keep it as-is
|
||||
return item;
|
||||
}
|
||||
|
||||
// Otherwise, this is the one we want - return an updated value
|
||||
return {
|
||||
...item,
|
||||
...updatedItem
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const billing = (
|
||||
state = {
|
||||
isWaiting: false,
|
||||
source: false,
|
||||
invoices: []},
|
||||
action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
|
||||
case UPDATE_CARD:
|
||||
case FETCH_BILLING:
|
||||
case FETCH_INVOICE:
|
||||
return Object.assign({}, state, { isWaiting: true});
|
||||
|
||||
|
||||
case UPDATE_CARD_SUCCESS:
|
||||
return Object.assign({}, state, { source: action.data.source, isWaiting: false});
|
||||
|
||||
case FETCH_BILLING_SUCCESS:
|
||||
return Object.assign({}, state, { source: action.data.source, isWaiting: false});
|
||||
|
||||
case FETCH_INVOICE_SUCCESS:
|
||||
return Object.assign({}, state, { invoices: action.data.invoices, isWaiting: false});
|
||||
|
||||
case UPDATE_CARD_ERROR:
|
||||
case FETCH_BILLING_ERROR:
|
||||
case FETCH_INVOICE_ERROR:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false
|
||||
});
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default billing;
|
||||
140
account/src/client/Plan/ListPlans.js
Normal file
140
account/src/client/Plan/ListPlans.js
Normal file
@@ -0,0 +1,140 @@
|
||||
import React, { Component } from "react";
|
||||
|
||||
import {
|
||||
Container,
|
||||
Divider,
|
||||
Checkbox,
|
||||
Button,
|
||||
Header,
|
||||
Table, Form
|
||||
} from "semantic-ui-react";
|
||||
// ----------------------------------------------------
|
||||
|
||||
|
||||
function planPrice(planType) {
|
||||
switch(planType) {
|
||||
case freePlanValue:
|
||||
return freePlanPrice;
|
||||
case proPlanValue:
|
||||
return proPlanPrice;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ListPlans extends Component {
|
||||
|
||||
|
||||
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleCancel = this.handleCancel.bind(this);
|
||||
this.handleUpdate = this.handleUpdate.bind(this);
|
||||
this.handleInputChange = this.handleInputChange.bind(this);
|
||||
var plans = {};
|
||||
var prices = {};
|
||||
var total = 0;
|
||||
|
||||
this.props.systems.forEach(system => {
|
||||
plans[system.shortName] = system.planType;
|
||||
prices[system.shortName] = planPrice(system.planType);
|
||||
total += planPrice(system.planType);
|
||||
});
|
||||
this.state = { plans: plans, prices: prices, total: total };
|
||||
}
|
||||
|
||||
|
||||
handleCancel() {
|
||||
var obj = {}
|
||||
this.props.systems.forEach(system => {
|
||||
obj[system.shortName] = system.planType;
|
||||
});
|
||||
this.setState({ plans: obj });
|
||||
}
|
||||
handleUpdate() {
|
||||
this.props.onUpdate(this.state.plans);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
}
|
||||
|
||||
handleInputChange(e, { name, value }) {
|
||||
var plans = this.state.plans;
|
||||
var prices = this.state.prices;
|
||||
var total = 0;
|
||||
plans[name] = value;
|
||||
prices[name] = planPrice(value);
|
||||
for (var system in prices) {
|
||||
total += prices[system];
|
||||
}
|
||||
this.setState({ plans: plans, prices: prices, total: total });
|
||||
}
|
||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
||||
render() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Table definition>
|
||||
<Table.Header>
|
||||
|
||||
<Table.Row>
|
||||
<Table.HeaderCell />
|
||||
<Table.HeaderCell textAlign='center'>Free</Table.HeaderCell>
|
||||
<Table.HeaderCell textAlign='center'>Pro</Table.HeaderCell>
|
||||
<Table.HeaderCell textAlign='center'>Monthly Price</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<tbody>
|
||||
{this.props.systems.map((system) =>
|
||||
|
||||
<Table.Row key={system.shortName}>
|
||||
<Table.Cell>
|
||||
<Header as='h4'>
|
||||
<Header.Content>
|
||||
{system.name}
|
||||
<Header.Subheader>{system.shortName}</Header.Subheader>
|
||||
</Header.Content>
|
||||
|
||||
</Header>
|
||||
</Table.Cell>
|
||||
<Table.Cell textAlign='center'>
|
||||
<Checkbox
|
||||
radio
|
||||
value={0}
|
||||
name={system.shortName}
|
||||
checked={this.state.plans[system.shortName] === 0}
|
||||
onChange={this.handleInputChange}
|
||||
/>
|
||||
</Table.Cell>
|
||||
<Table.Cell textAlign='center'>
|
||||
<Checkbox
|
||||
radio
|
||||
value={10}
|
||||
name={system.shortName}
|
||||
checked={this.state.plans[system.shortName] === 10}
|
||||
onChange={this.handleInputChange}
|
||||
/>
|
||||
</Table.Cell>
|
||||
<Table.Cell textAlign='center'>${this.state.prices[system.shortName]}</Table.Cell>
|
||||
</Table.Row>
|
||||
|
||||
)}
|
||||
<Table.Row key="total">
|
||||
<Table.Cell></Table.Cell>
|
||||
<Table.Cell></Table.Cell>
|
||||
<Table.Cell textAlign='right'>Estimated Monthly Total:</Table.Cell>
|
||||
<Table.Cell textAlign='center'>${this.state.total}</Table.Cell>
|
||||
</Table.Row>
|
||||
</tbody>
|
||||
</Table>
|
||||
<Button.Group floated="right">
|
||||
<Button content='Cancel' onClick={this.handleCancel} />
|
||||
<Button content='Update' onClick={this.handleUpdate} primary />
|
||||
</Button.Group>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ListPlans;
|
||||
131
account/src/client/Plan/UpdatePlans.js
Normal file
131
account/src/client/Plan/UpdatePlans.js
Normal file
@@ -0,0 +1,131 @@
|
||||
import React, { Component } from "react";
|
||||
import {
|
||||
Container,
|
||||
Divider,
|
||||
Modal,
|
||||
Button,
|
||||
Segment,
|
||||
Icon,
|
||||
Link,
|
||||
Header, Form, List} from "semantic-ui-react";
|
||||
import ListPlans from "./ListPlans"
|
||||
|
||||
|
||||
function planName(planType) {
|
||||
switch(planType) {
|
||||
case freePlanValue:
|
||||
return "Free";
|
||||
case proPlanValue:
|
||||
return "Pro";
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
class UpdatePlans extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleUpdate = this.handleUpdate.bind(this);
|
||||
this.handleOk = this.handleOk.bind(this);
|
||||
this.handleCancel = this.handleCancel.bind(this);
|
||||
this.findPlanChanges = this.findPlanChanges.bind(this);
|
||||
}
|
||||
|
||||
state = { modalOpen: false, updatedPlans: {}, changes: [] }
|
||||
|
||||
showModal = () => this.setState({ modalOpen: true })
|
||||
closeModal = () => this.setState({ modalOpen: false })
|
||||
|
||||
findPlanChanges(plans) {
|
||||
var changes = [];
|
||||
const systems = this.props.system.items;
|
||||
systems.forEach(system => {
|
||||
const newPlan = plans[system.shortName];
|
||||
if (newPlan != system.planType) {
|
||||
changes.push( system.name + " - " + planName(newPlan));
|
||||
}
|
||||
});
|
||||
return changes;
|
||||
}
|
||||
|
||||
|
||||
handleOk(){
|
||||
this.props.updatePlan(this.state.updatedPlans);
|
||||
this.closeModal();
|
||||
}
|
||||
|
||||
handleCancel() {
|
||||
this.setState({updatedPlans: {}});
|
||||
this.closeModal();
|
||||
}
|
||||
|
||||
handleUpdate(plans) {
|
||||
const changes = this.findPlanChanges(plans);
|
||||
|
||||
if (Array.isArray(changes) && changes.length) {
|
||||
var result = Object.keys(plans).map(function(key) {
|
||||
return {shortName: key, planType: plans[key]};
|
||||
});
|
||||
this.setState({updatedPlans: result, changes: changes});
|
||||
this.showModal()
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.fetchSystems();
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
||||
render() {
|
||||
const systems = this.props.system.items;
|
||||
const billingDefined = this.props.user.billing;
|
||||
return (
|
||||
<div>
|
||||
<Container text>
|
||||
<Modal size="tiny" open={this.state.modalOpen} onClose={this.closeModal}>
|
||||
<Modal.Header>Update Plans</Modal.Header>
|
||||
<Modal.Content>
|
||||
|
||||
<Header as='h4'>The following changes will be made:</Header>
|
||||
<List as='ul'>
|
||||
{this.state.changes.map((change) =>
|
||||
<List.Item as='li' content={change}/>
|
||||
)}
|
||||
</List>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={this.handleCancel} >
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={this.handleOk} primary>
|
||||
OK
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
<Form>
|
||||
<Header as="h1">System Plans</Header>
|
||||
|
||||
<Divider />
|
||||
{billingDefined? (
|
||||
<ListPlans systems={systems} onUpdate={this.handleUpdate} key={systems.length}/>
|
||||
) : (
|
||||
<Segment>
|
||||
<Header icon>
|
||||
<Icon name='credit card outline' />
|
||||
You need to add a Payment Method before you can upgrade a Plan
|
||||
</Header>
|
||||
<Button primary
|
||||
to='/billing'>Add Payment Method</Button>
|
||||
</Segment>
|
||||
)}
|
||||
</Form>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default UpdatePlans;
|
||||
19
account/src/client/Plan/UpdatePlansContainer.js
Normal file
19
account/src/client/Plan/UpdatePlansContainer.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as systemActions from "../System/system-actions"
|
||||
import * as billingActions from "../Billing/billing-actions"
|
||||
import UpdatePlans from "./UpdatePlans"
|
||||
import { bindActionCreators } from 'redux'
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
system: state.system,
|
||||
user: state.user
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
systemActions
|
||||
)(UpdatePlans)
|
||||
156
account/src/client/System/system-actions.js
Normal file
156
account/src/client/System/system-actions.js
Normal file
@@ -0,0 +1,156 @@
|
||||
import axios from "axios";
|
||||
//import { browserHistory } from "react-router"
|
||||
import * as types from "./system-constants";
|
||||
import { push } from 'connected-react-router';
|
||||
|
||||
|
||||
function beginUpdateSystem() {
|
||||
return { type: types.UPDATE_SYSTEM };
|
||||
}
|
||||
|
||||
function updateSystemSuccess(data) {
|
||||
return { type: types.UPDATE_SUCCESS_SYSTEM, data };
|
||||
}
|
||||
|
||||
function updateSystemError(data) {
|
||||
return { type: types.UPDATE_ERROR_SYSTEM, data };
|
||||
}
|
||||
|
||||
|
||||
function beginFetchSystem() {
|
||||
return { type: types.FETCH_SYSTEM };
|
||||
}
|
||||
|
||||
function fetchSystemSuccess(data) {
|
||||
return { type: types.FETCH_SUCCESS_SYSTEM,
|
||||
data };
|
||||
}
|
||||
|
||||
|
||||
function fetchSystemError(data) {
|
||||
return { type: types.FETCH_ERROR_SYSTEM,
|
||||
data };
|
||||
}
|
||||
|
||||
function beginUpdatePlan() {
|
||||
return { type: types.UPDATE_PLAN };
|
||||
}
|
||||
|
||||
function updatePlanSuccess(data) {
|
||||
return { type: types.UPDATE_PLAN_SUCCESS,
|
||||
data };
|
||||
}
|
||||
|
||||
|
||||
function updatePlanError(data) {
|
||||
return { type: types.UPDATE_PLAN_ERROR,
|
||||
data };
|
||||
}
|
||||
|
||||
|
||||
function makeUserRequest(method, data, api = "/login") {
|
||||
// returns a Promise
|
||||
return axios({
|
||||
method: method,
|
||||
url: api,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
|
||||
export function changeUrl(url) {
|
||||
return dispatch => {
|
||||
dispatch(push(url));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function updatePlan(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginUpdatePlan());
|
||||
|
||||
return makeUserRequest("post", {updatePlans:data}, account_server + "/api/plans/", {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(updatePlanSuccess(response.data.systems));
|
||||
} else {
|
||||
dispatch(updatePlanError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Example of an Async Action Creator
|
||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
||||
|
||||
export function updateSystem(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginUpdateSystem());
|
||||
|
||||
return makeUserRequest("post", data, admin_server + "/systems/" + data.shortName, {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const user = response.data.user
|
||||
|
||||
dispatch(updateSystemSuccess(response.data.system));
|
||||
dispatch(push("/system/"+data.shortName));
|
||||
} else {
|
||||
dispatch(updateProfileError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function shouldFetchSystems(state, subreddit) {
|
||||
if ((!state.system.items) || (state.system.items.length <1)) {
|
||||
return true
|
||||
} else if (state.system.isWaiting) {
|
||||
return false
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function fetchSystems() {
|
||||
return (dispatch, getState) => {
|
||||
if (shouldFetchSystems(getState())) {
|
||||
dispatch(beginFetchSystem());
|
||||
|
||||
return axios
|
||||
.get(admin_server + "/systems", {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(fetchSystemSuccess(response.data.systems));
|
||||
} else {
|
||||
dispatch(fetchSystemError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
10
account/src/client/System/system-constants.js
Normal file
10
account/src/client/System/system-constants.js
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
export const UPDATE_SYSTEM = "UPDATE_SYSTEM"
|
||||
export const UPDATE_SUCCESS_SYSTEM = "UPDATE_SUCCESS_SYSTEM"
|
||||
export const UPDATE_ERROR_SYSTEM = "UPDATE_ERROR_SYSTEM"
|
||||
export const FETCH_SYSTEM = "FETCH_SYSTEM"
|
||||
export const FETCH_SUCCESS_SYSTEM = "FETCH_SUCCESS_SYSTEM"
|
||||
export const FETCH_ERROR_SYSTEM = "FETCH_ERROR_SYSTEM"
|
||||
export const UPDATE_PLAN = "UPDATE_PLAN"
|
||||
export const UPDATE_PLAN_SUCCESS = "UPDATE_PLAN_SUCCESS"
|
||||
export const UPDATE_PLAN_ERROR = "UPDATE_PLAN_ERROR"
|
||||
78
account/src/client/System/system-reducer.js
Normal file
78
account/src/client/System/system-reducer.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import {
|
||||
UPDATE_SYSTEM,
|
||||
UPDATE_SUCCESS_SYSTEM,
|
||||
UPDATE_ERROR_SYSTEM,
|
||||
FETCH_SYSTEM,
|
||||
FETCH_SUCCESS_SYSTEM,
|
||||
FETCH_ERROR_SYSTEM,
|
||||
UPDATE_PLAN,
|
||||
UPDATE_PLAN_SUCCESS,
|
||||
UPDATE_PLAN_ERROR
|
||||
} from "./system-constants";
|
||||
|
||||
function updateObject(oldObject, newValues) {
|
||||
// Encapsulate the idea of passing a new object as the first parameter
|
||||
// to Object.assign to ensure we correctly copy data instead of mutating
|
||||
return Object.assign({}, oldObject, newValues);
|
||||
}
|
||||
|
||||
function updateObjectInArray(array, shortName, updatedItem) {
|
||||
return array.map( item => {
|
||||
if(item.shortName !== shortName) {
|
||||
// This isn't the item we care about - keep it as-is
|
||||
return item;
|
||||
}
|
||||
|
||||
// Otherwise, this is the one we want - return an updated value
|
||||
return {
|
||||
...item,
|
||||
...updatedItem
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const system = (
|
||||
state = {
|
||||
isWaiting: false,
|
||||
items: []},
|
||||
action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
|
||||
case UPDATE_SYSTEM:
|
||||
case FETCH_SYSTEM:
|
||||
case UPDATE_PLAN:
|
||||
|
||||
return Object.assign({}, state, { isWaiting: true});
|
||||
|
||||
|
||||
case UPDATE_PLAN_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: action.data
|
||||
});
|
||||
|
||||
case UPDATE_SUCCESS_SYSTEM:
|
||||
return Object.assign({}, state, {
|
||||
items: updateObjectInArray(state.items, action.data.shortName, action.data)
|
||||
});
|
||||
case FETCH_SUCCESS_SYSTEM:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: action.data
|
||||
});
|
||||
|
||||
case UPDATE_PLAN_ERROR:
|
||||
case UPDATE_ERROR_SYSTEM:
|
||||
case FETCH_ERROR_SYSTEM:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false
|
||||
});
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default system;
|
||||
81
account/src/client/User/ConfirmEmail.js
Normal file
81
account/src/client/User/ConfirmEmail.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import React, { Component } from "react";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Dimmer,
|
||||
Loader,
|
||||
Button,
|
||||
Message,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
class ConfirmEmail extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
state = {
|
||||
loading: true,
|
||||
confirmMessage: { success: false, message:""}
|
||||
};
|
||||
componentDidMount() {
|
||||
const { match: { params } } = this.props;
|
||||
|
||||
this.props
|
||||
.confirmEmail(params.userId, params.token)
|
||||
.then(confirmMessage => {
|
||||
if (confirmMessage) {
|
||||
// report to the user is there was a problem during login
|
||||
this.setState({
|
||||
confirmMessage: confirmMessage, loading: false
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var dimmerProps = { };
|
||||
if (this.state.loading) {
|
||||
dimmerProps["active"] = true;
|
||||
}
|
||||
return (
|
||||
|
||||
<Container text>
|
||||
<Dimmer {...dimmerProps}>
|
||||
<Loader indeterminate>Confirming Email Address</Loader>
|
||||
</Dimmer>
|
||||
|
||||
|
||||
{this.state.confirmMessage.success ? (
|
||||
<Message icon>
|
||||
|
||||
<Icon name='check'/>
|
||||
<Message.Content>
|
||||
<Message.Header>Success</Message.Header>
|
||||
<p>You have successfully confirmed you email address.</p>
|
||||
<Link to="/">
|
||||
<Button
|
||||
size="large"
|
||||
content="Continue to Login"
|
||||
fluid
|
||||
/></Link>
|
||||
|
||||
</Message.Content>
|
||||
</Message>
|
||||
) : (
|
||||
<Message icon>
|
||||
<Icon name='exclamation'/>
|
||||
<Message.Content>
|
||||
<Message.Header>Error</Message.Header>
|
||||
<p>{this.state.confirmMessage.message}</p>
|
||||
</Message.Content>
|
||||
|
||||
</Message>
|
||||
)}
|
||||
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ConfirmEmail;
|
||||
14
account/src/client/User/ConfirmEmailContainer.js
Normal file
14
account/src/client/User/ConfirmEmailContainer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { connect } from "react-redux"
|
||||
import ConfirmEmail from "./ConfirmEmail"
|
||||
import * as userActions from "./user-actions"
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
user: state.user
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(ConfirmEmail)
|
||||
196
account/src/client/User/Login.js
Normal file
196
account/src/client/User/Login.js
Normal file
@@ -0,0 +1,196 @@
|
||||
import React, { PropTypes, Component } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Divider
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const dividerStyle = {
|
||||
marginTop: "40px"
|
||||
};
|
||||
|
||||
const forgotStyle = {
|
||||
marginTop: "40px",
|
||||
textAlign: "right"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
|
||||
|
||||
class Login extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this._onLoginSubmit = this._onLoginSubmit.bind(this);
|
||||
this.handleInputChange = this.handleInputChange.bind(this);
|
||||
this.handleRegisterClick = this.handleRegisterClick.bind(this);
|
||||
}
|
||||
|
||||
state = {
|
||||
loginMessage: "",
|
||||
email: "",
|
||||
password: ""
|
||||
};
|
||||
handleRegisterClick = () => {
|
||||
this.props.changeUrl("/register");
|
||||
};
|
||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||
_onLoginSubmit(event) {
|
||||
event.preventDefault();
|
||||
const { email, password } = this.state;
|
||||
var success = {type: "path", nextPathname: "/" };
|
||||
if (this.props.nextPathname) {
|
||||
success.nextPathname = this.props.nextPathname;
|
||||
}
|
||||
if (this.props.nextLocation) {
|
||||
success.type = "location";
|
||||
switch(this.props.nextLocation) {
|
||||
case "admin":
|
||||
success.nextLocation = admin_server;
|
||||
break;
|
||||
case "frontend":
|
||||
success.nextLocation = frontend_server;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Passed in via react-redux. Returns a promise.
|
||||
this.props
|
||||
.manualLogin(
|
||||
{
|
||||
// this function is passed in via react-redux
|
||||
email,
|
||||
password
|
||||
},
|
||||
success
|
||||
|
||||
) // holds the path to redirect to after login (if any)
|
||||
.then(loginMessage => {
|
||||
if (loginMessage) {
|
||||
// report to the user is there was a problem during login
|
||||
this.setState({
|
||||
loginMessage
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var loginMessage = "";
|
||||
const { name, email } = this.state;
|
||||
|
||||
if (this.state.loginMessage) {
|
||||
loginMessage = (
|
||||
<Message icon>
|
||||
<Icon name="lemon" />
|
||||
<Message.Content>
|
||||
<Message.Header>Problems...</Message.Header>
|
||||
{this.state.loginMessage}
|
||||
</Message.Content>
|
||||
</Message>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Header as="h1">{site_name}</Header>
|
||||
<Grid stackable >
|
||||
<Grid.Row>
|
||||
<Grid.Column width={9}>
|
||||
|
||||
<Header size="large">Let's get this started!</Header>
|
||||
<Header size="small">
|
||||
{site_name} makes it easy to share recordings from{" "}
|
||||
<a href="https://github.com/robotastic/trunk-recorder">
|
||||
Trunk Recorder
|
||||
</a>.</Header>
|
||||
<p>
|
||||
Trunk Recorder makes it easy to record the radio systems
|
||||
used by your local police and fire department. Trunk Recorder
|
||||
is sort of like an awesome version of those Scanners from
|
||||
Radio Shack... 10-4!
|
||||
</p>
|
||||
<p>
|
||||
This site is a work in progress. I plan on adding more
|
||||
features over time, but right now it can:
|
||||
</p>
|
||||
<ul>
|
||||
<li>3 day archive</li>
|
||||
<li>Filter by talkgroup</li>
|
||||
</ul>
|
||||
<p>
|
||||
All of this goodness is free! In the future, I might offer
|
||||
paid accounts with additional features and a longer archive
|
||||
period, but I will always try to have a free version.
|
||||
</p>
|
||||
<p>
|
||||
{" "}
|
||||
- Luke{" "}
|
||||
<a
|
||||
href="mailto:{admin_email}?Subject={site_name}"
|
||||
target="_top"
|
||||
>
|
||||
admin@email.com
|
||||
</a>{" "}
|
||||
</p>
|
||||
</Grid.Column>
|
||||
<Grid.Column floated="right" width={6}>
|
||||
<Header as="h3">Need an account?</Header>
|
||||
<Button
|
||||
size="large"
|
||||
content="Register"
|
||||
onClick={this.handleRegisterClick}
|
||||
fluid
|
||||
/>
|
||||
<Divider style={dividerStyle} horizontal>Or</Divider>
|
||||
<Header as="h3">Login</Header>
|
||||
<Form onSubmit={this._onLoginSubmit}>
|
||||
<Segment padded>
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
icon="user"
|
||||
iconPosition="left"
|
||||
type="text"
|
||||
name="email"
|
||||
onChange={this.handleInputChange}
|
||||
placeholder="E-mail address"
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
icon="lock"
|
||||
iconPosition="left"
|
||||
type="password"
|
||||
name="password"
|
||||
onChange={this.handleInputChange}
|
||||
placeholder="Password"
|
||||
/>
|
||||
</Form.Field>
|
||||
|
||||
<Button type="submit" size="large" value="Login" fluid>
|
||||
Login
|
||||
</Button>
|
||||
{loginMessage}
|
||||
</Segment>
|
||||
</Form>
|
||||
<div style={forgotStyle} >
|
||||
<Link to="/send-reset-password">Forgot Password</Link>
|
||||
</div>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Login;
|
||||
36
account/src/client/User/LoginContainer.js
Normal file
36
account/src/client/User/LoginContainer.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import { connect } from "react-redux"
|
||||
import { push } from 'react-router-redux'
|
||||
import * as userActions from "./user-actions"
|
||||
import Login from "./Login"
|
||||
import queryString from '../query-string';
|
||||
|
||||
|
||||
// Function passed in to `connect` to subscribe to Redux store updates.
|
||||
// Any time it updates, mapStateToProps is called.
|
||||
// The second argument "ownProps" contains props passed to the component
|
||||
const mapStateToProps = (state, props) => {
|
||||
|
||||
let nextPathname = false;
|
||||
|
||||
try {nextPathname = props.location.state.nextPathname}
|
||||
catch(err) {}
|
||||
const uri = queryString.parse(props.location.search);
|
||||
let nextLocation = uri['nextLocation'];
|
||||
|
||||
return {
|
||||
|
||||
user: state.user,
|
||||
nextPathname, // this prop passed in by React Router
|
||||
nextLocation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Connects React component to the redux store
|
||||
// It does not modify the component class passed to it
|
||||
// Instead, it returns a new, connected component class, for you to use.
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(Login)
|
||||
45
account/src/client/User/Profile.js
Normal file
45
account/src/client/User/Profile.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import React, { Component } from "react"
|
||||
import UserForm from "./UserForm";
|
||||
import {
|
||||
Container,
|
||||
Header
|
||||
} from "semantic-ui-react";
|
||||
|
||||
class Profile extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleProfileSubmit = this.handleProfileSubmit.bind(this);
|
||||
}
|
||||
|
||||
state = {
|
||||
requestMessage: ""
|
||||
}
|
||||
|
||||
|
||||
|
||||
handleProfileSubmit(user) {
|
||||
user.userId = this.props.user.userId
|
||||
this.props
|
||||
.updateProfile(user)
|
||||
.then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
// The Key on UserForm get updated when the user is loaded. This forces the Component to be completely redrawn, otherwise the changes in the Prop are not copied to State.
|
||||
return(
|
||||
<Container text>
|
||||
<Header as="h1">Update Profile</Header>
|
||||
<UserForm onSubmit={this.handleProfileSubmit} user={this.props.user} isEditing={true} requestMessage={this.state.requestMessage} isWaiting={this.props.isWaiting} key={this.props.user.userId}/>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Profile
|
||||
15
account/src/client/User/ProfileContainer.js
Normal file
15
account/src/client/User/ProfileContainer.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { connect } from "react-redux"
|
||||
import Profile from "./Profile"
|
||||
import * as userActions from "./user-actions"
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
user: state.user,
|
||||
isWaiting: state.user.isWaiting
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(Profile)
|
||||
71
account/src/client/User/Register.js
Normal file
71
account/src/client/User/Register.js
Normal file
@@ -0,0 +1,71 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
|
||||
import UserForm from "./UserForm";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const requestMessageStyle = {
|
||||
color: "red"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
class Register extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this._onRegisterSubmit = this._onRegisterSubmit.bind(this);
|
||||
}
|
||||
|
||||
state = {
|
||||
requestMessage: ""
|
||||
}
|
||||
|
||||
|
||||
|
||||
_onRegisterSubmit(user) {
|
||||
this.props
|
||||
.manualRegister(user)
|
||||
.then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Container text>
|
||||
<Message icon>
|
||||
<Icon name='trophy'/>
|
||||
<Message.Content>
|
||||
<Message.Header>Welcome!</Message.Header>
|
||||
<p>Creating an account on OpenMHz is the first step in sharing radio system recordings using Trunk Recorder.</p>
|
||||
<p>After creating an account, head over <a href="https://github.com/robotastic/trunk-recorder">here</a> to learn more about Trunk Recorder</p>
|
||||
<p> - Luke</p>
|
||||
</Message.Content>
|
||||
</Message>
|
||||
</Container>
|
||||
<Container text>
|
||||
<Header style={{ paddingTop: '20px' }} as="h1">Register</Header>
|
||||
<UserForm onSubmit={this._onRegisterSubmit} requestMessage={this.state.requestMessage} isWaiting={this.props.isWaiting}/>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Register;
|
||||
14
account/src/client/User/RegisterContainer.js
Normal file
14
account/src/client/User/RegisterContainer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as userActions from "./user-actions"
|
||||
import Register from "./Register"
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
isWaiting: state.user.isWaiting
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(Register)
|
||||
113
account/src/client/User/ResetPassword.js
Normal file
113
account/src/client/User/ResetPassword.js
Normal file
@@ -0,0 +1,113 @@
|
||||
import React, { Component } from "react";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
|
||||
class ResetPassword extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleResetPassword = this.handleResetPassword.bind(this);
|
||||
this.handleInputChange = this.handleInputChange.bind(this);
|
||||
}
|
||||
state = {
|
||||
checkInputMessages: [],
|
||||
password: "",
|
||||
confirmPassword: "",
|
||||
passwordError: false,
|
||||
confirmPasswordError: false,
|
||||
sentReset: false
|
||||
};
|
||||
|
||||
|
||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||
|
||||
handleResetPassword(event) {
|
||||
let error = false;
|
||||
var checkInputMessages = [];
|
||||
|
||||
if (this.state.password === "") {
|
||||
this.setState({ passwordError: true });
|
||||
checkInputMessages.push("Password is required");
|
||||
error = true;
|
||||
} if (this.state.password.length < 7) {
|
||||
this.setState({ passwordError: true });
|
||||
checkInputMessages.push("Password must be 7 charecters or more");
|
||||
error = true;
|
||||
}else {
|
||||
this.setState({ passwordError: false });
|
||||
}
|
||||
|
||||
if (this.state.password !== this.state.confirmPassword) {
|
||||
this.setState({ confirmPasswordError: true });
|
||||
checkInputMessages.push("The passwords did not match");
|
||||
error = true;
|
||||
} else {
|
||||
this.setState({ confirmPasswordError: false });
|
||||
}
|
||||
|
||||
const { match: { params } } = this.props;
|
||||
this.setState({ checkInputMessages: checkInputMessages });
|
||||
if (!error) {
|
||||
this.props.resetPassword(params.userId, params.token, this.state.password).then(resetSent => {
|
||||
this.setState({resetSent: true});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Container text>
|
||||
<Segment>
|
||||
<Form
|
||||
className="raised padding segment"
|
||||
onSubmit={this.handleSubmit}
|
||||
>
|
||||
<Form.Group widths="equal">
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="password"
|
||||
type="password"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.passwordError}
|
||||
label="Password"
|
||||
placeholder="Password..."
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="confirmPassword"
|
||||
type="password"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.confirmPasswordError}
|
||||
label="Confirm Password"
|
||||
placeholder="Confirm Password..."
|
||||
/>
|
||||
</Form.Field>
|
||||
</Form.Group>
|
||||
<Button
|
||||
size="large"
|
||||
content="Reset Password"
|
||||
onClick={this.handleResetPassword}
|
||||
fluid
|
||||
/>
|
||||
</Form>
|
||||
</Segment>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ResetPassword;
|
||||
14
account/src/client/User/ResetPasswordContainer.js
Normal file
14
account/src/client/User/ResetPasswordContainer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { connect } from "react-redux"
|
||||
import ResetPassword from "./ResetPassword"
|
||||
import * as userActions from "./user-actions"
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
user: state.user
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(ResetPassword)
|
||||
115
account/src/client/User/SendResetPassword.js
Normal file
115
account/src/client/User/SendResetPassword.js
Normal file
@@ -0,0 +1,115 @@
|
||||
import React, { Component } from "react";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
const returnStyle = {
|
||||
marginTop: "30px"
|
||||
};
|
||||
|
||||
class SendResetPassword extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSendResetPassword = this.handleSendResetPassword.bind(this);
|
||||
this.handleInputChange = this.handleInputChange.bind(this);
|
||||
}
|
||||
state = {
|
||||
checkInputMessages: "",
|
||||
email: "",
|
||||
emailError: false,
|
||||
sentReset: false
|
||||
};
|
||||
|
||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||
|
||||
handleSendResetPassword(event) {
|
||||
|
||||
|
||||
if (this.state.email === "") {
|
||||
this.setState({ emailError: true, checkInputMessages: "Email is required"});
|
||||
|
||||
} else {
|
||||
this.setState({ emailError: false });
|
||||
|
||||
this.props.sendResetPassword({email: this.state.email}).then(resetMessage => {
|
||||
if (resetMessage) {
|
||||
// report to the user is there was a problem during login
|
||||
|
||||
this.setState({resetSent: false, checkInputMessages: resetMessage, emailError: true});
|
||||
} else {
|
||||
this.setState({resetSent: true});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
render() {
|
||||
var resetMessage = "";
|
||||
if (this.state.checkInputMessages.length) {
|
||||
resetMessage = (
|
||||
<Message compact warning icon>
|
||||
<Icon name="lightning" />
|
||||
<Message.Content>
|
||||
<Message.Header>Problems...</Message.Header>
|
||||
|
||||
{this.state.checkInputMessages}
|
||||
|
||||
</Message.Content>
|
||||
</Message>
|
||||
);
|
||||
}
|
||||
return (
|
||||
|
||||
|
||||
<Grid verticalAlign='middle' centered>
|
||||
<Grid.Row>
|
||||
|
||||
<Grid.Column width="6">
|
||||
{ !this.state.resetSent ? (
|
||||
<div>
|
||||
<h2>Forgot your password?</h2>
|
||||
<Form className="raised padding segment" onSubmit={this.handleSubmit}>
|
||||
Enter the email address for your account.
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="email"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.emailError}
|
||||
label="Email"
|
||||
placeholder="Email..."
|
||||
/>
|
||||
</Form.Field>
|
||||
<Button
|
||||
size="large"
|
||||
content="Reset Password"
|
||||
onClick={this.handleSendResetPassword}
|
||||
fluid
|
||||
/>
|
||||
</Form>
|
||||
{resetMessage}
|
||||
</div>
|
||||
)
|
||||
:( <Segment raised padded='very'>
|
||||
<h2>Reset Link Sent </h2>
|
||||
<div>An email with a link to reset your password was sent to: {this.state.email}</div>
|
||||
<Link to="/" style={returnStyle}><Icon name="left arrow"/>Back to OpenMHz</Link>
|
||||
</Segment>
|
||||
)}
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default SendResetPassword;
|
||||
14
account/src/client/User/SendResetPasswordContainer.js
Normal file
14
account/src/client/User/SendResetPasswordContainer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { connect } from "react-redux"
|
||||
import SendResetPassword from "./SendResetPassword"
|
||||
import * as userActions from "./user-actions"
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
user: state.user
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(SendResetPassword)
|
||||
36
account/src/client/User/SentConfirmEmail.js
Normal file
36
account/src/client/User/SentConfirmEmail.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import React, { Component } from "react"
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
|
||||
class SentConfirmEmail extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
render() {
|
||||
return(
|
||||
<div>
|
||||
<Container text>
|
||||
<Message icon>
|
||||
<Icon name='envelope outline'/>
|
||||
<Message.Content>
|
||||
<Message.Header>Confirmation email sent!</Message.Header>
|
||||
<p>We sent an email to the address you gave us: {this.props.user.email}<br/>
|
||||
Please click on the link in the email to verify the email address.</p>
|
||||
</Message.Content>
|
||||
</Message>
|
||||
</Container>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default SentConfirmEmail
|
||||
14
account/src/client/User/SentConfirmEmailContainer.js
Normal file
14
account/src/client/User/SentConfirmEmailContainer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { connect } from "react-redux"
|
||||
import SentConfirmEmail from "./SentConfirmEmail"
|
||||
import * as userActions from "./user-actions"
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
user: state.user
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(SentConfirmEmail)
|
||||
83
account/src/client/User/Terms.js
Normal file
83
account/src/client/User/Terms.js
Normal file
@@ -0,0 +1,83 @@
|
||||
import React, { Component } from "react";
|
||||
import { Segment,
|
||||
TextArea,
|
||||
Container,
|
||||
Button } from "semantic-ui-react";
|
||||
|
||||
class Terms extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleAccept = this.handleAccept.bind(this);
|
||||
this.handleDecline = this.handleDecline.bind(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
handleAccept() {
|
||||
this.props
|
||||
.acceptTerms(this.props.user.userId)
|
||||
.then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleDecline() {
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
|
||||
<Container text>
|
||||
<Segment attached>
|
||||
The agreement is useful to The Guardian to set the rules and guidelines for visitors, users and customers:
|
||||
|
||||
Registration: inform users that they must agree to a set of rules when they register on your website or mobile app
|
||||
Disable or terminate accounts: inform users that their accounts can be disabled or terminated if abuses happen on your website or mobile app, e.g. spamming, swearing etc.
|
||||
Owner of content: notify users that you, the company, is the owner of the content appearing on your website or mobile app – except in cases where other users can post content (upload, share, create etc.) where the users are the owners of such content
|
||||
Changes to the agreement: users should be informed about upcoming changes to the agreement before the changes are applied.
|
||||
DMCA: The Guardian is also informing owners of copyright content that they can submit a DMCA notice to the website if they found infringing content in their DMCA clause.
|
||||
And more
|
||||
These are only a few examples of what kind of clauses and disclosures you can add in this kind of agreement.
|
||||
|
||||
What is a Terms of Use
|
||||
While a Terms of Use is recommended to have, it’s not mandatory by law as the Privacy Policy agreement is required.
|
||||
|
||||
This agreement serves a single purpose: to inform users of rules that they must agree to. A Privacy Policy must inform users about your privacy practices (what data you collect, why, how, etc.)
|
||||
|
||||
The definition of a Terms of Use agreement is simple:
|
||||
|
||||
Terms of service (also known as terms of use and terms and conditions, commonly abbreviated as ToS or TOS and TOU) are rules which one must agree to abide by in order to use a service.
|
||||
|
||||
Wikipedia
|
||||
Because this agreement simply acts as a contract between you, the company, and the users using or accessing your website or mobile app, the agreement can be named as you’d like:
|
||||
|
||||
Terms of Use (ToU)
|
||||
Terms of Service (ToS)
|
||||
Terms and Conditions (T&C)
|
||||
User Agreement
|
||||
Conditions of Use
|
||||
And so on
|
||||
The “Conditions of Use” of Amazon could be named “Terms of Use”:
|
||||
</Segment>
|
||||
<Button.Group attached="bottom">
|
||||
<Button
|
||||
onClick={this.handleDecline}
|
||||
>Decline</Button>
|
||||
<Button.Or />
|
||||
<Button positive
|
||||
onClick={this.handleAccept}
|
||||
>Accept</Button>
|
||||
</Button.Group>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
export default Terms;
|
||||
14
account/src/client/User/TermsContainer.js
Normal file
14
account/src/client/User/TermsContainer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as userActions from "./user-actions"
|
||||
import Terms from "./Terms"
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
user: state.user
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(Terms)
|
||||
292
account/src/client/User/UserForm.js
Normal file
292
account/src/client/User/UserForm.js
Normal file
@@ -0,0 +1,292 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Dimmer,
|
||||
Loader,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const checkInputMessagestyle = {
|
||||
color: "red"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
class UserForm extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleInputChange = this.handleInputChange.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.checkInputs = this.checkInputs.bind(this);
|
||||
this.render = this.render.bind(this)
|
||||
|
||||
this.state = {
|
||||
checkInputMessages: [],
|
||||
registerMessages: "",
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
screenName: "",
|
||||
email: "",
|
||||
location: "",
|
||||
password: "",
|
||||
confirmPassword: "",
|
||||
firstNameError: false,
|
||||
lastNameError: false,
|
||||
screenNameError: false,
|
||||
emailError: false,
|
||||
locationError: false,
|
||||
passwordError: false,
|
||||
confirmPasswordError: false,
|
||||
isEditing: this.props.isEditing
|
||||
};
|
||||
if (this.props.isEditing) {
|
||||
this.state.firstName = this.props.user.firstName;
|
||||
this.state.lastName = this.props.user.lastName;
|
||||
this.state.screenName = this.props.user.screenName;
|
||||
this.state.email = this.props.user.email;
|
||||
this.state.location = this.props.user.location;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
checkInputs() {
|
||||
let error = false;
|
||||
var checkInputMessages= [];
|
||||
|
||||
if (this.state.firstName === "") {
|
||||
this.setState({ firstNameError: true });
|
||||
checkInputMessages.push("First Name is required");
|
||||
error = true;
|
||||
} else {
|
||||
this.setState({ firstNameError: false });
|
||||
}
|
||||
|
||||
if (this.state.lastName === "") {
|
||||
this.setState({ lastNameError: true });
|
||||
checkInputMessages.push("Last Name is required");
|
||||
error = true;
|
||||
} else {
|
||||
this.setState({ lastNameError: false });
|
||||
}
|
||||
|
||||
if (this.state.email === "") {
|
||||
this.setState({ emailError: true });
|
||||
checkInputMessages.push("Email is required");
|
||||
error = true;
|
||||
} else {
|
||||
this.setState({ emailError: false });
|
||||
}
|
||||
|
||||
if (this.state.location === "") {
|
||||
this.setState({ locationError: true });
|
||||
checkInputMessages.push("Location is required");
|
||||
error = true;
|
||||
} else {
|
||||
this.setState({ locationError: false });
|
||||
}
|
||||
|
||||
if (this.state.screenName === "") {
|
||||
this.setState({ screenNameError: true });
|
||||
checkInputMessages.push("Screen Name is required");
|
||||
error = true;
|
||||
} else {
|
||||
this.setState({ screenNameError: false });
|
||||
}
|
||||
|
||||
if (this.props.isEditing) {
|
||||
this.setState({ checkInputMessages: checkInputMessages });
|
||||
return error;
|
||||
}
|
||||
|
||||
if (this.state.password === "") {
|
||||
this.setState({ passwordError: true });
|
||||
checkInputMessages.push("Password is required");
|
||||
error = true;
|
||||
} if (this.state.password.length < 7) {
|
||||
this.setState({ passwordError: true });
|
||||
checkInputMessages.push("Password must be 7 charecters or more");
|
||||
error = true;
|
||||
}else {
|
||||
this.setState({ passwordError: false });
|
||||
}
|
||||
|
||||
if (this.state.password !== this.state.confirmPassword) {
|
||||
this.setState({ confirmPasswordError: true });
|
||||
checkInputMessages.push("The passwords did not match");
|
||||
error = true;
|
||||
} else {
|
||||
this.setState({ confirmPasswordError: false });
|
||||
}
|
||||
|
||||
this.setState({ checkInputMessages: checkInputMessages });
|
||||
return error;
|
||||
}
|
||||
|
||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||
|
||||
handleSubmit(event) {
|
||||
event.preventDefault();
|
||||
let inputError = this.checkInputs();
|
||||
|
||||
if (!inputError) {
|
||||
const user = (({ firstName, lastName, screenName, location, email, password }) => ({ firstName, lastName, screenName, location, email, password }))(this.state);
|
||||
this.props.onSubmit(user);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var registerMessage = "";
|
||||
var floatStyle = {
|
||||
overflow: 'auto'
|
||||
}
|
||||
var dimmerProps = { };
|
||||
if (this.props.isWaiting) {
|
||||
dimmerProps["active"] = true;
|
||||
}
|
||||
const { name, email } = this.state;
|
||||
const { isEditing} = this.props;
|
||||
if (this.state.checkInputMessages.length || this.props.requestMessage.length) {
|
||||
var counter = 0;
|
||||
registerMessage = (
|
||||
<Message compact warning icon>
|
||||
<Icon name="lightning" />
|
||||
<Message.Content>
|
||||
<Message.Header>Problems...</Message.Header>
|
||||
<ul>
|
||||
{this.state.checkInputMessages.map(function(listValue) {
|
||||
return <li key={`ListItem_${counter++}`}>{listValue}</li>;
|
||||
})}
|
||||
{ this.props.requestMessage.length>0 &&
|
||||
<li key="req-mess">{this.props.requestMessage}</li>
|
||||
}
|
||||
</ul>
|
||||
</Message.Content>
|
||||
</Message>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<Form
|
||||
className="raised padding segment"
|
||||
onSubmit={this.handleSubmit}
|
||||
>
|
||||
<Dimmer {...dimmerProps}>
|
||||
<Loader indeterminate>Updating Profile</Loader>
|
||||
</Dimmer>
|
||||
|
||||
<Form.Group widths="equal">
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="firstName"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.firstNameError}
|
||||
defaultValue={this.state.firstName}
|
||||
label="First name"
|
||||
placeholder="First Name..."
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="lastName"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.lastNameError}
|
||||
defaultValue={this.state.lastName}
|
||||
label="Last name"
|
||||
placeholder="Last Name..."
|
||||
/>
|
||||
</Form.Field>
|
||||
</Form.Group>
|
||||
<Form.Group widths="equal">
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="email"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.emailError}
|
||||
defaultValue={this.state.email}
|
||||
disabled={isEditing}
|
||||
label="Email"
|
||||
placeholder="Email..."
|
||||
/>
|
||||
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="screenName"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.screenNameError}
|
||||
defaultValue={this.state.screenName}
|
||||
label="Screen Name"
|
||||
placeholder="Screen Name..."
|
||||
/>
|
||||
<p style={{ fontStyle: "italic" }}>
|
||||
Shown on OpenMHz for each of your systems
|
||||
</p>
|
||||
</Form.Field>
|
||||
</Form.Group>
|
||||
<Form.Group widths="equal">
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="location"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.locationError}
|
||||
defaultValue={this.state.location}
|
||||
label="General Location"
|
||||
placeholder="City, State..."
|
||||
/>
|
||||
</Form.Field>
|
||||
</Form.Group>
|
||||
{isEditing!=true && (
|
||||
<Form.Group widths="equal">
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="password"
|
||||
type="password"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.passwordError}
|
||||
disabled={isEditing}
|
||||
label="Password"
|
||||
placeholder="Password..."
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Form.Input
|
||||
type="text"
|
||||
name="confirmPassword"
|
||||
type="password"
|
||||
onChange={this.handleInputChange}
|
||||
error={this.state.confirmPasswordError}
|
||||
disabled={isEditing}
|
||||
label="Confirm Password"
|
||||
placeholder="Confirm Password..."
|
||||
/>
|
||||
</Form.Field>
|
||||
</Form.Group>
|
||||
)}
|
||||
<div style={floatStyle}>
|
||||
<Button type="submit" size="large" floated="right" value="Login" color='blue'>
|
||||
{isEditing!=true? 'Register' : 'Update' }
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
{registerMessage}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default UserForm;
|
||||
53
account/src/client/User/WaitConfirmEmail.js
Normal file
53
account/src/client/User/WaitConfirmEmail.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import React, { Component } from "react"
|
||||
import { Link } from 'react-router-dom'
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Button,
|
||||
Message,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
class WaitConfirmEmail extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSendConfirmEmail = this.handleSendConfirmEmail.bind(this);
|
||||
|
||||
}
|
||||
handleSendConfirmEmail(event) {
|
||||
this.props.sendConfirmEmail(this.props.user.userId).then(loginMessage => {
|
||||
if (loginMessage) {
|
||||
// report to the user is there was a problem during login
|
||||
this.setState({
|
||||
loginMessage
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
return(
|
||||
<Container text>
|
||||
<Message icon>
|
||||
<Icon name='envelope outline'/>
|
||||
<Message.Content>
|
||||
<Message.Header>Confirm your email address</Message.Header>
|
||||
<p>We sent an email to the address you gave us: {this.props.user.email}<br/>
|
||||
Please click on the link in the email to verify the email address.</p>
|
||||
<Header as='h3'>Didn't get an email?</Header>
|
||||
<p>So, you have waited a bit and haven't gotten anything?</p>
|
||||
<p>...and you checked your spam folder?</p>
|
||||
<p>Well, click below.</p>
|
||||
<Button
|
||||
size="large"
|
||||
content="Resend Email Confirmation"
|
||||
onClick={this.handleSendConfirmEmail}
|
||||
/>
|
||||
</Message.Content>
|
||||
</Message>
|
||||
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default WaitConfirmEmail
|
||||
14
account/src/client/User/WaitConfirmEmailContainer.js
Normal file
14
account/src/client/User/WaitConfirmEmailContainer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { connect } from "react-redux"
|
||||
import WaitConfirmEmail from "./WaitConfirmEmail"
|
||||
import * as userActions from "./user-actions"
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
user: state.user
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(WaitConfirmEmail)
|
||||
391
account/src/client/User/user-actions.js
Normal file
391
account/src/client/User/user-actions.js
Normal file
@@ -0,0 +1,391 @@
|
||||
import axios from "axios";
|
||||
//import { browserHistory } from "react-router"
|
||||
import * as types from "./user-constants";
|
||||
import { push } from 'connected-react-router';
|
||||
|
||||
// "Log In" action creators
|
||||
function beginLogin() {
|
||||
return { type: types.MANUAL_LOGIN_USER };
|
||||
}
|
||||
|
||||
function loginSuccess(data) {
|
||||
return {
|
||||
type: types.LOGIN_SUCCESS_USER,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
function loginEmailError(data) {
|
||||
return {
|
||||
type: types.LOGIN_EMAIL_ERROR_USER,
|
||||
data
|
||||
};
|
||||
}
|
||||
function loginError() {
|
||||
return { type: types.LOGIN_ERROR_USER };
|
||||
}
|
||||
|
||||
// "update profile" action creators
|
||||
function beginUpdateProfile() {
|
||||
return { type: types.UPDATE_PROFILE_USER };
|
||||
}
|
||||
|
||||
function updateProfileSuccess(data) {
|
||||
return { type: types.UPDATE_PROFILE_SUCCESS_USER, data };
|
||||
}
|
||||
|
||||
function updateProfileError() {
|
||||
return { type: types.UPDATE_PROFILE_ERROR_USER };
|
||||
}
|
||||
|
||||
// "Reset Password" action creators
|
||||
function beginResetPassword() {
|
||||
return { type: types.RESET_PASSWORD_USER };
|
||||
}
|
||||
|
||||
function resetPasswordSuccess() {
|
||||
return { type: types.RESET_PASSWORD_SUCCESS_USER };
|
||||
}
|
||||
|
||||
function resetPasswordError() {
|
||||
return { type: types.RESET_PASSWORD_ERROR_USER };
|
||||
}
|
||||
|
||||
// "Send Reset Password" action creators
|
||||
function beginSendResetPassword() {
|
||||
return { type: types.SEND_RESET_PASSWORD_USER };
|
||||
}
|
||||
|
||||
function sendResetPasswordSuccess() {
|
||||
return { type: types.SEND_RESET_PASSWORD_SUCCESS_USER };
|
||||
}
|
||||
|
||||
function sendResetPasswordError() {
|
||||
return { type: types.SEND_RESET_PASSWORD_ERROR_USER };
|
||||
}
|
||||
|
||||
// "Confirm" action creators
|
||||
function beginConfirm() {
|
||||
return { type: types.CONFIRM_USER };
|
||||
}
|
||||
|
||||
function confirmSuccess() {
|
||||
return { type: types.CONFIRM_SUCCESS_USER };
|
||||
}
|
||||
|
||||
function confirmError() {
|
||||
return { type: types.CONFIRM_ERROR_USER };
|
||||
}
|
||||
|
||||
// "Send Confirm" action creators
|
||||
function beginSendConfirm() {
|
||||
return { type: types.SEND_CONFIRM_USER };
|
||||
}
|
||||
|
||||
function sendConfirmSuccess() {
|
||||
return { type: types.SEND_CONFIRM_SUCCESS_USER };
|
||||
}
|
||||
|
||||
function sendConfirmError() {
|
||||
return { type: types.SEND_CONFIRM_ERROR_USER };
|
||||
}
|
||||
|
||||
// "Log Out" action creators
|
||||
function beginLogout() {
|
||||
return { type: types.LOGOUT_USER };
|
||||
}
|
||||
|
||||
function logoutSuccess() {
|
||||
return { type: types.LOGOUT_SUCCESS_USER };
|
||||
}
|
||||
|
||||
function logoutError() {
|
||||
return { type: types.LOGOUT_ERROR_USER };
|
||||
}
|
||||
|
||||
// "Register" action creators
|
||||
function beginRegister() {
|
||||
return { type: types.REGISTER_USER };
|
||||
}
|
||||
|
||||
function registerSuccess(data) {
|
||||
return {
|
||||
type: types.REGISTER_SUCCESS_USER,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
function registerError() {
|
||||
return { type: types.REGISTER_ERROR_USER };
|
||||
}
|
||||
|
||||
// "Terms" action creators
|
||||
function beginAgreeTerms() {
|
||||
return { type: types.AGREE_TERMS_USER };
|
||||
}
|
||||
|
||||
function agreeTermsSuccess() {
|
||||
return { type: types.AGREE_TERMS_SUCCESS_USER };
|
||||
}
|
||||
|
||||
function agreeTermsError() {
|
||||
return { type: types.AGREE_TERMS_ERROR_USER };
|
||||
}
|
||||
|
||||
function makeUserRequest(method, data, api = "/login") {
|
||||
// returns a Promise
|
||||
return axios({
|
||||
method: method,
|
||||
url: api,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
|
||||
export function changeUrl(url) {
|
||||
return dispatch => {
|
||||
dispatch(push(url));
|
||||
};
|
||||
}
|
||||
|
||||
// Example of an Async Action Creator
|
||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
||||
export function manualLogin(
|
||||
data,
|
||||
success // path to redirect to upon successful log in
|
||||
) {
|
||||
return dispatch => {
|
||||
dispatch(beginLogin());
|
||||
|
||||
return makeUserRequest("post", data, "/login", {withCredentials: true})
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const user = response.data.user
|
||||
dispatch(loginSuccess(user));
|
||||
// use browserHistory singleton to control navigation. Will generate a
|
||||
// state change for time-traveling as we are using the react-router-redux package
|
||||
//browserHistory.push(successPath)
|
||||
if (success && (success.type=="path")) {
|
||||
dispatch(push(success.nextPathname));
|
||||
} else if (success && (success.type=="location")) {
|
||||
window.location=success.nextLocation;
|
||||
} else {
|
||||
dispatch(push("/"));
|
||||
}
|
||||
} else {
|
||||
let loginMessage = response.data.message;
|
||||
console.log("loginMessage");
|
||||
if (loginMessage == "unconfirmed email") {
|
||||
data.userId = response.data.userId;
|
||||
dispatch(loginEmailError(data));
|
||||
dispatch(push("/wait-confirm-email"));
|
||||
} else {
|
||||
dispatch(loginError());
|
||||
}
|
||||
return loginMessage;
|
||||
}
|
||||
})
|
||||
.catch(function(response) {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// Example of an Async Action Creator
|
||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
||||
export function isAuthenticated() {
|
||||
return dispatch => {
|
||||
dispatch(beginAuthenticated());
|
||||
|
||||
return axios
|
||||
.get("/authenticated")
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(loginSuccess());
|
||||
return true;
|
||||
} else {
|
||||
dispatch(loginError());
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened during logout that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Example of an Async Action Creator
|
||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
||||
export function manualLogout() {
|
||||
return dispatch => {
|
||||
dispatch(beginLogout());
|
||||
|
||||
return axios
|
||||
.get("/logout")
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(logoutSuccess());
|
||||
// use browserHistory singleton to control navigation. Will generate a
|
||||
// state change for time-traveling as we are using the react-router-redux package
|
||||
//browserHistory.push("/") // logout to home page
|
||||
dispatch(push("/"));
|
||||
} else {
|
||||
dispatch(logoutError());
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened during logout that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function confirmEmail(userId, token) {
|
||||
return dispatch => {
|
||||
dispatch(beginConfirm());
|
||||
return makeUserRequest("post", {}, "/users/" + userId + "/confirm/" + token).then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(confirmSuccess());
|
||||
let requestMessage = {success: true, message: response.data.message};
|
||||
return requestMessage;
|
||||
} else {
|
||||
dispatch(confirmError());
|
||||
let requestMessage = {success: false, message: response.data.message};
|
||||
return requestMessage;
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function resetPassword(userId, token,password) {
|
||||
return dispatch => {
|
||||
dispatch(beginResetPassword());
|
||||
return makeUserRequest("post", {password: password}, "/users/" + userId + "/reset-password/" + token).then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(resetPasswordSuccess());
|
||||
dispatch(push("/login"));
|
||||
} else {
|
||||
dispatch(resetPasswordError());
|
||||
let requestMessage = response.data.message;
|
||||
return requestMessage;
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function sendResetPassword(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginSendResetPassword());
|
||||
return makeUserRequest("post", data, "/api/send-reset-password").then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(sendResetPasswordSuccess());
|
||||
} else {
|
||||
dispatch(sendResetPasswordError());
|
||||
return response.data.message;
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function sendConfirmEmail(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginSendConfirm());
|
||||
return makeUserRequest("post", data, "/users/" + data + "/send-confirm").then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(sendConfirmSuccess());
|
||||
dispatch(push("/sent-confirm-email"));
|
||||
} else {
|
||||
dispatch(sendConfirmError());
|
||||
let requestMessage = response.data.Message;
|
||||
return requestMessage;
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function acceptTerms(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginAgreeTerms());
|
||||
return makeUserRequest("post", data, "/users/" + data + "/terms").then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(agreeTermsSuccess());
|
||||
} else {
|
||||
dispatch(agreeTermsError());
|
||||
let requestMessage = response.data.Message;
|
||||
return requestMessage;
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function updateProfile(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginUpdateProfile());
|
||||
|
||||
return makeUserRequest("post", data, "/users/" + data.userId)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const user = response.data.user
|
||||
dispatch(updateProfileSuccess(user));
|
||||
dispatch(push("/"));
|
||||
} else {
|
||||
dispatch(updateProfileError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function manualRegister(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginRegister());
|
||||
|
||||
return makeUserRequest("post", data, "/register")
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
data.userId = response.data.userId;
|
||||
dispatch(registerSuccess(data));
|
||||
dispatch(push("/sent-confirm-email"));
|
||||
} else {
|
||||
dispatch(registerError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
31
account/src/client/User/user-constants.js
Normal file
31
account/src/client/User/user-constants.js
Normal file
@@ -0,0 +1,31 @@
|
||||
export const MANUAL_LOGIN_USER = "MANUAL_LOGIN_USER"
|
||||
export const LOGIN_SUCCESS_USER = "LOGIN_SUCCESS_USER"
|
||||
export const LOGIN_EMAIL_ERROR_USER = "LOGIN_EMAIL_ERROR_USER"
|
||||
export const LOGIN_ERROR_USER = "LOGIN_ERROR_USER"
|
||||
export const CONFIRM_USER = "CONFIRM_USER"
|
||||
export const CONFIRM_ERROR_USER = "CONFIRM_ERROR_USER"
|
||||
export const CONFIRM_SUCCESS_USER = "CONFIRM_SUCCESS_USER"
|
||||
export const RESET_PASSWORD_USER = "RESET_PASSWORD_USER"
|
||||
export const RESET_PASSWORD_ERROR_USER = "RESET_PASSWORD_ERROR_USER"
|
||||
export const RESET_PASSWORD_SUCCESS_USER = "RESET_PASSWORD_SUCCESS_USER"
|
||||
export const SEND_RESET_PASSWORD_USER = "SEND_RESET_PASSWORD_USER"
|
||||
export const SEND_RESET_PASSWORD_ERROR_USER = "SEND_RESET_PASSWORD_ERROR_USER"
|
||||
export const SEND_RESET_PASSWORD_SUCCESS_USER = "SEND_RESET_PASSWORD_SUCCESS_USER"
|
||||
export const SEND_CONFIRM_USER = "SEND_CONFIRM_USER"
|
||||
export const SEND_CONFIRM_ERROR_USER = "SEND_CONFIRM_ERROR_USER"
|
||||
export const SEND_CONFIRM_SUCCESS_USER = "SEND_CONFIRM_SUCCESS_USER"
|
||||
export const SIGNUP_USER = "SIGNUP_USER"
|
||||
export const SIGNUP_SUCCESS_USER = "SIGNUP_SUCCESS_USER"
|
||||
export const SIGNUP_ERROR_USER = "SIGNUP_ERROR_USER"
|
||||
export const LOGOUT_USER = "LOGOUT_USER"
|
||||
export const LOGOUT_SUCCESS_USER = "LOGOUT_SUCCESS_USER"
|
||||
export const LOGOUT_ERROR_USER = "LOGOUT_ERROR_USER"
|
||||
export const UPDATE_PROFILE_USER = "UPDATE_PROFILE_USER"
|
||||
export const UPDATE_PROFILE_SUCCESS_USER = "UPDATE_PROFILE_SUCCESS_USER"
|
||||
export const UPDATE_PROFILE_ERROR_USER = "UPDATE_PROFILE_ERROR_USER"
|
||||
export const REGISTER_USER = "REGISTER_USER"
|
||||
export const REGISTER_SUCCESS_USER = "REGISTER_SUCCESS_USER"
|
||||
export const REGISTER_ERROR_USER = "REGISTER_ERROR_USER"
|
||||
export const AGREE_TERMS_USER = "AGREE_TERMS_USER"
|
||||
export const AGREE_TERMS_SUCCESS_USER = "AGREE_TERMS_SUCCESS_USER"
|
||||
export const AGREE_TERMS_ERROR_USER = "AGREE_TERMS_ERROR_USER"
|
||||
139
account/src/client/User/user-reducer.js
Normal file
139
account/src/client/User/user-reducer.js
Normal file
@@ -0,0 +1,139 @@
|
||||
import {
|
||||
MANUAL_LOGIN_USER,
|
||||
LOGIN_SUCCESS_USER,
|
||||
LOGIN_ERROR_USER,
|
||||
LOGIN_EMAIL_ERROR_USER,
|
||||
SEND_RESET_PASSWORD_USER,
|
||||
SEND_RESET_PASSWORD_ERROR_USER,
|
||||
SEND_RESET_PASSWORD_SUCCESS_USER,
|
||||
RESET_PASSWORD_USER,
|
||||
RESET_PASSWORD_ERROR_USER,
|
||||
RESET_PASSWORD_SUCCESS_USER,
|
||||
CONFIRM_USER,
|
||||
CONFIRM_ERROR_USER,
|
||||
CONFIRM_SUCCESS_USER,
|
||||
UPDATE_PROFILE_USER,
|
||||
UPDATE_PROFILE_ERROR_USER,
|
||||
UPDATE_PROFILE_SUCCESS_USER,
|
||||
SEND_CONFIRM_USER,
|
||||
SEND_CONFIRM_ERROR_USER,
|
||||
SEND_CONFIRM_SUCCESS_USER,
|
||||
LOGOUT_USER,
|
||||
LOGOUT_SUCCESS_USER,
|
||||
LOGOUT_ERROR_USER,
|
||||
REGISTER_USER,
|
||||
REGISTER_SUCCESS_USER,
|
||||
REGISTER_ERROR_USER
|
||||
} from "./user-constants";
|
||||
|
||||
const user = (
|
||||
state = {
|
||||
isWaiting: false,
|
||||
authenticated: false,
|
||||
userId: ""
|
||||
},
|
||||
action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
case MANUAL_LOGIN_USER:
|
||||
return Object.assign({}, state, { isWaiting: true });
|
||||
case LOGIN_SUCCESS_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: true,
|
||||
...action.data
|
||||
});
|
||||
case LOGIN_EMAIL_ERROR_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false,
|
||||
userId: action.data.userId
|
||||
});
|
||||
case LOGIN_ERROR_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false
|
||||
});
|
||||
|
||||
case UPDATE_PROFILE_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: true
|
||||
});
|
||||
|
||||
case UPDATE_PROFILE_SUCCESS_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
...action.data
|
||||
});
|
||||
|
||||
case UPDATE_PROFILE_ERROR_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false
|
||||
});
|
||||
|
||||
case CONFIRM_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: true,
|
||||
authenticated: false
|
||||
});
|
||||
case CONFIRM_SUCCESS_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false
|
||||
});
|
||||
case CONFIRM_ERROR_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
case RESET_PASSWORD_USER:
|
||||
case SEND_RESET_PASSWORD_USER:
|
||||
case SEND_CONFIRM_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: true,
|
||||
authenticated: false
|
||||
});
|
||||
|
||||
case RESET_PASSWORD_ERROR_USER:
|
||||
case RESET_PASSWORD_SUCCESS_USER:
|
||||
case SEND_RESET_PASSWORD_ERROR_USER:
|
||||
case SEND_RESET_PASSWORD_SUCCESS_USER:
|
||||
case SEND_CONFIRM_ERROR_USER:
|
||||
case SEND_CONFIRM_SUCCESS_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false
|
||||
});
|
||||
|
||||
|
||||
case LOGOUT_USER:
|
||||
return Object.assign({}, state, { isWaiting: true });
|
||||
case LOGOUT_SUCCESS_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: false,
|
||||
email: "",
|
||||
userId: ""
|
||||
});
|
||||
case LOGOUT_ERROR_USER:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
authenticated: true
|
||||
});
|
||||
case REGISTER_USER:
|
||||
return Object.assign({}, state, { isWaiting: true });
|
||||
case REGISTER_SUCCESS_USER:
|
||||
return Object.assign({}, state, { isWaiting: false,
|
||||
userId: action.data.userId });
|
||||
case REGISTER_ERROR_USER:
|
||||
return Object.assign({}, state, { isWaiting: false });
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default user;
|
||||
95
account/src/client/client.js
Normal file
95
account/src/client/client.js
Normal file
@@ -0,0 +1,95 @@
|
||||
import React from "react"
|
||||
import { render } from "react-dom"
|
||||
import { Provider } from "react-redux"
|
||||
import { Switch, Route} from 'react-router-dom'
|
||||
import { createStore, combineReducers, applyMiddleware } from 'redux'
|
||||
import thunk from "redux-thunk"
|
||||
import {createLogger} from "redux-logger"
|
||||
//import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux'
|
||||
import { routerMiddleware } from 'connected-react-router'
|
||||
import { ConnectedRouter } from 'connected-react-router'
|
||||
import isNode from "detect-node"
|
||||
//import rootReducer from "./reducers"
|
||||
import createRootReducer from './reducers'
|
||||
import { createHashHistory } from 'history'
|
||||
import createHistory from 'history/createBrowserHistory'
|
||||
|
||||
import App from "./components/container/App"
|
||||
import LoginContainer from "./User/LoginContainer"
|
||||
import RegisterContainer from "./User/RegisterContainer"
|
||||
import ProfileContainer from "./User/ProfileContainer"
|
||||
import BillingContainer from "./Billing/BillingContainer"
|
||||
import Default from "./components/pure/Default"
|
||||
import NavigationContainer from "./components/container/NavigationContainer"
|
||||
import ConfirmEmailContainer from "./User/ConfirmEmailContainer"
|
||||
import WaitConfirmEmailContainer from "./User/WaitConfirmEmailContainer"
|
||||
import SentConfirmEmailContainer from "./User/SentConfirmEmailContainer"
|
||||
import SendResetPasswordContainer from "./User/SendResetPasswordContainer"
|
||||
import ResetPasswordContainer from "./User/ResetPasswordContainer"
|
||||
import Restricted from "./components/container/Restricted"
|
||||
import TermsContainer from "./User/TermsContainer"
|
||||
import UpdatePlans from "./Plan/UpdatePlansContainer"
|
||||
|
||||
// Create a history of your choosing (we're using a browser history in this case)
|
||||
const history = createHistory()
|
||||
|
||||
// Build the middleware for intercepting and dispatching navigation actions
|
||||
const historyMiddleware = routerMiddleware(history)
|
||||
|
||||
let middleware = [
|
||||
thunk,
|
||||
historyMiddleware
|
||||
|
||||
]
|
||||
|
||||
// only add Redux-Logger on the client-side because it causes problems server-side.
|
||||
if (!isNode) {
|
||||
middleware.push(createLogger())
|
||||
}
|
||||
|
||||
|
||||
// Add the reducer to your store on the `router` key
|
||||
// Also apply our middleware for navigating
|
||||
const store = createStore(
|
||||
createRootReducer(history),
|
||||
applyMiddleware(thunk,
|
||||
historyMiddleware, createLogger())
|
||||
)
|
||||
|
||||
/*
|
||||
<Route path="/system/:shortName" component={Restricted(SystemContainer, store)} />
|
||||
<Route path="/update-system/:shortName" component={Restricted(EditSystemContainer, store)} />
|
||||
<Route path="/create-system" component={Restricted(CreateSystemContainer, store)} />
|
||||
<Route path="/list-systems" component={Restricted(ListSystemsContainer, store)} />
|
||||
|
||||
<Route path="/system/:shortName" component={Restricted(SystemContainer, store)} />
|
||||
<Route path="/update-system/:shortName" component={EditSystemContainer} />
|
||||
<Route path="/create-system" component={CreateSystemContainer} />
|
||||
<Route path="/list-systems" component={ListSystemsContainer} />
|
||||
*/
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<ConnectedRouter history={history}>
|
||||
<div>
|
||||
<App>
|
||||
<Switch>
|
||||
|
||||
<Route exact path="/" component={Restricted(ProfileContainer, store)} />
|
||||
<Route path="/login" component={LoginContainer} />
|
||||
<Route path="/register" component={RegisterContainer} />
|
||||
<Route path="/wait-confirm-email" component={WaitConfirmEmailContainer} />
|
||||
<Route path="/sent-confirm-email" component={SentConfirmEmailContainer} />
|
||||
<Route path="/send-reset-password" component={SendResetPasswordContainer} />
|
||||
<Route path="/reset-password/:userId/:token" component={ResetPasswordContainer} />
|
||||
<Route path="/confirm-email/:userId/:token" component={ConfirmEmailContainer} />
|
||||
<Route path="/terms" component={Restricted(TermsContainer, store)} />
|
||||
|
||||
<Route path="/billing" component={Restricted(BillingContainer, store)} />
|
||||
<Route path="/profile" component={Restricted(ProfileContainer, store)} />
|
||||
<Route path="/update-plans" component={Restricted(UpdatePlans, store)} />
|
||||
</Switch>
|
||||
</App>
|
||||
</div>
|
||||
</ConnectedRouter>
|
||||
</Provider>
|
||||
, document.getElementById("app"))
|
||||
19
account/src/client/components/container/App.js
Normal file
19
account/src/client/components/container/App.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import React, { Component } from "react"
|
||||
import NavigationContainer from "./NavigationContainer"
|
||||
|
||||
class App extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
return(
|
||||
<div>
|
||||
<NavigationContainer />
|
||||
{this.props.children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default App
|
||||
@@ -0,0 +1,21 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as userActions from "../../User/user-actions"
|
||||
import Navigation from "../pure/Navigation"
|
||||
|
||||
|
||||
// Function passed in to `connect` to subscribe to Redux store updates.
|
||||
// Any time it updates, mapStateToProps is called.
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
user: state.user
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Connects React component to the redux store
|
||||
// It does not modify the component class passed to it
|
||||
// Instead, it returns a new, connected component class, for you to use.
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
userActions
|
||||
)(Navigation)
|
||||
55
account/src/client/components/container/Restricted.js
Normal file
55
account/src/client/components/container/Restricted.js
Normal file
@@ -0,0 +1,55 @@
|
||||
// in src/restricted.js
|
||||
import React, { Component } from 'react';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import * as userActions from "../../User/user-actions"
|
||||
import * as types from "../../User/user-constants";
|
||||
import axios from "axios";
|
||||
/**
|
||||
* Higher-order component (HOC) to wrap restricted pages
|
||||
*/
|
||||
export default (BaseComponent, store) => {
|
||||
class Restricted extends Component {
|
||||
componentWillMount() {
|
||||
this.checkAuthentication(this.props);
|
||||
}
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.location !== this.props.location) {
|
||||
this.checkAuthentication(nextProps);
|
||||
}
|
||||
}
|
||||
|
||||
checkAuthentication(params) {
|
||||
const { history } = params;
|
||||
const authenticated = store.getState().user.authenticated;
|
||||
if (!authenticated) {
|
||||
axios
|
||||
.get("/authenticated")
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const user = response.data.user
|
||||
store.dispatch({
|
||||
type: types.LOGIN_SUCCESS_USER,
|
||||
data: user
|
||||
});
|
||||
} else {
|
||||
history.replace({ pathname: '/login',
|
||||
state: { nextPathname: params.location.pathname } });
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened during logout that triggered an Error
|
||||
history.replace({ pathname: '/login',
|
||||
state: { nextPathname: params.location.pathname } });
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
render() {
|
||||
return <BaseComponent {...this.props} />;
|
||||
}
|
||||
}
|
||||
return withRouter(Restricted);
|
||||
}
|
||||
31
account/src/client/components/pure/Default.js
Normal file
31
account/src/client/components/pure/Default.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import React, { Component } from "react"
|
||||
|
||||
class Default extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
return(
|
||||
<div>
|
||||
<h2>React-Passport-Redux-Example</h2>
|
||||
<p>Demonstration of PassportJS authentication in React w/ Redux. Use the links above to register a new user and login/logout. You will only be able to view the MyProfile page when you are logged in. Logging in will redirect you to MyProfile if you had clicked that link beforehand.</p>
|
||||
<p>I'll be doing my best to document code with useful comments so look for more detail there. Note: you should be able to implement the authentication functionality using less packages. I was working on another project before deciding to make this example repo so some bloat may have travelled over from that.</p>
|
||||
<p>In full, this repo demonstrates:</p>
|
||||
<ul>
|
||||
<li><strong>React</strong> for the view layer </li>
|
||||
<li><strong>PassportJS</strong> for authentication (using a Local Strategy)</li>
|
||||
<li><strong>Redux</strong> to handle our state</li>
|
||||
<li><strong>React Router</strong> for routing client-side</li>
|
||||
<li><strong>Express</strong> for handling server requests (REST and page requests)</li>
|
||||
<li><strong>MongoDB</strong> for our database, with <strong>Mongoose</strong> handling our schema</li>
|
||||
<li><strong>Webpack</strong> to bundle our client-side code</li>
|
||||
<li>Hot reloading using <strong>webpack-dev-middleware</strong> and <strong>webpack-hot-middleware</strong></li>
|
||||
</ul>
|
||||
<p>Shoutout to GitHub member <b>choonkending</b> whose <a href="https://github.com/choonkending/react-webpack-node" target="_blank">repo</a> was a big help. Pull requests and comments / issue reports are most welcome!</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Default
|
||||
31
account/src/client/components/pure/Message.js
Normal file
31
account/src/client/components/pure/Message.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import React, { Component } from "react";
|
||||
import { Modal, Icon, Button, Header } from "semantic-ui-react";
|
||||
|
||||
class Message extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
_logout = event => {
|
||||
event.preventDefault();
|
||||
this.props.manualLogout();
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal open={this.props.open} onClose={this.props.onClose} basic size="small">
|
||||
<Header icon="info" content={this.props.title} />
|
||||
<Modal.Content>
|
||||
<p>{this.props.message}</p>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button color='green' onClick={this.props.onClose} inverted>
|
||||
<Icon name='checkmark' /> Got it
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Message;
|
||||
57
account/src/client/components/pure/Navigation.js
Normal file
57
account/src/client/components/pure/Navigation.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import React, { Component } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Menu, Dropdown } from "semantic-ui-react";
|
||||
|
||||
const navStyle = {
|
||||
marginBottom: "30px"
|
||||
};
|
||||
const blankStyle = {
|
||||
marginBottom: "50px"
|
||||
};
|
||||
class Navigation extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this._logout = this._logout.bind(this);
|
||||
}
|
||||
|
||||
_logout = event => {
|
||||
event.preventDefault();
|
||||
this.props.manualLogout();
|
||||
};
|
||||
|
||||
render() {
|
||||
var profileLink = account_server + "/profile";
|
||||
var billingLink = account_server + "/billing";
|
||||
return (
|
||||
<div>
|
||||
{this.props.user.authenticated ? (
|
||||
<Menu style={navStyle}>
|
||||
<Menu.Item name="systems" header>
|
||||
OpenMHz
|
||||
</Menu.Item>
|
||||
<Menu.Menu position="right">
|
||||
{/* <Link to="/update-plans">
|
||||
<Menu.Item name="systems">Update Plans</Menu.Item>
|
||||
</Link> */}
|
||||
<Dropdown item text={this.props.user.email}>
|
||||
<Dropdown.Menu>
|
||||
<Dropdown.Item href={profileLink}>Profile</Dropdown.Item>
|
||||
{/* <Dropdown.Item href={billingLink}>Billing</Dropdown.Item> */}
|
||||
<Dropdown.Item onClick={this._logout}>Logout</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
</Menu.Menu>
|
||||
</Menu>
|
||||
) : (
|
||||
<Menu style={navStyle}>
|
||||
<Menu.Item name="systems" header>
|
||||
OpenMHz
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Navigation;
|
||||
5
account/src/client/components/style/style.css
Normal file
5
account/src/client/components/style/style.css
Normal file
@@ -0,0 +1,5 @@
|
||||
.field {
|
||||
padding-top: 10px;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
11
account/src/client/query-string.js
Normal file
11
account/src/client/query-string.js
Normal file
@@ -0,0 +1,11 @@
|
||||
export default {
|
||||
parse: function parse(queryString) {
|
||||
var query = {};
|
||||
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
|
||||
for (var i = 0; i < pairs.length; i++) {
|
||||
var pair = pairs[i].split('=');
|
||||
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
12
account/src/client/reducers/index.js
Normal file
12
account/src/client/reducers/index.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { combineReducers } from "redux"
|
||||
import { connectRouter } from 'connected-react-router'
|
||||
import user from "../User/user-reducer"
|
||||
import system from "../System/system-reducer"
|
||||
import billing from "../Billing/billing-reducer"
|
||||
|
||||
export default (history) => combineReducers({
|
||||
router: connectRouter(history),
|
||||
user,
|
||||
system,
|
||||
billing
|
||||
})
|
||||
21
account/src/client/stories/index.js
Normal file
21
account/src/client/stories/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { storiesOf } from '@storybook/react';
|
||||
import { Button } from '@storybook/react/demo';
|
||||
import InvoiceList from '../Billing/InvoiceList';
|
||||
import 'semantic-ui-css/semantic.min.css'
|
||||
|
||||
storiesOf('Button', module)
|
||||
.add('with text', () => (
|
||||
<Button>Hello Button</Button>
|
||||
))
|
||||
.add('with some emoji', () => (
|
||||
<Button><span role="img" aria-label="so cool">😀 😎 👍 💯</span></Button>
|
||||
));
|
||||
|
||||
|
||||
export const invoices = [{"amount_due":1500,"amount_paid":1500,"date":1548819212,"invoice_pdf":"https://pay.stripe.com/invoice/invst_BYlZ3MlhYMHEStbvdVJ6vddxgp/pdf","paid":true,"status":"paid","description":null},{"amount_due":1500,"amount_paid":1500,"date":1548819083,"invoice_pdf":"https://pay.stripe.com/invoice/invst_ts0VnXKuxHWHce02yjhu0Cz455/pdf","paid":true,"status":"paid","description":null},{"amount_due":1500,"amount_paid":1500,"date":1548818978,"invoice_pdf":"https://pay.stripe.com/invoice/invst_HSjke6BJAWGlZL8ggn3Jgb8pnT/pdf","paid":true,"status":"paid","description":null},{"amount_due":6500,"amount_paid":6500,"date":1548816924,"invoice_pdf":"https://pay.stripe.com/invoice/invst_joLNjLFGU3PIondKAAop6kJaSZ/pdf","paid":true,"status":"paid","description":null},{"amount_due":1500,"amount_paid":1500,"date":1548772157,"invoice_pdf":"https://pay.stripe.com/invoice/invst_cSWcbq3UKUHxPQChSjkxRKx6gO/pdf","paid":true,"status":"paid","description":null},{"amount_due":1500,"amount_paid":1500,"date":1548772077,"invoice_pdf":"https://pay.stripe.com/invoice/invst_1aMYlwnPOdXKbebGuCjQfUrsg2/pdf","paid":true,"status":"paid","description":null}];
|
||||
|
||||
storiesOf('InvoiceList', module).add("standard", () => {
|
||||
return (<InvoiceList invoices={invoices}/>)
|
||||
|
||||
});
|
||||
BIN
account/src/resources/powered_by_stripe.png
Normal file
BIN
account/src/resources/powered_by_stripe.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
60
account/src/server/config/express.js
Normal file
60
account/src/server/config/express.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import path from "path"
|
||||
import express from "express"
|
||||
import session from "express-session"
|
||||
import bodyParser from "body-parser"
|
||||
import connectMongo from "connect-mongo"
|
||||
import secrets from "./secrets"
|
||||
|
||||
const MongoStore = connectMongo(session)
|
||||
var cookie_domain = process.env['COOKIE_DOMAIN'] != null ? process.env['COOKIE_DOMAIN'] : '.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
|
||||
|
||||
export default function(app, passport) {
|
||||
app.set("port", 3009)
|
||||
|
||||
// X-Powered-By header has no functional value.
|
||||
// Keeping it makes it easier for an attacker to build the site's profile
|
||||
// It can be removed safely
|
||||
app.disable("x-powered-by")
|
||||
app.enable('trust proxy')
|
||||
app.use(bodyParser.json())
|
||||
app.use(bodyParser.urlencoded({ extended: true }))
|
||||
app.use(express.static(path.join(process.cwd(), 'public')));
|
||||
|
||||
const sess = {
|
||||
secret: 'secret',
|
||||
/*saveUninitialized: false,
|
||||
resave: false,*/
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
secret: secrets.sessionSecret,
|
||||
proxy: true,
|
||||
name: "sessionId",
|
||||
cookie: {
|
||||
httpOnly: true,
|
||||
secure: false,
|
||||
domain: cookie_domain
|
||||
},
|
||||
store: new MongoStore({
|
||||
url: secrets.db,
|
||||
autoReconnect: true
|
||||
})
|
||||
}
|
||||
|
||||
var node_env = process.env.NODE_ENV;
|
||||
console.log('--------------------------');
|
||||
console.log('===> 😊 Starting Server . . .');
|
||||
console.log('===> Environment: ' + node_env);
|
||||
/*if(node_env === 'production') {
|
||||
console.log('===> 🚦 Note: In order for authentication to work in production');
|
||||
console.log('===> you will need a secure HTTPS connection');
|
||||
sess.cookie.secure = true; // Serve secure cookies
|
||||
sess.cookie.httpOnly = false;
|
||||
}*/
|
||||
|
||||
app.use(session(sess))
|
||||
|
||||
app.use(passport.initialize())
|
||||
app.use(passport.session())
|
||||
|
||||
}
|
||||
35
account/src/server/config/passport-strategies/local.js
Normal file
35
account/src/server/config/passport-strategies/local.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Configuring local strategy to authenticate strategies
|
||||
Code modified from : https://github.com/madhums/node-express-mongoose-demo/blob/master/config/passport/local.js
|
||||
*/
|
||||
|
||||
import mongoose from "mongoose"
|
||||
import { Strategy as LocalStrategy } from "passport-local"
|
||||
import User from "../../models/user"
|
||||
|
||||
/*
|
||||
By default, LocalStrategy expects to find credentials in parameters named username and password.
|
||||
If your site prefers to name these fields differently, options are available to change the defaults.
|
||||
*/
|
||||
export default new LocalStrategy({
|
||||
usernameField: "email"
|
||||
}, (email, password, done) => {
|
||||
User.findOne({
|
||||
$or: [{
|
||||
email
|
||||
}, {
|
||||
local: {
|
||||
email
|
||||
}
|
||||
}]
|
||||
}, (err, user) => {
|
||||
if(!user) return done(null, false, { message: `Email ${email} not found` })
|
||||
user.comparePassword(password, (err, isMatch) => {
|
||||
if (isMatch) {
|
||||
return done(null, user)
|
||||
} else {
|
||||
return done(null, false, { message: "Invalid email or password" })
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
25
account/src/server/config/passport.js
Normal file
25
account/src/server/config/passport.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/* Initializing PassportJS */
|
||||
import User from "../models/user"
|
||||
import local from "./passport-strategies/local"
|
||||
|
||||
export default function (app, passport) {
|
||||
// Configure Passport authenticated session persistence.
|
||||
//
|
||||
// In order to restore authentication state across HTTP requests, Passport needs
|
||||
// to serialize users into and deserialize users out of the session. The
|
||||
// typical implementation of this is as simple as supplying the user ID when
|
||||
// serializing, and querying the user record by ID from the database when
|
||||
// deserializing.
|
||||
passport.serializeUser((user, done) => {
|
||||
done(null, user.id)
|
||||
})
|
||||
|
||||
passport.deserializeUser((id, done) => {
|
||||
User.findById(id, (err, user) => {
|
||||
done(err, user)
|
||||
})
|
||||
})
|
||||
|
||||
// use the following strategies
|
||||
passport.use(local)
|
||||
}
|
||||
15
account/src/server/config/secrets.js
Normal file
15
account/src/server/config/secrets.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/** Important **/
|
||||
/** You should not be committing this file to GitHub **/
|
||||
/** Repeat: DO! NOT! COMMIT! THIS! FILE! TO! YOUR! REPO! **/
|
||||
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
|
||||
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : 27017;
|
||||
var mongoUrl = 'mongodb://' + host + ':' + port + '/scanner';
|
||||
|
||||
|
||||
|
||||
const secrets = {
|
||||
db: mongoUrl,
|
||||
sessionSecret: "letthisbeyoursecret"
|
||||
}
|
||||
|
||||
export default secrets
|
||||
272
account/src/server/controllers/plans.js
Normal file
272
account/src/server/controllers/plans.js
Normal file
@@ -0,0 +1,272 @@
|
||||
import mongoose from "mongoose";
|
||||
import Plan from "../models/plan";
|
||||
import System from "../models/system";
|
||||
|
||||
const stripeKeyPublishable = process.env.STRIPE_PUBLISHABLE_KEY;
|
||||
const stripeKeySecret = process.env.STRIPE_SECRET_KEY;
|
||||
|
||||
const stripe = require("stripe")(stripeKeySecret);
|
||||
|
||||
var admin_email = process.env['ADMIN_EMAIL'] != null ? process.env['ADMIN_EMAIL'] : "luke@openmhz.com";
|
||||
var site_name = process.env['SITE_NAME'] != null ? process.env['SITE_NAME'] : "OpenMHz";
|
||||
var account_server = process.env['ACCOUNT_SERVER'] != null ? process.env['ACCOUNT_SERVER'] : "https://account.openmhz.com";
|
||||
var cookie_domain = process.env['COOKIE_DOMAIN'] != null ? process.env['COOKIE_DOMAIN'] : '.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
|
||||
exports.isLoggedIn = function (req, res, next) {
|
||||
if (req.isAuthenticated()) return next();
|
||||
res.redirect("/login");
|
||||
};
|
||||
|
||||
|
||||
function makeSystemsResponse(systems) {
|
||||
var returnSys = systems.map(obj => {
|
||||
var rObj = (({
|
||||
name,
|
||||
shortName,
|
||||
description,
|
||||
systemType,
|
||||
city,
|
||||
state,
|
||||
county,
|
||||
country,
|
||||
userId,
|
||||
key,
|
||||
planType,
|
||||
showScreenName
|
||||
}) => ({
|
||||
name,
|
||||
shortName,
|
||||
description,
|
||||
systemType,
|
||||
city,
|
||||
state,
|
||||
county,
|
||||
country,
|
||||
userId,
|
||||
key,
|
||||
planType,
|
||||
showScreenName
|
||||
}))(obj);
|
||||
rObj.id = obj._id;
|
||||
return rObj;
|
||||
});
|
||||
return returnSys;
|
||||
}
|
||||
|
||||
function findSubscriptionItem(subscription, planId) {
|
||||
var items = subscription.items.data;
|
||||
|
||||
var subscriptionItem = items.find(function (element) {
|
||||
return element.plan.id == planId;
|
||||
});
|
||||
return subscriptionItem;
|
||||
};
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
// makes sure the plans a user is trying to update actually belong to them.
|
||||
function validatePlans(systems, updatedPlans) {
|
||||
var validatedPlans = [];
|
||||
systems.forEach(function (system) {
|
||||
|
||||
// Find the updated plan for that system.
|
||||
const updatedPlan = updatedPlans.find(function (element) {
|
||||
return element.shortName == system.shortName;
|
||||
})
|
||||
if (!updatedPlan) {
|
||||
console.log("ERROR: updated plan not found for ShortName");
|
||||
}
|
||||
|
||||
// Update that systems plan type
|
||||
// TODO: add validation of plantype
|
||||
system.planType = updatedPlan.planType;
|
||||
validatedPlans.push({ shortName: system.shortName, planType: updatedPlan.planType });
|
||||
});
|
||||
return validatedPlans;
|
||||
}
|
||||
exports.updatePlans = async function (req, res, next) {
|
||||
const userId = mongoose.Types.ObjectId(req.user._id);
|
||||
|
||||
if (!req.user.customerId) {
|
||||
console.log("ERROR: user does not have billing setup");
|
||||
res.json({
|
||||
success: false,
|
||||
message: "ERROR: user does not have billing setup"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedPlans = req.body.updatePlans;
|
||||
console.log(updatedPlans);
|
||||
|
||||
try {
|
||||
var plan = await Plan.findOne({ userId: userId });
|
||||
|
||||
// looks like the User does not have a plan yet
|
||||
|
||||
if (!plan) {
|
||||
plan = new Plan({ userId: userId });
|
||||
}
|
||||
|
||||
|
||||
// Find all of the Users Systems
|
||||
var systems = await System.find({ userId: mongoose.Types.ObjectId(req.user._id) })
|
||||
|
||||
|
||||
} catch (err) {
|
||||
|
||||
console.log("Error upate plans: " + err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// For each of the User's Systems
|
||||
var validatedPlans = validatePlans(systems, updatedPlans);
|
||||
|
||||
// Create the subscription object
|
||||
console.log("---------Validated Plans--------");
|
||||
console.log(validatedPlans);
|
||||
var proPlans = { plan: "plan_EQoJeqkAw6FCgy", quantity: 0 };
|
||||
var proPlanSystems = [];
|
||||
var proPlanQuantity = 0;
|
||||
validatedPlans.forEach(function (plan) {
|
||||
if (plan.planType == 10) {
|
||||
proPlanQuantity++;
|
||||
proPlans.quantity++;
|
||||
proPlanSystems.push(plan.shortName);
|
||||
}
|
||||
});
|
||||
|
||||
if (!plan.subscriptionId) {
|
||||
//proPlans.metadata = proPlanSystems.join();
|
||||
var items = [];
|
||||
items.push(proPlans);
|
||||
//Subscribe the User
|
||||
|
||||
console.log(subscription);
|
||||
try {
|
||||
var subscription = await stripe.subscriptions.create({
|
||||
customer: req.user.customerId,
|
||||
items: items
|
||||
});
|
||||
console.log(subscription);
|
||||
|
||||
const subscriptionItem = findSubscriptionItem(subscription, "plan_EQoJeqkAw6FCgy");
|
||||
if (subscriptionItem) {
|
||||
plan.proSystemSubscription = { subscriptionItemId: subscriptionItem.id, quantity: proPlanQuantity, systems: proPlanSystems };
|
||||
plan.subscriptionId = subscription.id;
|
||||
await plan.save();
|
||||
systems.forEach(async function (system) { await system.save(); });
|
||||
// Save the updated Systems
|
||||
const returnSystems = makeSystemsResponse(systems);
|
||||
res.json({
|
||||
success: true,
|
||||
systems: returnSystems
|
||||
});
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Error upate plans: " + err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// we alreay have a Subscription for the User
|
||||
try {
|
||||
var subscriptionItem=null;
|
||||
// Check if the user has a Pro Plan subscription Item setup yet.
|
||||
if (plan.proSystemSubscription) {
|
||||
subscriptionItem = await stripe.subscriptionItems.update(plan.proSystemSubscription.subscriptionItemId,
|
||||
{
|
||||
quantity: proPlanQuantity,
|
||||
});
|
||||
} else {
|
||||
// Create one if they don't
|
||||
subscriptionItem = await stripe.subscriptionItems.create(
|
||||
{
|
||||
subscription: plan.subscriptionId,
|
||||
plan: "plan_EQoJeqkAw6FCgy",
|
||||
quantity: proPlanQuantity,
|
||||
});
|
||||
}
|
||||
|
||||
if (subscriptionItem) {
|
||||
plan.proSystemSubscription = { subscriptionItemId: subscriptionItem.id, quantity: proPlanQuantity, systems: proPlanSystems };
|
||||
await plan.save();
|
||||
systems.forEach(async function (system) { await system.save(); });
|
||||
// Save the updated Systems
|
||||
const returnSystems = makeSystemsResponse(systems);
|
||||
res.json({
|
||||
success: true,
|
||||
systems: returnSystems
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("Error upate plans: " + err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.getInvoices = async function (req, res, next) {
|
||||
if (!req.user.customerId) {
|
||||
console.log("ERROR: user does not have billing setup");
|
||||
res.json({
|
||||
success: false,
|
||||
message: "ERROR: user does not have billing setup"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("Trying to fetch invoices for: " + req.user.customerId);
|
||||
var invoices = await stripe.invoices.list( { limit: 12, customer: req.user.customerId });
|
||||
console.log(invoices);
|
||||
var obj = invoices.data.map(obj => {
|
||||
var rObj = (({
|
||||
amount_due,
|
||||
amount_paid,
|
||||
date,
|
||||
invoice_pdf,
|
||||
paid,
|
||||
status,
|
||||
description
|
||||
}) => ({
|
||||
amount_due,
|
||||
amount_paid,
|
||||
date,
|
||||
invoice_pdf,
|
||||
paid,
|
||||
status,
|
||||
description
|
||||
}))(obj);
|
||||
rObj.id = obj._id;
|
||||
return rObj;
|
||||
});
|
||||
return res.json({
|
||||
success: true,
|
||||
invoices: obj
|
||||
});
|
||||
} catch (err) {
|
||||
console.log("Error retrieving licesnes: " + err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
62
account/src/server/controllers/systems.js
Normal file
62
account/src/server/controllers/systems.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import mongoose from "mongoose";
|
||||
import System from "../models/system";
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
exports.getUserSystems = function(_id) {
|
||||
console.log("Listing Systems for: " + _id);
|
||||
System.find(
|
||||
{
|
||||
userId: mongoose.Types.ObjectId(_id)
|
||||
},
|
||||
function(err, systems) {
|
||||
if (err) {
|
||||
console.error("Error - ListSystems: " + err);
|
||||
return({ success: false, message: err });
|
||||
}
|
||||
|
||||
|
||||
var returnSys = systems.map(obj => {
|
||||
var rObj = (({
|
||||
name,
|
||||
shortName,
|
||||
description,
|
||||
systemType,
|
||||
city,
|
||||
state,
|
||||
county,
|
||||
country,
|
||||
userId,
|
||||
key,
|
||||
planType,
|
||||
showScreenName
|
||||
}) => ({
|
||||
name,
|
||||
shortName,
|
||||
description,
|
||||
systemType,
|
||||
city,
|
||||
state,
|
||||
county,
|
||||
country,
|
||||
userId,
|
||||
key,
|
||||
planType,
|
||||
showScreenName
|
||||
}))(obj);
|
||||
rObj.id = obj._id;
|
||||
return rObj;
|
||||
});
|
||||
|
||||
|
||||
return({ success: true, systems: returnSys });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
exports.listSystems = function(req, res, next) {
|
||||
return listSystems(req.user._id);
|
||||
}
|
||||
|
||||
606
account/src/server/controllers/users.js
Normal file
606
account/src/server/controllers/users.js
Normal file
@@ -0,0 +1,606 @@
|
||||
import mongoose from "mongoose";
|
||||
import passport from "passport";
|
||||
import User from "../models/user";
|
||||
import secrets from "../config/secrets";
|
||||
const mailjet = require("node-mailjet").connect(
|
||||
process.env['MAILJET_KEY'],
|
||||
process.env['MAILJET_SECRET']
|
||||
);
|
||||
const crypto = require("crypto");
|
||||
|
||||
var admin_email = process.env['ADMIN_EMAIL'] != null ? process.env['ADMIN_EMAIL'] : "luke@openmhz.com";
|
||||
var site_name = process.env['SITE_NAME'] != null ? process.env['SITE_NAME'] : "OpenMHz";
|
||||
var account_server = process.env['ACCOUNT_SERVER'] != null ? process.env['ACCOUNT_SERVER'] : "https://account.openmhz.com";
|
||||
var cookie_domain = process.env['COOKIE_DOMAIN'] != null ? process.env['COOKIE_DOMAIN'] : '.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
|
||||
exports.isLoggedIn = function(req, res, next) {
|
||||
if (req.isAuthenticated()) return next();
|
||||
res.redirect("/login");
|
||||
};
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
exports.authenticated = function(req, res, next) {
|
||||
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
|
||||
console.log("auth: " + req.isAuthenticated());
|
||||
console.log("req.user: " + req.user);
|
||||
if (req.isAuthenticated()) {
|
||||
var clientUser = (({
|
||||
firstName,
|
||||
lastName,
|
||||
screenName,
|
||||
location,
|
||||
email,
|
||||
admin
|
||||
}) => ({
|
||||
firstName,
|
||||
lastName,
|
||||
screenName,
|
||||
location,
|
||||
email,
|
||||
admin
|
||||
}))(
|
||||
req.user
|
||||
);
|
||||
clientUser.userId = req.user.id
|
||||
if (req.user.customerId) {
|
||||
clientUser.billing = true;
|
||||
} else {
|
||||
clientUser.billing = false;
|
||||
}
|
||||
return res.json({
|
||||
success: true,
|
||||
user: clientUser
|
||||
});
|
||||
|
||||
} else {
|
||||
return res.json({
|
||||
success: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
exports.login = function(req, res, next) {
|
||||
// Do email and password validation for the server
|
||||
passport.authenticate("local", function(err, user, info) {
|
||||
if (err) return next(err);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
message: info.message
|
||||
});
|
||||
}
|
||||
// ***********************************************************************
|
||||
// "Note that when using a custom callback, it becomes the application's
|
||||
// responsibility to establish a session (by calling req.login()) and send
|
||||
// a response."
|
||||
// Source: http://passportjs.org/docs
|
||||
// ***********************************************************************
|
||||
// Passport exposes a login() function on req (also aliased as logIn())
|
||||
// that can be used to establish a login session
|
||||
req.login(user, loginErr => {
|
||||
|
||||
if (loginErr) {
|
||||
return res.json({
|
||||
success: false,
|
||||
message: loginErr
|
||||
});
|
||||
}
|
||||
if (!user.confirmEmail) {
|
||||
req.logout();
|
||||
return res.json({
|
||||
success: false,
|
||||
message: "unconfirmed email",
|
||||
userId: user.id
|
||||
});
|
||||
}
|
||||
console.log(user);
|
||||
// go ahead and create the new user
|
||||
var clientUser = (({
|
||||
firstName,
|
||||
lastName,
|
||||
screenName,
|
||||
location,
|
||||
email,
|
||||
admin
|
||||
}) => ({
|
||||
firstName,
|
||||
lastName,
|
||||
screenName,
|
||||
location,
|
||||
email,
|
||||
admin
|
||||
}))(
|
||||
user
|
||||
);
|
||||
clientUser.userId = user.id
|
||||
return res.json({
|
||||
success: true,
|
||||
message: "authentication succeeded",
|
||||
user: clientUser,
|
||||
userId: user.id
|
||||
});
|
||||
});
|
||||
})(req, res, next);
|
||||
};
|
||||
|
||||
exports.confirmEmail = function(req, res, next) {
|
||||
const userId = req.params["userId"];
|
||||
const token = req.params["token"];
|
||||
|
||||
User.findById(userId, (err, user) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (user.confirmEmail) {
|
||||
console.log("User already confirmed email: " + userId);
|
||||
res.json({
|
||||
success: false,
|
||||
message: "already confirmed email"
|
||||
});
|
||||
return;
|
||||
}
|
||||
const today = new Date();
|
||||
if (user.confirmEmailTTL < today) {
|
||||
res.json({
|
||||
success: false,
|
||||
message: "token expired"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (user.confirmEmailToken != token) {
|
||||
console.log(
|
||||
"Token Mismatch DB: " + user.confirmEmailToken + " submitted: " + token
|
||||
);
|
||||
res.json({
|
||||
success: false,
|
||||
message: "token mismatch"
|
||||
});
|
||||
return;
|
||||
}
|
||||
user.confirmEmail = true;
|
||||
user.confirmEmailToken = "";
|
||||
user.save(err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.log("User: " + user.email + " confirmed email address");
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
return;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
exports.resetPassword = function(req, res, next) {
|
||||
const userId = req.params["userId"];
|
||||
const token = req.params["token"];
|
||||
|
||||
User.findById(userId, (err, user) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const today = new Date();
|
||||
if (user.resetPasswordTTL < today) {
|
||||
res.json({
|
||||
success: false,
|
||||
message: "token expired"
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (user.resetPasswordToken != token) {
|
||||
console.log(
|
||||
"Token Mismatch DB: " + user.resetPasswordToken + " submitted: " + token
|
||||
);
|
||||
res.json({
|
||||
success: false,
|
||||
message: "token mismatch"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
user.password = req.body.password
|
||||
user.confirmEmail = true;
|
||||
user.confirmEmailToken = "";
|
||||
user.resetPasswordToken = "";
|
||||
user.save(err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
return;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// -------------------------------------------
|
||||
exports.sendResetPassword = function(req, res, next) {
|
||||
User.findOne({
|
||||
email: req.body.email
|
||||
}, (err, user) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!user) {
|
||||
console.error("Reset password failed. No user: " + req.body.email);
|
||||
res.json({
|
||||
success: false,
|
||||
message: "No account register for " + req.body.email
|
||||
});
|
||||
return;
|
||||
}
|
||||
const buffer = crypto.randomBytes(20);
|
||||
const token = buffer.toString("hex");
|
||||
var tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
user.resetPasswordToken = token;
|
||||
user.resetPasswordTTL = tomorrow;
|
||||
user.save(err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const request = mailjet.post("send", {
|
||||
version: "v3.1"
|
||||
}).request({
|
||||
Messages: [{
|
||||
From: {
|
||||
Email: admin_email,
|
||||
Name: site_name + " Admin"
|
||||
},
|
||||
To: [{
|
||||
Email: user.email,
|
||||
Name: user.firstName + " " + user.lastName
|
||||
}],
|
||||
Subject: site_name + " - Password Reset",
|
||||
TextPart: "It looks like you may have forgot your password. Copy this link to your browser to reset your password. Let us know if you are receiving this but did not request a password reset. /r" + account_server + "/reset-password/" + user.id + "/" + token,
|
||||
HTMLPart: "<h3>Thanks for using " + site_name + "!</h3><br />It looks like you may have forgot your password. Copy this link to your browser to reset your password. Let us know if you are receiving this but did not request a password reset.<p>" + account_server + "/reset-password/" + user.id + "/" + token + "</p>"
|
||||
}]
|
||||
});
|
||||
request
|
||||
.then(result => {
|
||||
console.log(`Password reset sent to: ${user.email}`)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err.statusCode);
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
});
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
return;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function handleSendConfirmEmail(user) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (user.confirmEmail) {
|
||||
console.log("Error - Send Confirm Email - User already confirmed email: " + user.email);
|
||||
reject({
|
||||
success: false,
|
||||
message: "already confirmed email"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const buffer = crypto.randomBytes(20);
|
||||
const token = buffer.toString("hex");
|
||||
var tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
user.confirmEmailToken = token;
|
||||
user.confirmEmailTTL = tomorrow;
|
||||
user.save().then(function(user) {
|
||||
return mailjet.post("send", {
|
||||
version: "v3.1"
|
||||
}).request({
|
||||
Messages: [{
|
||||
From: {
|
||||
Email: admin_email,
|
||||
Name: site_name + " Admin"
|
||||
},
|
||||
To: [{
|
||||
Email: user.email,
|
||||
Name: user.firstName + " " + user.lastName
|
||||
}],
|
||||
Subject: "Confirm " + site_name + " Account",
|
||||
TextPart: "Thanks for signing up for " + site_name + ". We just wanted to check and make sure your email address was real. Copy and paste this addres in your browser to confirm your email address: " + account_server + "/confirm-email/" + user._id + "/" + token,
|
||||
HTMLPart: "<h3>Thanks for signing up for " + site_name + "</h3><br />We just wanted to check and make sure your email address was real. Copy and paste this addres in your browser to confirm your email address:<p> " + account_server + "/confirm-email/" + user._id + "/" + token + "</p>"
|
||||
}]
|
||||
});
|
||||
}).then(result => {
|
||||
console.log("Confirm email sent to: " + user.email);
|
||||
resolve({
|
||||
success: true,
|
||||
userId: user._id
|
||||
});
|
||||
}).catch(err => {
|
||||
console.error("Admin Email: " + admin_email + " User Email: " + user.email);
|
||||
console.error("Error - Send Confirm Email - caught: " + err);
|
||||
reject({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// -------------------------------------------
|
||||
exports.sendConfirmEmail = function(req, res, next) {
|
||||
const userId = req.params["userId"];
|
||||
User.findById(userId, (err, user) => {
|
||||
if (err) {
|
||||
console.error("Error - Send Confirm Email: " + err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!user) {
|
||||
console.error("Error - Send Confirm Email: User not found " + userId);
|
||||
res.json({
|
||||
success: false,
|
||||
message: "user not found"
|
||||
});
|
||||
return;
|
||||
}
|
||||
handleSendConfirmEmail(user).then(function(result) {
|
||||
res.json(result);
|
||||
return;
|
||||
}).catch(function(error) {
|
||||
res.json(error);
|
||||
return;
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
exports.logout = function(req, res, next) {
|
||||
// the logout method is added to the request object automatically by Passport
|
||||
req.logout();
|
||||
res.clearCookie('sessionId', {domain: cookie_domain, path:'/'});
|
||||
return res.json({
|
||||
success: true
|
||||
});
|
||||
};
|
||||
|
||||
exports.terms = function(req, res, next) {
|
||||
const userId = req.params["userId"];
|
||||
User.findById(userId, (err, user) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (req.user.id != userId) {
|
||||
console.log(
|
||||
"Logged in user's ID: " +
|
||||
req.user.id +
|
||||
" does not match Param: " +
|
||||
userId
|
||||
);
|
||||
res.json({
|
||||
success: false,
|
||||
message: "UserID incorrect"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
user.terms = 1.1; //User.termsVer;
|
||||
user.save(err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
return;
|
||||
});
|
||||
});
|
||||
};
|
||||
// -------------------------------------------
|
||||
|
||||
|
||||
exports.validateProfile = function(req, res, next) {
|
||||
if (!req.body.firstName || (req.body.firstName.length < 2)) {
|
||||
console.error("ERROR: Validate System - req.body.firstName");
|
||||
res.json({
|
||||
success: false,
|
||||
message: "First Name is Required"
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.locals.firstName = req.body.firstName.replace(/[^\w\s\.\,\-\'\`]/gi, '');
|
||||
|
||||
if (!req.body.lastName || (req.body.lastName.length < 2)) {
|
||||
console.error("ERROR: Validate System - req.body.lastName");
|
||||
res.json({
|
||||
success: false,
|
||||
message: "Last Name is Required"
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.locals.lastName = req.body.lastName.replace(/[^\w\s\.\,\-\'\`]/gi, '');
|
||||
|
||||
|
||||
res.locals.screenName = req.body.screenName.replace(/[^\w\s\.\,\-\_]/gi, '');
|
||||
|
||||
if (!req.body.location || (req.body.location.length < 2)) {
|
||||
console.error("ERROR: Validate System - req.body.location");
|
||||
res.json({
|
||||
success: false,
|
||||
message: "System location is Required"
|
||||
});
|
||||
return;
|
||||
}
|
||||
res.locals.location = req.body.location.replace(/[^\w\s\.\,\-\_]/gi, '');
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
exports.updateProfile = function(req, res, next) {
|
||||
const userId = req.params["userId"];
|
||||
|
||||
User.findById(userId, (err, user) => {
|
||||
// is email address already in use?
|
||||
if (req.user.id != userId) {
|
||||
console.log(
|
||||
"ERROR: Logged in user's ID: " +
|
||||
req.user.id +
|
||||
" does not match Param: " +
|
||||
userId
|
||||
);
|
||||
res.json({
|
||||
success: false,
|
||||
message: "UserID incorrect"
|
||||
});
|
||||
return;
|
||||
}
|
||||
// go ahead and create the new user
|
||||
user.firstName = res.locals.firstName
|
||||
user.lastName = res.locals.lastName
|
||||
user.screenName = res.locals.screenName
|
||||
user.location = res.locals.location
|
||||
|
||||
console.log(user)
|
||||
user.save(err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
var clientUser = (({
|
||||
firstName,
|
||||
lastName,
|
||||
screenName,
|
||||
location
|
||||
}) => ({
|
||||
firstName,
|
||||
lastName,
|
||||
screenName,
|
||||
location
|
||||
}))(
|
||||
user
|
||||
);
|
||||
console.log("Updated Profile: " + userId)
|
||||
res.json({
|
||||
success: true,
|
||||
user: clientUser
|
||||
});
|
||||
return;
|
||||
});
|
||||
});
|
||||
};
|
||||
// -------------------------------------------
|
||||
|
||||
exports.register = function(req, res, next) {
|
||||
User.findOne({
|
||||
$or: [{
|
||||
email: req.body.email
|
||||
}, {
|
||||
local: {
|
||||
email: req.body.email
|
||||
}
|
||||
}]
|
||||
}, (err, user) => {
|
||||
// is email address already in use?
|
||||
if (user) {
|
||||
res.json({
|
||||
success: false,
|
||||
message: "Email already in use"
|
||||
});
|
||||
return;
|
||||
}
|
||||
// go ahead and create the new user
|
||||
var user = (({
|
||||
firstName,
|
||||
lastName,
|
||||
screenName,
|
||||
location,
|
||||
email,
|
||||
password
|
||||
}) => ({
|
||||
firstName,
|
||||
lastName,
|
||||
screenName,
|
||||
location,
|
||||
|
||||
}))(
|
||||
res.locals
|
||||
);
|
||||
user.password = req.body.password;
|
||||
user.email = req.body.email;
|
||||
|
||||
User.create(user).then(function(dbUser) {
|
||||
console.log(dbUser);
|
||||
// Since regiestration worked, send a confirmation email.
|
||||
return handleSendConfirmEmail(dbUser);
|
||||
}).then(function(result) {
|
||||
res.json(result);
|
||||
return;
|
||||
}).catch(function(err) {
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
});
|
||||
});
|
||||
};
|
||||
282
account/src/server/index.js
Normal file
282
account/src/server/index.js
Normal file
@@ -0,0 +1,282 @@
|
||||
import fs from "fs"
|
||||
import express from "express"
|
||||
import mongoose from "mongoose"
|
||||
import passport from "passport"
|
||||
import webpack from "webpack"
|
||||
import path from "path"
|
||||
import config from "../../webpack/webpack.config.dev.js"
|
||||
import secrets from "./config/secrets"
|
||||
import configurePassport from "./config/passport"
|
||||
import configureExpress from "./config/express"
|
||||
import users from "./controllers/users"
|
||||
import plans from "./controllers/plans"
|
||||
const stripeKeyPublishable = process.env.STRIPE_PUBLISHABLE_KEY;
|
||||
const stripeKeySecret = process.env.STRIPE_SECRET_KEY;
|
||||
|
||||
const stripe = require("stripe")(stripeKeySecret);
|
||||
import "./models/user"
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
const app = express()
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
const connect = () => {
|
||||
mongoose.connect(secrets.db, (err, res) => {
|
||||
if (err) {
|
||||
console.log(`Error connecting to ${secrets.db}. ${err}`)
|
||||
} else {
|
||||
console.log(`Successfully connected to ${secrets.db}.`)
|
||||
}
|
||||
})
|
||||
}
|
||||
connect()
|
||||
|
||||
mongoose.connection.on("error", console.error)
|
||||
mongoose.connection.on("disconnected", connect)
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
const isDev = process.env.NODE_ENV === "development"
|
||||
|
||||
// if in development mode set up the middleware required for hot reloading and rebundling
|
||||
if(isDev) {
|
||||
|
||||
const compiler = webpack(config)
|
||||
|
||||
app.use(require("webpack-dev-middleware")(compiler, {
|
||||
noInfo: true,
|
||||
publicPath: config.output.publicPath
|
||||
}))
|
||||
|
||||
app.use(require("webpack-hot-middleware")(compiler))
|
||||
}
|
||||
|
||||
|
||||
var backend_server = process.env['BACKEND_SERVER'] != null ? process.env['BACKEND_SERVER'] : 'https://api.openmhz.com';
|
||||
var frontend_server = process.env['FRONTEND_SERVER'] != null ? process.env['FRONTEND_SERVER'] : 'https://openmhz.com';
|
||||
var media_server = process.env['MEDIA_SERVER'] != null ? process.env['MEDIA_SERVER'] : 'https://media.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
var socket_server = process.env['SOCKET_SERVER'] != null ? process.env['SOCKET_SERVER'] : 'wss://api.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
var admin_server = process.env['ADMIN_SERVER'] != null ? process.env['ADMIN_SERVER'] : 'https://admin.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
var account_server = process.env['ACCOUNT_SERVER'] != null ? process.env['ACCOUNT_SERVER'] : 'https://account.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
var site_name = process.env['SITE_NAME'] != null ? process.env['SITE_NAME'] : "OpenMHz";
|
||||
const proPlanValue = process.env['PRO_PLAN'] != null ? process.env['PRO_PLAN'] : 10;
|
||||
const freePlanValue = process.env['FREE_PLAN'] != null ? process.env['FREE_PLAN'] : 0;
|
||||
const proPlanPrice = process.env['PRO_PLAN_PRICE'] != null ? process.env['PRO_PLAN_PRICE'] : 15;
|
||||
const freePlanPrice = process.env['FREE_PLAN_PRICE'] != null ? process.env['FREE_PLAN_PRICE'] : 0;
|
||||
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
configurePassport(app, passport)
|
||||
configureExpress(app, passport)
|
||||
|
||||
|
||||
app.all('*', function(req, res, next) {
|
||||
var allowedOrigins = [account_server, admin_server, frontend_server];
|
||||
var origin = req.headers.origin;
|
||||
if(allowedOrigins.indexOf(origin) > -1){
|
||||
res.setHeader('Access-Control-Allow-Origin', origin);
|
||||
}
|
||||
res.header("Access-Control-Allow-Credentials", "true");
|
||||
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type');
|
||||
next();
|
||||
});
|
||||
|
||||
// -------------------------------------------
|
||||
app.use(express.static(path.join(__dirname, "public")));
|
||||
app.post("/login", users.login)
|
||||
app.get("/logout", users.logout)
|
||||
app.get("/authenticated", users.authenticated)
|
||||
app.post("/register", users.validateProfile, users.register)
|
||||
app.post("/users/:userId/reset-password/:token", users.resetPassword)
|
||||
app.post("/api/send-reset-password", users.sendResetPassword)
|
||||
app.post("/users/:userId", users.isLoggedIn, users.validateProfile, users.updateProfile)
|
||||
app.post("/users/:userId/terms", users.isLoggedIn, users.terms)
|
||||
app.post("/users/:userId/send-confirm", users.sendConfirmEmail)
|
||||
app.post("/users/:userId/confirm/:token", users.confirmEmail)
|
||||
/*app.get("/api/invoices", users.isLoggedIn, plans.getInvoices)
|
||||
app.post("/api/plans", users.isLoggedIn, plans.updatePlans)
|
||||
app.get("/api/billing", users.isLoggedIn, (req,res) => {
|
||||
if (req.user.customerId) {
|
||||
stripe.customers.retrieve(
|
||||
req.user.customerId,
|
||||
function(err, customer) {
|
||||
if (err) {
|
||||
return res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
}
|
||||
if (customer) {
|
||||
if (customer.sources.total_count < 1) {
|
||||
return res.json({
|
||||
success: false,
|
||||
message: "Payment sources not defined"
|
||||
});
|
||||
}
|
||||
|
||||
for (var i=0; i < customer.sources.data.length; i++) {
|
||||
|
||||
|
||||
var source = customer.sources.data[i];
|
||||
if (source.id == customer.default_source) {
|
||||
console.log("match on: " + i);
|
||||
var obj = {
|
||||
name: source.owner.name,
|
||||
brand: source.card.brand,
|
||||
country: source.card.country,
|
||||
exp_month: source.card.exp_month,
|
||||
exp_year: source.card.exp_year,
|
||||
last4: source.card.last4
|
||||
}
|
||||
return res.json({
|
||||
success: true,
|
||||
source: obj
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return res.json({
|
||||
success: false,
|
||||
message: "Default payment source not found"
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
} else {
|
||||
return res.json({
|
||||
success: false,
|
||||
message: "User does not have a Customer ID"
|
||||
});
|
||||
}
|
||||
});*/
|
||||
|
||||
function updateCustomerId(req, res, err, customer) {
|
||||
if (err){
|
||||
return res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
}
|
||||
req.user.customerId = customer.id;
|
||||
req.user.save(err => {
|
||||
if (err) {
|
||||
console.error("Error saving customer ID");
|
||||
console.error(err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
console.log(customer);
|
||||
if (customer.sources.total_count < 1) {
|
||||
return res.json({
|
||||
success: false,
|
||||
message: "Payment sources not defined"
|
||||
});
|
||||
}
|
||||
|
||||
for (var i=0; i < customer.sources.data.length; i++) {
|
||||
console.log("--------Customer-----------");
|
||||
console.log(customer);
|
||||
|
||||
var source = customer.sources.data[i];
|
||||
if (source.id == customer.default_source) {
|
||||
console.log("--------Source-----------");
|
||||
console.log(source);
|
||||
var obj = {
|
||||
name: source.owner.name,
|
||||
brand: source.card.brand,
|
||||
country: source.card.country,
|
||||
exp_month: source.card.exp_month,
|
||||
exp_year: source.card.exp_year,
|
||||
last4: source.card.last4
|
||||
}
|
||||
return res.json({
|
||||
success: true,
|
||||
source: obj
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
app.post("/api/customer", users.isLoggedIn, (req, res) => {
|
||||
|
||||
//
|
||||
if (req.user.customerId) {
|
||||
stripe.customers.update(req.user.customerId, {
|
||||
source: req.body.sourceId
|
||||
}, function(err, customer) {
|
||||
return updateCustomerId(req, res, err, customer);
|
||||
});
|
||||
} else {
|
||||
stripe.customers.create({
|
||||
email: req.user.email,
|
||||
source: req.body.sourceId
|
||||
}, function(err, customer) {
|
||||
return updateCustomerId(req, res, err, customer);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.get("*", (req, res, next) => {
|
||||
|
||||
// if we are in production mode then an extension will be provided, usually ".min"
|
||||
const minified = process.env.MIN_EXT || ""
|
||||
|
||||
// this is the HTML we will send to the client when they request any page. React and React Router
|
||||
// will take over once the scripts are loaded client-side
|
||||
const appHTML =
|
||||
`<!doctype html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<title>OpenMHz - Account</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="https://js.stripe.com/v3/"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/style/style.css"></link>
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/semantic-ui@2.4.1/dist/semantic.min.css" />
|
||||
<script>
|
||||
const frontend_server = "${frontend_server}";
|
||||
const admin_server = "${admin_server}";
|
||||
const backend_server = "${backend_server}";
|
||||
const media_server = "${media_server}";
|
||||
const socket_server = "${socket_server}";
|
||||
const account_server = "${account_server}";
|
||||
const site_name = "${site_name}";
|
||||
const proPlanValue = ${proPlanValue};
|
||||
const freePlanValue = ${freePlanValue};
|
||||
const proPlanPrice = ${proPlanPrice};
|
||||
const freePlanPrice = ${freePlanPrice};
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script src="/assets/app${minified}.js"></script>
|
||||
</body>
|
||||
</html>`
|
||||
|
||||
res.status(200).end(appHTML)
|
||||
|
||||
})
|
||||
|
||||
// start listening to incoming requests
|
||||
app.listen(app.get("port"), app.get("host"), (err) => {
|
||||
if (err) {
|
||||
console.err(err.stack)
|
||||
} else {
|
||||
console.log(`App listening on port ${app.get("port")} [${process.env.NODE_ENV} mode]`)
|
||||
}
|
||||
})
|
||||
23
account/src/server/models/plan.js
Normal file
23
account/src/server/models/plan.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// Defining a User Model in mongoose
|
||||
// Code modified from https://github.com/sahat/hackathon-starter
|
||||
import bcrypt from "bcrypt-nodejs"
|
||||
import mongoose from "mongoose"
|
||||
|
||||
|
||||
var SubscriptionSchema = mongoose.Schema({ subscriptionItemId: String, quantity: {type: Number, default: 0}, systems: [String] });
|
||||
const PlanSchema = new mongoose.Schema({
|
||||
|
||||
userId: mongoose.Schema.Types.ObjectId,
|
||||
userPlan: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
subscriptionId: String,
|
||||
proSystemSubscription: SubscriptionSchema
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export default mongoose.model("Plan", PlanSchema)
|
||||
27
account/src/server/models/system.js
Normal file
27
account/src/server/models/system.js
Normal file
@@ -0,0 +1,27 @@
|
||||
var mongoose = require('mongoose');
|
||||
var bcrypt = require('bcrypt-nodejs');
|
||||
|
||||
var systemSchema = mongoose.Schema({
|
||||
name: String,
|
||||
shortName: String,
|
||||
systemType: String,
|
||||
county: String,
|
||||
country: String,
|
||||
city: String,
|
||||
state: String,
|
||||
description: String,
|
||||
showScreenName: Boolean,
|
||||
planType: {type: Number, default: 0},
|
||||
userId: mongoose.Schema.Types.ObjectId,
|
||||
key: String
|
||||
});
|
||||
|
||||
systemSchema.methods.generateHash = function(password) {
|
||||
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
|
||||
};
|
||||
|
||||
systemSchema.methods.validPassword = function(password) {
|
||||
return bcrypt.compareSync(password, this.local.password);
|
||||
};
|
||||
|
||||
module.exports = mongoose.model('System', systemSchema);
|
||||
92
account/src/server/models/user.js
Normal file
92
account/src/server/models/user.js
Normal file
@@ -0,0 +1,92 @@
|
||||
// Defining a User Model in mongoose
|
||||
// Code modified from https://github.com/sahat/hackathon-starter
|
||||
import bcrypt from "bcrypt-nodejs"
|
||||
import mongoose from "mongoose"
|
||||
import crypto from "crypto"
|
||||
|
||||
|
||||
|
||||
const UserSchema = new mongoose.Schema({
|
||||
local: {
|
||||
name: String,
|
||||
email: String,
|
||||
password: String
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
unique: true,
|
||||
lowercase: true
|
||||
},
|
||||
password: String,
|
||||
screenName: {
|
||||
type: String,
|
||||
unique: true,
|
||||
lowercase: true
|
||||
},
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
location: String,
|
||||
email: String,
|
||||
resetPasswordToken: String,
|
||||
resetPasswordTTL: Date,
|
||||
confirmEmail: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
customerId: {
|
||||
type: String,
|
||||
default: ""
|
||||
},
|
||||
confirmEmailToken: String,
|
||||
confirmEmailTTL: Date,
|
||||
admin: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
terms: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
ver: {
|
||||
type: Number,
|
||||
default: 1.1
|
||||
},
|
||||
sysCount: Number,
|
||||
lastLogin: { type : Date, default: Date.now }
|
||||
})
|
||||
|
||||
/**
|
||||
* Password hash middleware.
|
||||
*/
|
||||
UserSchema.pre("save", function(next) {
|
||||
var user = this
|
||||
if (!user.isModified("password")) return next()
|
||||
bcrypt.genSalt(8, (err, salt) => {
|
||||
if (err) return next(err)
|
||||
bcrypt.hash(user.password, salt, null, (err, hash) => {
|
||||
if (err) return next(err)
|
||||
user.password = hash
|
||||
user.local.password = hash;
|
||||
next()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
/*
|
||||
Defining our own custom document instance method
|
||||
*/
|
||||
UserSchema.methods = {
|
||||
comparePassword: function(candidatePassword, cb) {
|
||||
bcrypt.compare(candidatePassword, this.local.password, (err, isMatch) => {
|
||||
if (err) return cb(err)
|
||||
cb(null, isMatch)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Statics
|
||||
*/
|
||||
UserSchema.statics = {}
|
||||
|
||||
export default mongoose.model("User", UserSchema)
|
||||
30
account/src/server/public/style/style.css
Normal file
30
account/src/server/public/style/style.css
Normal file
@@ -0,0 +1,30 @@
|
||||
.field {
|
||||
padding-top: 10px;
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
/**
|
||||
* The CSS shown here will not be introduced in the Quickstart guide, but shows
|
||||
* how you can use CSS to style your Element's container.
|
||||
*/
|
||||
.StripeElement {
|
||||
background-color: white;
|
||||
height: 40px;
|
||||
padding: 10px 12px;
|
||||
border-radius: 5px;
|
||||
border: 1px solid rgba(34,36,38,.15);
|
||||
color: rgba(0,0,0,.87);
|
||||
}
|
||||
|
||||
.StripeElement--focus {
|
||||
border-color: #85b7d9;
|
||||
}
|
||||
|
||||
.StripeElement--invalid {
|
||||
border-color: #fa755a;
|
||||
}
|
||||
|
||||
.StripeElement--webkit-autofill {
|
||||
background-color: #fefde5 !important;
|
||||
}
|
||||
18
account/upgrade_db.js
Normal file
18
account/upgrade_db.js
Normal file
@@ -0,0 +1,18 @@
|
||||
db = db.getMongo().getDB( "scanner" );
|
||||
|
||||
|
||||
|
||||
db.users.find().forEach(
|
||||
function(user){
|
||||
|
||||
db.systems.updateMany(
|
||||
{ "user": { $eq: user.email } },
|
||||
{
|
||||
$set: { "userId": user._id, "showScreenName": false },
|
||||
}
|
||||
);
|
||||
|
||||
print("Upgrading: " + user.email);
|
||||
|
||||
|
||||
});
|
||||
56
account/webpack/webpack.config.dev.js
Normal file
56
account/webpack/webpack.config.dev.js
Normal file
@@ -0,0 +1,56 @@
|
||||
var path = require("path")
|
||||
var webpack = require("webpack")
|
||||
var assetsPath = path.join(__dirname, "..", "public", "assets")
|
||||
var publicPath = "/assets/"
|
||||
|
||||
module.exports = {
|
||||
name: "browser",
|
||||
mode: 'development',
|
||||
devtool: "eval-source-map",
|
||||
|
||||
// The base directory (absolute path!) for resolving the entry option.
|
||||
context: path.join(__dirname, "..", "src", "client"),
|
||||
|
||||
entry: {
|
||||
app: [
|
||||
"./client",
|
||||
"webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000&reload=true"
|
||||
]
|
||||
},
|
||||
|
||||
optimization: {
|
||||
minimize: false
|
||||
},
|
||||
|
||||
output: {
|
||||
path: assetsPath,
|
||||
filename: "[name].js",
|
||||
publicPath: publicPath
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.(js|jsx)$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
}],
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: [".js", ".jsx"],
|
||||
modules: [
|
||||
path.resolve('src'),
|
||||
'node_modules',
|
||||
],
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NoEmitOnErrorsPlugin(),
|
||||
new webpack.DefinePlugin({
|
||||
"process.env": {
|
||||
NODE_ENV: JSON.stringify("development")
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
51
account/webpack/webpack.config.prod.js
Normal file
51
account/webpack/webpack.config.prod.js
Normal file
@@ -0,0 +1,51 @@
|
||||
var path = require("path")
|
||||
var webpack = require("webpack")
|
||||
var assetsPath = path.join(__dirname, "..", "public", "assets")
|
||||
var publicPath = "/assets/"
|
||||
|
||||
module.exports = {
|
||||
// The configuration for the client
|
||||
name: "browser",
|
||||
mode: 'production',
|
||||
devtool: "source-map",
|
||||
|
||||
// The base directory (absolute path!) for resolving the entry option.
|
||||
context: path.join(__dirname, "..", "src", "client"),
|
||||
|
||||
optimization: {
|
||||
minimize: true
|
||||
},
|
||||
entry: {
|
||||
app: "./client"
|
||||
},
|
||||
|
||||
output: {
|
||||
path: assetsPath,
|
||||
filename: "[name].min.js",
|
||||
publicPath: publicPath
|
||||
},
|
||||
|
||||
resolve: {
|
||||
extensions: [".js", ".jsx"],
|
||||
modules: [
|
||||
path.resolve('src'),
|
||||
'node_modules',
|
||||
],
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: [{
|
||||
test: /\.(js|jsx)$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel-loader',
|
||||
}],
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
"process.env": {
|
||||
NODE_ENV: JSON.stringify("production")
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
4999
account/yarn.lock
Normal file
4999
account/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
12
admin/.babelrc
Normal file
12
admin/.babelrc
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"presets":
|
||||
["@babel/preset-env",
|
||||
"@babel/react"],
|
||||
"plugins": [
|
||||
"@babel/plugin-proposal-class-properties",
|
||||
["@babel/plugin-transform-runtime", {
|
||||
"regenerator": true
|
||||
}],
|
||||
["lodash", { "id": ["lodash", "semantic-ui-react"] }]
|
||||
]
|
||||
}
|
||||
3
admin/.dockerignore
Normal file
3
admin/.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
lib
|
||||
public
|
||||
36
admin/.gitignore
vendored
Normal file
36
admin/.gitignore
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
lib
|
||||
uploads/
|
||||
|
||||
# Dependency directory
|
||||
node_modules
|
||||
assets
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
21
admin/Dockerfile
Normal file
21
admin/Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
||||
# docker build -t trunk-server-frontend .
|
||||
# do a `git pull` in trunk-server-frontend to update
|
||||
|
||||
FROM node:10
|
||||
|
||||
|
||||
ENV HOME=/home/app
|
||||
|
||||
RUN mkdir -p /home/app
|
||||
COPY ./package.json /tmp
|
||||
RUN cd /tmp && npm install
|
||||
RUN cp -a /tmp/node_modules /home/app
|
||||
|
||||
# add `/usr/src/app/node_modules/.bin` to $PATH
|
||||
ENV PATH /usr/app/node_modules/.bin:$PATH
|
||||
|
||||
WORKDIR $HOME
|
||||
COPY . $HOME/
|
||||
RUN npm run build
|
||||
|
||||
CMD ["npm", "run", "start"]
|
||||
21
admin/LICENSE
Normal file
21
admin/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Frank Kilkelly
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
0
admin/README.md
Normal file
0
admin/README.md
Normal file
10
admin/devStart.js
Normal file
10
admin/devStart.js
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
Called during development only. Allows us to use ES6 and JSX in our server code.
|
||||
*/
|
||||
|
||||
require('@babel/register')({
|
||||
presets: ["@babel/preset-env",
|
||||
"@babel/react"]
|
||||
});
|
||||
|
||||
require("./src/server/index")
|
||||
6915
admin/package-lock.json
generated
Normal file
6915
admin/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
94
admin/package.json
Normal file
94
admin/package.json
Normal file
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"name": "react-passport-redux-example",
|
||||
"version": "1.0.0",
|
||||
"description": "Demonstration of PassportJS authentication in React w/ Redux.",
|
||||
"main": "devStart.js",
|
||||
"scripts": {
|
||||
"build:lib": "babel src/server --out-dir lib/server",
|
||||
"build:umd": "webpack --config webpack/webpack.config.dev.js",
|
||||
"build:umd:min": "webpack --config webpack/webpack.config.prod.js",
|
||||
"build": "npm run clean && npm run build:lib && npm run build:umd && npm run build:umd:min",
|
||||
"postinstall": "npm run build",
|
||||
"clean": "rimraf lib public/assets",
|
||||
"server": "better-npm-run server",
|
||||
"server:dev": "better-npm-run server:dev",
|
||||
"start": "npm run server",
|
||||
"start:dev": "npm run server:dev"
|
||||
},
|
||||
"betterScripts": {
|
||||
"server": {
|
||||
"command": "node lib/server/index.js",
|
||||
"env": {
|
||||
"NODE_ENV": "production",
|
||||
"MIN_EXT": ".min"
|
||||
}
|
||||
},
|
||||
"server:dev": {
|
||||
"command": "node devStart.js",
|
||||
"env": {
|
||||
"NODE_ENV": "development"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "7.3.1",
|
||||
"@vx/axis": "^0.0.184",
|
||||
"@vx/curve": "^0.0.182",
|
||||
"@vx/glyph": "^0.0.183",
|
||||
"@vx/group": "^0.0.183",
|
||||
"@vx/legend": "^0.0.183",
|
||||
"@vx/mock-data": "^0.0.185",
|
||||
"@vx/responsive": "0.0.184",
|
||||
"@vx/scale": "0.0.182",
|
||||
"@vx/shape": "0.0.184",
|
||||
"@vx/tooltip": "0.0.184",
|
||||
"axios": "^0.18.0",
|
||||
"babel-loader": "8.0.5",
|
||||
"bcrypt-nodejs": "^0.0.3",
|
||||
"better-npm-run": "^0.1.0",
|
||||
"body-parser": "^1.18.2",
|
||||
"connect-mongo": "^2.0.1",
|
||||
"connected-react-router": "6.3.1",
|
||||
"csv-parse": "^4.3.3",
|
||||
"d3-time-format": "^2.1.3",
|
||||
"express": "^4.16.2",
|
||||
"express-session": "^1.15.6",
|
||||
"fs-extra": "^7.0.1",
|
||||
"lodash": "4.17.11",
|
||||
"mongoose": "^5.4",
|
||||
"multer": "^1.3.0",
|
||||
"node-mailjet": "*",
|
||||
"node-uuid": "^1.4.8",
|
||||
"passport": "^0.4.0",
|
||||
"passport-local": "^1.0.0",
|
||||
"react": "16.8.2",
|
||||
"react-dom": "16.8.2",
|
||||
"react-redux": "^6.0.0",
|
||||
"react-router": "^4.2.0",
|
||||
"react-router-dom": "^4.2.2",
|
||||
"redux": "^4.0.1",
|
||||
"redux-thunk": "^2.2.0",
|
||||
"semantic-ui-react": "^0.85.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.2.3",
|
||||
"@babel/core": "7.3.3",
|
||||
"@babel/plugin-proposal-class-properties": "7.3.3",
|
||||
"@babel/plugin-proposal-export-default-from": "7.2.0",
|
||||
"@babel/plugin-proposal-object-rest-spread": "7.3.2",
|
||||
"@babel/plugin-transform-runtime": "7.2.0",
|
||||
"@babel/preset-env": "7.3.1",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@babel/preset-stage-1": "^7.0.0",
|
||||
"@babel/register": "^7.0.0",
|
||||
"babel-plugin-lodash": "3.3.4",
|
||||
"detect-node": "2.0.4",
|
||||
"redux-logger": "^3.0.6",
|
||||
"rimraf": "2.6.3",
|
||||
"uglifyjs-webpack-plugin": "2.1.1",
|
||||
"webpack": "4.29.5",
|
||||
"webpack-cli": "3.2.3",
|
||||
"webpack-dev-middleware": "3.5.2",
|
||||
"webpack-hot-middleware": "2.24.3"
|
||||
}
|
||||
}
|
||||
258
admin/src/client/Group/GroupModal.js
Normal file
258
admin/src/client/Group/GroupModal.js
Normal file
@@ -0,0 +1,258 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Modal,
|
||||
Rail,
|
||||
Segment,
|
||||
List,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const requestMessageStyle = {
|
||||
color: "red"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
class GroupModal extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleClose = this.handleClose.bind(this);
|
||||
|
||||
// Set initial state
|
||||
this.state = {
|
||||
editGroup: false,
|
||||
groupName: "",
|
||||
group: {
|
||||
name: "",
|
||||
items: []
|
||||
},
|
||||
talkgroups: this.props.talkgroups ? this.props.talkgroups : []
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
//this.props.groupActions.fetchGroups(this.props.shortName);
|
||||
|
||||
this.props.talkgroupActions.fetchTalkgroups(this.props.shortName);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.talkgroups && nextProps.groups && nextProps.editGroupId) {
|
||||
var editGroup = nextProps.groups.find(
|
||||
group => group._id === nextProps.editGroupId
|
||||
);
|
||||
var items = [];
|
||||
|
||||
var talkgroups = nextProps.talkgroups;
|
||||
for (var i = 0; i < editGroup.talkgroups.length; i++) {
|
||||
const talkgroupId = editGroup.talkgroups[i];
|
||||
const index = talkgroups.findIndex(tg => tg.num === talkgroupId);
|
||||
if (index >= 0) {
|
||||
const item = {
|
||||
num: talkgroups[index].num,
|
||||
description: talkgroups[index].description
|
||||
};
|
||||
items.push(item);
|
||||
talkgroups = talkgroups
|
||||
.slice(0, index)
|
||||
.concat(talkgroups.slice(index + 1));
|
||||
}
|
||||
}
|
||||
const group = {name: editGroup.groupName, items: items}
|
||||
this.setState({group: group, talkgroups: talkgroups, groupName: editGroup.groupName});
|
||||
} else {
|
||||
this.setState({ talkgroups: nextProps.talkgroups })
|
||||
|
||||
}
|
||||
|
||||
if (!nextProps.editGroupId && (this.props.editGroupId != nextProps.editGroupId)) {
|
||||
this.setState({ groupName: "", group: {
|
||||
name: "",
|
||||
items: []
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
||||
removeTalkgroup(event, index) {
|
||||
const item = {
|
||||
num: this.state.group.items[index].num,
|
||||
description: this.state.group.items[index].description
|
||||
};
|
||||
|
||||
const talkgroups = this.state.talkgroups.slice(0); // copy
|
||||
|
||||
for (var i = 0, len = talkgroups.length; i < len; i++) {
|
||||
if (item.num < talkgroups[i].num) {
|
||||
talkgroups.splice(i, 0, item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.setState({
|
||||
group: {
|
||||
items: this.state.group.items
|
||||
.slice(0, index)
|
||||
.concat(this.state.group.items.slice(index + 1))
|
||||
},
|
||||
talkgroups: talkgroups
|
||||
});
|
||||
}
|
||||
|
||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||
|
||||
addTalkgroup(event, index) {
|
||||
const item = {
|
||||
num: this.state.talkgroups[index].num,
|
||||
description: this.state.talkgroups[index].description
|
||||
};
|
||||
|
||||
this.setState({
|
||||
group: { items: this.state.group.items.concat(item) },
|
||||
talkgroups: this.state.talkgroups
|
||||
.slice(0, index)
|
||||
.concat(this.state.talkgroups.slice(index + 1))
|
||||
});
|
||||
}
|
||||
handleClose = () => this.props.onClose(false);
|
||||
handleSubmit() {
|
||||
var talkgroupNums = this.state.group.items.map(a => a.num);
|
||||
const data = {
|
||||
shortName: this.props.shortName,
|
||||
groupName: this.state.groupName,
|
||||
talkgroups: JSON.stringify(talkgroupNums)
|
||||
};
|
||||
if (this.props.editGroupId) {
|
||||
const data = {
|
||||
_id: this.props.editGroupId,
|
||||
shortName: this.props.shortName,
|
||||
groupName: this.state.groupName,
|
||||
talkgroups: JSON.stringify(talkgroupNums)
|
||||
};
|
||||
|
||||
this.props.groupActions.updateGroup(data).then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
this.props.onClose(false);
|
||||
} else {
|
||||
this.props.onClose(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const data = {
|
||||
shortName: this.props.shortName,
|
||||
groupName: this.state.groupName,
|
||||
talkgroups: JSON.stringify(talkgroupNums)
|
||||
};
|
||||
|
||||
this.props.groupActions.createGroup(data).then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
this.props.onClose(false);
|
||||
} else {
|
||||
this.props.onClose(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const talkgroups = this.state.talkgroups;
|
||||
const group = this.state.group.items;
|
||||
const railStyle = {
|
||||
top: "15px",
|
||||
minHeight: "200px"
|
||||
};
|
||||
return (
|
||||
<Modal open={this.props.open} onClose={this.handleClose} centered={false}>
|
||||
<Modal.Header>
|
||||
{this.props.editGroupId ? "Create Group" : "Edit Group"}
|
||||
</Modal.Header>
|
||||
<Modal.Content scrolling>
|
||||
<Modal.Description>
|
||||
<Grid container columns={2}>
|
||||
<Grid.Column>
|
||||
<Table>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Number</Table.HeaderCell>
|
||||
|
||||
<Table.HeaderCell>Description</Table.HeaderCell>
|
||||
<Table.HeaderCell />
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{talkgroups &&
|
||||
talkgroups.map((talkgroup, i) => (
|
||||
<Table.Row link="true" key={talkgroup.num + "-" + i}>
|
||||
<Table.Cell>{talkgroup.num}</Table.Cell>
|
||||
|
||||
<Table.Cell>{talkgroup.description}</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Icon
|
||||
link
|
||||
name="plus"
|
||||
onClick={e => this.addTalkgroup(e, i)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
<Rail position="right">
|
||||
<Segment style={railStyle}>
|
||||
<Input
|
||||
name="groupName"
|
||||
onChange={this.handleInputChange}
|
||||
placeholder="Group Name"
|
||||
value={this.state.groupName}
|
||||
/>
|
||||
<List divided relaxed>
|
||||
{group.map((talkgroup, i) => (
|
||||
<List.Item key={"Group-" + i}>
|
||||
<List.Icon
|
||||
name="remove"
|
||||
verticalAlign="middle"
|
||||
link={true}
|
||||
onClick={e => this.removeTalkgroup(e, i)}
|
||||
/>
|
||||
<List.Content>{talkgroup.description}</List.Content>
|
||||
</List.Item>
|
||||
))}
|
||||
</List>
|
||||
<Button onClick={this.handleSubmit}>
|
||||
<Icon name="checkmark" />{" "}
|
||||
{this.props.editGroupId ? "Update" : "Save"}
|
||||
</Button>
|
||||
</Segment>
|
||||
</Rail>
|
||||
</Grid.Column>
|
||||
</Grid>
|
||||
</Modal.Description>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={this.handleSubmit}>
|
||||
<Icon name="checkmark" />{" "}
|
||||
{this.props.editGroupId ? "Update" : "Save"}
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default GroupModal;
|
||||
26
admin/src/client/Group/GroupModalContainer.js
Normal file
26
admin/src/client/Group/GroupModalContainer.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as groupActionCreators from "./group-actions"
|
||||
import * as talkgroupActionCreators from "../Talkgroups/talkgroup-actions"
|
||||
import { bindActionCreators } from 'redux'
|
||||
import GroupModal from "./GroupModal"
|
||||
|
||||
//groups: state.group.items[props.match.params.shortName],
|
||||
function mapStateToProps(state,props) {
|
||||
return {
|
||||
talkgroups: state.talkgroup.items[props.shortName],
|
||||
groups: state.group.items[props.shortName],
|
||||
shortName: props.shortName
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
groupActions: bindActionCreators(groupActionCreators,dispatch),
|
||||
talkgroupActions: bindActionCreators(talkgroupActionCreators, dispatch)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(GroupModal)
|
||||
82
admin/src/client/Group/ListGroups.js
Normal file
82
admin/src/client/Group/ListGroups.js
Normal file
@@ -0,0 +1,82 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { Link } from 'react-router-dom'
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
class ListGroups extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
||||
render() {
|
||||
const groups = this.props.groups;
|
||||
if (groups) {
|
||||
return (
|
||||
|
||||
<Table >
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Name</Table.HeaderCell>
|
||||
<Table.HeaderCell>Talkgroup Count</Table.HeaderCell>
|
||||
<Table.HeaderCell></Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{groups.map((group, i) => (
|
||||
<Table.Row key={ "Group-" + i}>
|
||||
<Table.Cell>{group.groupName}</Table.Cell>
|
||||
<Table.Cell>{group.talkgroups.length}</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Icon
|
||||
name="pencil alternate"
|
||||
link={true}
|
||||
onClick={e => this.props.editGroup(group._id)}
|
||||
/><Icon
|
||||
name="up arrow"
|
||||
link={true}
|
||||
onClick={e => this.props.reorderGroup(i, i-1)}
|
||||
/><Icon
|
||||
name="down arrow"
|
||||
link={true}
|
||||
onClick={e => this.props.reorderGroup(i, i+1)}
|
||||
/><Icon
|
||||
name="remove"
|
||||
link={true}
|
||||
onClick={e => this.props.deleteGroup(group._id)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div/>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ListGroups;
|
||||
244
admin/src/client/Group/group-actions.js
Normal file
244
admin/src/client/Group/group-actions.js
Normal file
@@ -0,0 +1,244 @@
|
||||
import axios from "axios";
|
||||
//import { browserHistory } from "react-router"
|
||||
import * as types from "./group-constants";
|
||||
import { push } from 'connected-react-router';
|
||||
|
||||
// "Log In" action creators
|
||||
function beginCreateGroup() {
|
||||
return { type: types.CREATE_GROUP };
|
||||
}
|
||||
|
||||
function createGroupSuccess(data) {
|
||||
return {
|
||||
type: types.CREATE_SUCCESS_GROUP,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
function createGroupError(data) {
|
||||
return {
|
||||
type: types.CREATE_ERROR_GROUP,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function beginUpdateGroup() {
|
||||
return { type: types.UPDATE_GROUP };
|
||||
}
|
||||
|
||||
function updateGroupSuccess(data) {
|
||||
return { type: types.UPDATE_SUCCESS_GROUP, data };
|
||||
}
|
||||
|
||||
function updateGroupError() {
|
||||
return { type: types.UPDATE_ERROR_GROUP };
|
||||
}
|
||||
|
||||
|
||||
function beginDeleteGroup() {
|
||||
return { type: types.DELETE_GROUP };
|
||||
}
|
||||
|
||||
function deleteGroupSuccess(data) {
|
||||
return { type: types.DELETE_SUCCESS_GROUP, data };
|
||||
}
|
||||
|
||||
function deleteGroupError() {
|
||||
return { type: types.DELETE_ERROR_GROUP };
|
||||
}
|
||||
|
||||
function beginFetchGroup() {
|
||||
return { type: types.FETCH_GROUP };
|
||||
}
|
||||
|
||||
function fetchGroupSuccess(data) {
|
||||
return {
|
||||
type: types.FETCH_SUCCESS_GROUP,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
function fetchGroupError(data) {
|
||||
return {
|
||||
type: types.FETCH_ERROR_GROUP,
|
||||
data
|
||||
};
|
||||
}
|
||||
|
||||
function saveGroupOrderSuccess() {
|
||||
return { type: types.SAVE_ORDER_SUCCESS_GROUP };
|
||||
}
|
||||
|
||||
function saveGroupOrderError() {
|
||||
return { type: types.SAVE_ORDER_ERROR_GROUP };
|
||||
}
|
||||
|
||||
function makeUserRequest(method, data, api = "/login") {
|
||||
// returns a Promise
|
||||
return axios({
|
||||
method: method,
|
||||
url: api,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
|
||||
export function changeUrl(url) {
|
||||
return dispatch => {
|
||||
dispatch(push(url));
|
||||
};
|
||||
}
|
||||
|
||||
// Example of an Async Action Creator
|
||||
// http://redux.js.org/docs/advanced/AsyncActions.html
|
||||
|
||||
export function updateGroup(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginUpdateGroup());
|
||||
|
||||
return makeUserRequest("post", data, "/groups/" + data.shortName + "/" + data._id)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(updateGroupSuccess(response.data.group));
|
||||
} else {
|
||||
dispatch(updateGroupError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function shouldFetchGroups(state,shortName) {
|
||||
if (!state.group.items || !state.group.items[shortName]) {
|
||||
return true;
|
||||
} else if (state.group.isWaiting) {
|
||||
return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function reorderGroup(shortName, oldIndex, newIndex) {
|
||||
return (dispatch, getState) => {
|
||||
const data = {
|
||||
shortName: shortName,
|
||||
oldIndex: oldIndex,
|
||||
newIndex: newIndex
|
||||
};
|
||||
dispatch({
|
||||
type: types.REORDER_GROUP,
|
||||
data
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function fetchGroups(shortName) {
|
||||
return (dispatch, getState) => {
|
||||
if (shouldFetchGroups(getState(), shortName)) {
|
||||
dispatch(beginFetchGroup());
|
||||
return axios
|
||||
.get("/groups/" + shortName)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const data = { shortName: shortName, groups: response.data.groups };
|
||||
dispatch(fetchGroupSuccess(data));
|
||||
} else {
|
||||
dispatch(fetchGroupError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function saveGroupOrder(shortName, data) {
|
||||
return dispatch => {
|
||||
dispatch({
|
||||
type: types.SAVE_ORDER_GROUP,
|
||||
data
|
||||
});
|
||||
|
||||
return makeUserRequest(
|
||||
"post",
|
||||
data,
|
||||
"/groups/" + shortName + "/reorder"
|
||||
)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(saveGroupOrderSuccess());
|
||||
} else {
|
||||
dispatch(saveGroupOrderError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function deleteGroup(shortName, groupId) {
|
||||
return dispatch => {
|
||||
dispatch(beginDeleteGroup());
|
||||
|
||||
return makeUserRequest("delete", null, "/groups/" + shortName + "/" + groupId)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const data = {shortName: shortName, groupId: groupId}
|
||||
dispatch(deleteGroupSuccess(data));
|
||||
} else {
|
||||
dispatch(deleteGroupError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function createGroup(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginCreateGroup());
|
||||
|
||||
return makeUserRequest("post", data, "/groups/" + data.shortName)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(createGroupSuccess(response.data.group));
|
||||
} else {
|
||||
dispatch(createGroupError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
16
admin/src/client/Group/group-constants.js
Normal file
16
admin/src/client/Group/group-constants.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export const CREATE_GROUP = "CREATE_GROUP"
|
||||
export const CREATE_SUCCESS_GROUP = "CREATE_SUCCESS_GROUP"
|
||||
export const CREATE_ERROR_GROUP = "CREATE_ERROR_GROUP"
|
||||
export const UPDATE_GROUP = "UPDATE_GROUP"
|
||||
export const UPDATE_SUCCESS_GROUP = "UPDATE_SUCCESS_GROUP"
|
||||
export const UPDATE_ERROR_GROUP = "UPDATE_ERROR_GROUP"
|
||||
export const DELETE_GROUP = "DELETE_GROUP"
|
||||
export const DELETE_SUCCESS_GROUP = "DELETE_SUCCESS_GROUP"
|
||||
export const DELETE_ERROR_GROUP = "DELETE_ERROR_GROUP"
|
||||
export const FETCH_GROUP = "FETCH_GROUP"
|
||||
export const FETCH_SUCCESS_GROUP = "FETCH_SUCCESS_GROUP"
|
||||
export const FETCH_ERROR_GROUP = "FETCH_ERROR_GROUP"
|
||||
export const REORDER_GROUP = "REORDER_GROUP"
|
||||
export const SAVE_ORDER_GROUP = "SAVE_ORDER_GROUP"
|
||||
export const SAVE_ORDER_SUCCESS_GROUP = "SAVE_ORDER_SUCCESS_GROUP"
|
||||
export const SAVE_ORDER_ERROR_GROUP = "SAVE_ORDER_ERROR_GROUP"
|
||||
128
admin/src/client/Group/group-reducer.js
Normal file
128
admin/src/client/Group/group-reducer.js
Normal file
@@ -0,0 +1,128 @@
|
||||
import {
|
||||
CREATE_GROUP,
|
||||
CREATE_SUCCESS_GROUP,
|
||||
CREATE_ERROR_GROUP,
|
||||
DELETE_GROUP,
|
||||
DELETE_SUCCESS_GROUP,
|
||||
DELETE_ERROR_GROUP,
|
||||
UPDATE_GROUP,
|
||||
UPDATE_SUCCESS_GROUP,
|
||||
UPDATE_ERROR_GROUP,
|
||||
FETCH_GROUP,
|
||||
FETCH_SUCCESS_GROUP,
|
||||
FETCH_ERROR_GROUP,
|
||||
REORDER_GROUP,
|
||||
SAVE_ORDER_GROUP,
|
||||
SAVE_ORDER_ERROR_GROUP,
|
||||
SAVE_ORDER_SUCCESS_GROUP
|
||||
} from "./group-constants";
|
||||
|
||||
function updateObject(oldObject, newValues) {
|
||||
// Encapsulate the idea of passing a new object as the first parameter
|
||||
// to Object.assign to ensure we correctly copy data instead of mutating
|
||||
return Object.assign({}, oldObject, newValues);
|
||||
}
|
||||
|
||||
function updateItemInArray(array, updatedItem) {
|
||||
const updatedItems = array.map(item => {
|
||||
if(item._id !== updatedItem._id) {
|
||||
// Since we only want to update one item, preserve all others as they are now
|
||||
return item;
|
||||
}
|
||||
return updatedItem;
|
||||
});
|
||||
|
||||
return updatedItems;
|
||||
}
|
||||
|
||||
const group = (
|
||||
state = {
|
||||
orderChange: false,
|
||||
isWaiting: false,
|
||||
items: {}},
|
||||
action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
|
||||
case SAVE_ORDER_GROUP:
|
||||
case CREATE_GROUP:
|
||||
case FETCH_GROUP:
|
||||
case DELETE_GROUP:
|
||||
case UPDATE_GROUP:
|
||||
return Object.assign({}, state, { isWaiting: true});
|
||||
|
||||
case UPDATE_SUCCESS_GROUP:
|
||||
const updatedGroups = updateItemInArray(state.items[action.data.shortName], action.data);
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: {
|
||||
...state.items,
|
||||
[action.data.shortName]: updatedGroups
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
case CREATE_SUCCESS_GROUP:
|
||||
const newGroups = state.items[action.data.shortName].concat(action.data);
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: {
|
||||
...state.items,
|
||||
[action.data.shortName]: newGroups
|
||||
}
|
||||
});
|
||||
|
||||
case DELETE_SUCCESS_GROUP:
|
||||
const delGroups = state.items[action.data.shortName].filter(x => x._id != action.data.groupId);
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: {
|
||||
...state.items,
|
||||
[action.data.shortName]: delGroups
|
||||
}
|
||||
});
|
||||
|
||||
case FETCH_SUCCESS_GROUP:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: {
|
||||
...state.items,
|
||||
[action.data.shortName]: action.data.groups
|
||||
}
|
||||
});
|
||||
|
||||
case SAVE_ORDER_SUCCESS_GROUP:
|
||||
return Object.assign({}, state, {
|
||||
orderChange: false,
|
||||
isWaiting: false
|
||||
});
|
||||
|
||||
case SAVE_ORDER_ERROR_GROUP:
|
||||
case FETCH_ERROR_GROUP:
|
||||
case CREATE_ERROR_GROUP:
|
||||
case DELETE_ERROR_GROUP:
|
||||
case UPDATE_ERROR_GROUP:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false
|
||||
});
|
||||
|
||||
case REORDER_GROUP:
|
||||
if ((action.data.newIndex<0)||(action.data.newIndex>(state.items[action.data.shortName].length-1))) {
|
||||
return state
|
||||
}
|
||||
const moveGroups = state.items[action.data.shortName].slice();
|
||||
moveGroups.splice(action.data.newIndex, 0, moveGroups.splice(action.data.oldIndex, 1)[0]);
|
||||
return Object.assign({}, state, {
|
||||
orderChange: true,
|
||||
items: {
|
||||
...state.items,
|
||||
[action.data.shortName]: moveGroups
|
||||
}
|
||||
});
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default group;
|
||||
150
admin/src/client/Permission/AddPermissionModal.js
Normal file
150
admin/src/client/Permission/AddPermissionModal.js
Normal file
@@ -0,0 +1,150 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Checkbox,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Modal,
|
||||
Rail,
|
||||
Segment,
|
||||
List,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const requestMessageStyle = {
|
||||
color: "red"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
class AddPermissionModal extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleClose = this.handleClose.bind(this);
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
// Set initial state
|
||||
this.state = {
|
||||
role: 5,
|
||||
email: "",
|
||||
error: ""
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
||||
}
|
||||
|
||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||
handleChange = (e, { newRole }) => this.setState({ newRole })
|
||||
|
||||
|
||||
|
||||
|
||||
handleClose = () => {
|
||||
this.setState({
|
||||
error: ""
|
||||
});
|
||||
this.props.onClose(false);
|
||||
}
|
||||
handleSubmit() {
|
||||
//if (this.props.updatePermissionId) {
|
||||
const data = {email: this.state.email, shortName: this.props.shortName, role: this.state.role }
|
||||
|
||||
this.props.permissionActions.addPermission(data).then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
error: requestMessage
|
||||
});
|
||||
//this.props.onClose(false);
|
||||
} else {
|
||||
this.setState({
|
||||
error: ""
|
||||
});
|
||||
this.props.onClose(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
const railStyle = {
|
||||
top: "15px",
|
||||
minHeight: "200px"
|
||||
};
|
||||
var errorMessage = "";
|
||||
|
||||
if (this.state.error) {
|
||||
errorMessage = (
|
||||
<Message negative>
|
||||
<Message.Header>That didn't work...</Message.Header>
|
||||
<p>{this.state.error}</p>
|
||||
</Message>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal size='tiny' open={this.props.open} onClose={this.handleClose} centered={false}>
|
||||
<Modal.Header>Select Role</Modal.Header>
|
||||
<Modal.Content >
|
||||
<Modal.Description>
|
||||
<Form>
|
||||
<Form.Field>
|
||||
Add User Access to System: {this.props.shortName}
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Input label="User's email" placeholder='user@domain.com' name='email' onChange={this.handleInputChange} />
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Checkbox
|
||||
radio
|
||||
label='User'
|
||||
name='role'
|
||||
value={5}
|
||||
checked={(this.state.role >= 0) && (this.state.role < 10)}
|
||||
onChange={this.handleInputChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Checkbox
|
||||
radio
|
||||
label='Admin'
|
||||
name='role'
|
||||
value={15}
|
||||
checked={(this.state.role >= 10) && (this.state.role < 20)}
|
||||
onChange={this.handleInputChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
</Form>
|
||||
{errorMessage}
|
||||
</Modal.Description>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={this.handleClose} >
|
||||
<Icon name='remove' /> Cancel
|
||||
</Button>
|
||||
<Button onClick={this.handleSubmit} >
|
||||
<Icon name='plus' /> Add
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default AddPermissionModal;
|
||||
23
admin/src/client/Permission/AddPermissionModalContainer.js
Normal file
23
admin/src/client/Permission/AddPermissionModalContainer.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as permissionActionCreators from "./permission-actions"
|
||||
import { bindActionCreators } from 'redux'
|
||||
import AddPermissionModal from "./AddPermissionModal"
|
||||
|
||||
//groups: state.group.items[props.match.params.shortName],
|
||||
function mapStateToProps(state,props) {
|
||||
return {
|
||||
permissions: state.permission.items,
|
||||
shortName: props.shortName
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
permissionActions: bindActionCreators(permissionActionCreators,dispatch)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(AddPermissionModal)
|
||||
76
admin/src/client/Permission/ListPermissions.js
Normal file
76
admin/src/client/Permission/ListPermissions.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { Link } from 'react-router-dom'
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
class ListPermissions extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
||||
render() {
|
||||
const permissions = this.props.permissions;
|
||||
if (permissions) {
|
||||
return (
|
||||
|
||||
<Table >
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Name</Table.HeaderCell>
|
||||
<Table.HeaderCell>Email</Table.HeaderCell>
|
||||
<Table.HeaderCell>Role</Table.HeaderCell>
|
||||
<Table.HeaderCell></Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
<Table.Body>
|
||||
{permissions.map((permission, i) => (
|
||||
<Table.Row key={ "Group-" + i}>
|
||||
<Table.Cell>{permission.firstName} {permission.lastName}</Table.Cell>
|
||||
<Table.Cell>{permission.email}</Table.Cell>
|
||||
<Table.Cell>{permission.role}</Table.Cell>
|
||||
<Table.Cell><Icon
|
||||
name="pencil alternate"
|
||||
link={true}
|
||||
onClick={e => this.props.updatePermission(permission._id)}
|
||||
/>
|
||||
<Icon
|
||||
name="remove"
|
||||
link={true}
|
||||
onClick={e => this.props.deletePermission(permission)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div/>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ListPermissions;
|
||||
134
admin/src/client/Permission/UpdatePermissionModal.js
Normal file
134
admin/src/client/Permission/UpdatePermissionModal.js
Normal file
@@ -0,0 +1,134 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Checkbox,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Modal,
|
||||
Rail,
|
||||
Segment,
|
||||
List,
|
||||
Input,
|
||||
Button,
|
||||
Message,
|
||||
Icon,
|
||||
Table
|
||||
} from "semantic-ui-react";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const requestMessageStyle = {
|
||||
color: "red"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
class UpdatePermissionModal extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleClose = this.handleClose.bind(this);
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
// Set initial state
|
||||
this.state = {
|
||||
newRole: false,
|
||||
permission: false
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
||||
if (nextProps.permissions && nextProps.updatePermissionId) {
|
||||
var updatePermission = nextProps.permissions.find(permission=> permission._id === nextProps.updatePermissionId);
|
||||
|
||||
if (updatePermission) {
|
||||
this.setState({permission: updatePermission, newRole: updatePermission.role});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleChange = (e, { name, value }) => this.setState({ newRole: value })
|
||||
|
||||
|
||||
|
||||
|
||||
handleClose = () => this.props.onClose(false);
|
||||
handleSubmit() {
|
||||
if (this.props.updatePermissionId) {
|
||||
const data = {permissionId: this.props.updatePermissionId, shortName: this.props.shortName, role: this.state.newRole }
|
||||
|
||||
this.props.permissionActions.update(data).then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
this.props.onClose(false);
|
||||
} else {
|
||||
this.props.onClose(true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
const railStyle = {
|
||||
top: "15px",
|
||||
minHeight: "200px"
|
||||
};
|
||||
var user = ""
|
||||
if (this.state.permission) {
|
||||
user = this.state.permission.email
|
||||
}
|
||||
return (
|
||||
<Modal size='tiny' open={this.props.open} onClose={this.handleClose} centered={false}>
|
||||
<Modal.Header>Select Role</Modal.Header>
|
||||
<Modal.Content >
|
||||
<Modal.Description>
|
||||
<Form>
|
||||
<Form.Field>
|
||||
Set role for <b>{user}</b>:
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Checkbox
|
||||
radio
|
||||
label='User'
|
||||
name='checkboxRadioGroup'
|
||||
value={5}
|
||||
checked={(this.state.newRole >= 0) && (this.state.newRole < 10)}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
<Form.Field>
|
||||
<Checkbox
|
||||
radio
|
||||
label='Admin'
|
||||
name='checkboxRadioGroup'
|
||||
value={15}
|
||||
checked={(this.state.newRole >= 10) && (this.state.newRole < 20)}
|
||||
onChange={this.handleChange}
|
||||
/>
|
||||
</Form.Field>
|
||||
</Form>
|
||||
|
||||
</Modal.Description>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={this.handleSubmit} >
|
||||
<Icon name='checkmark' /> Update
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default UpdatePermissionModal;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as permissionActionCreators from "./permission-actions"
|
||||
import { bindActionCreators } from 'redux'
|
||||
import UpdatePermissionModal from "./UpdatePermissionModal"
|
||||
|
||||
//groups: state.group.items[props.match.params.shortName],
|
||||
function mapStateToProps(state,props) {
|
||||
return {
|
||||
permissions: state.permission.items,
|
||||
shortName: props.shortName
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
permissionActions: bindActionCreators(permissionActionCreators,dispatch)
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(UpdatePermissionModal)
|
||||
166
admin/src/client/Permission/permission-actions.js
Normal file
166
admin/src/client/Permission/permission-actions.js
Normal file
@@ -0,0 +1,166 @@
|
||||
import axios from "axios";
|
||||
//import { browserHistory } from "react-router"
|
||||
import * as types from "./permission-constants";
|
||||
|
||||
function beginAddPermission() {
|
||||
return { type: types.ADD_PERMISSION };
|
||||
}
|
||||
|
||||
function addPermissionSuccess(data) {
|
||||
return { type: types.ADD_PERMISSION_SUCCESS, data };
|
||||
}
|
||||
|
||||
function addPermissionError() {
|
||||
return { type: types.ADD_PERMISSION_ERROR };
|
||||
}
|
||||
|
||||
function beginDeletePermission() {
|
||||
return { type: types.DELETE_PERMISSION };
|
||||
}
|
||||
|
||||
function deletePermissionSuccess(data) {
|
||||
return { type: types.DELETE_PERMISSION_SUCCESS, data };
|
||||
}
|
||||
|
||||
function deletePermissionError() {
|
||||
return { type: types.DELETE_PERMISSION_ERROR };
|
||||
}
|
||||
|
||||
|
||||
function beginUpdateRole() {
|
||||
return { type: types.UPDATE_ROLE };
|
||||
}
|
||||
|
||||
function updateRoleSuccess(data) {
|
||||
return { type: types.UPDATE_ROLE_SUCCESS, data };
|
||||
}
|
||||
|
||||
function updateRoleError() {
|
||||
return { type: types.UPDATE_ROLE_ERROR };
|
||||
}
|
||||
|
||||
// "Log In" action creators
|
||||
function beginFetchPermission() {
|
||||
return { type: types.FETCH_PERMISSION };
|
||||
}
|
||||
|
||||
function fetchPermissionError(data) {
|
||||
return { type: types.FETCH_ERROR_PERMISSION,
|
||||
data };
|
||||
}
|
||||
|
||||
function fetchPermissionSuccess(data) {
|
||||
return { type: types.FETCH_SUCCESS_PERMISSION,
|
||||
data };
|
||||
}
|
||||
|
||||
function shouldFetch(state) {
|
||||
if ((!state.permission.items) || (state.permission.items.length <1)) {
|
||||
return true
|
||||
} else if (state.permission.isWaiting) {
|
||||
return false
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function fetch(shortName) {
|
||||
return (dispatch, getState) => {
|
||||
if (shouldFetch(getState())) {
|
||||
dispatch(beginFetchPermission());
|
||||
|
||||
return axios
|
||||
.get("/permissions/"+shortName)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(fetchPermissionSuccess(response.data.permissions));
|
||||
} else {
|
||||
dispatch(fetchPermissionError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function update(data) {
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch(beginUpdateRole());
|
||||
var url = "/permissions/" + data.shortName + "/" + data.permissionId;
|
||||
return axios.post( url, data)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(updateRoleSuccess(response.data.permission));
|
||||
} else {
|
||||
dispatch(updateRoleError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
export function addPermission(data) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(beginAddPermission());
|
||||
var url = "/permissions/" + data.shortName;
|
||||
return axios.post( url, data)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(addPermissionSuccess(response.data.permission));
|
||||
} else {
|
||||
dispatch(addPermissionError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function deletePermission(data) {
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch(beginDeletePermission());
|
||||
var url = "/permissions/" + data.shortName + "/" + data.permissionId;
|
||||
return axios.delete( url)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
dispatch(deletePermissionSuccess(data.permissionId));
|
||||
} else {
|
||||
dispatch(deletePermissionError());
|
||||
let registerMessage = response.data.message;
|
||||
return registerMessage;
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
12
admin/src/client/Permission/permission-constants.js
Normal file
12
admin/src/client/Permission/permission-constants.js
Normal file
@@ -0,0 +1,12 @@
|
||||
export const ADD_PERMISSION = "ADD_PERMISSION"
|
||||
export const ADD_PERMISSION_ERROR = "ADD_PERMISSION_ERROR"
|
||||
export const ADD_PERMISSION_SUCCESS = "ADD_PERMISSION_SUCCESS"
|
||||
export const FETCH_PERMISSION = "FETCH_PERMISSION"
|
||||
export const FETCH_ERROR_PERMISSION = "FETCH_ERROR_PERMISSION"
|
||||
export const FETCH_SUCCESS_PERMISSION = "FETCH_SUCCESS_PERMISSION"
|
||||
export const UPDATE_ROLE = "UPDATE_ROLE"
|
||||
export const UPDATE_ROLE_ERROR = "UPDATE_ROLE_ERROR"
|
||||
export const UPDATE_ROLE_SUCCESS = "UPDATE_ROLE SUCCESS"
|
||||
export const DELETE_PERMISSION = "DELETE_PERMISSION"
|
||||
export const DELETE_PERMISSION_ERROR = "DELETE_PERMISSION_ERROR"
|
||||
export const DELETE_PERMISSION_SUCCESS = "DELETE_PERMISSION_SUCCESS"
|
||||
87
admin/src/client/Permission/permission-reducer.js
Normal file
87
admin/src/client/Permission/permission-reducer.js
Normal file
@@ -0,0 +1,87 @@
|
||||
import {
|
||||
ADD_PERMISSION,
|
||||
ADD_PERMISSION_SUCCESS,
|
||||
ADD_PERMISSION_ERROR,
|
||||
DELETE_PERMISSION,
|
||||
DELETE_PERMISSION_SUCCESS,
|
||||
DELETE_PERMISSION_ERROR,
|
||||
FETCH_PERMISSION,
|
||||
FETCH_SUCCESS_PERMISSION,
|
||||
FETCH_ERROR_PERMISSION,
|
||||
UPDATE_ROLE,
|
||||
UPDATE_ROLE_ERROR,
|
||||
UPDATE_ROLE_SUCCESS
|
||||
} from "./permission-constants";
|
||||
|
||||
function updateRoleInArray(array, updatedItem) {
|
||||
const updatedItems = array.map(item => {
|
||||
if(item._id !== updatedItem._id) {
|
||||
// Since we only want to update one item, preserve all others as they are now
|
||||
return item;
|
||||
}
|
||||
item.role = updatedItem.role;
|
||||
return item;
|
||||
});
|
||||
|
||||
return updatedItems;
|
||||
}
|
||||
|
||||
function deleteItemInArray(array, _id) {
|
||||
const updatedItems = array.filter(function (item) {
|
||||
return item._id !== _id;
|
||||
});
|
||||
|
||||
return updatedItems;
|
||||
}
|
||||
|
||||
const permission = (
|
||||
state = {
|
||||
isWaiting: false,
|
||||
items: []
|
||||
},
|
||||
action
|
||||
) => {
|
||||
switch (action.type) {
|
||||
|
||||
|
||||
case ADD_PERMISSION_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: [...state.items, action.data]
|
||||
});
|
||||
case DELETE_PERMISSION_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: deleteItemInArray(state.items, action.data)
|
||||
});
|
||||
case UPDATE_ROLE_SUCCESS:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: updateRoleInArray(state.items, action.data)
|
||||
});
|
||||
case FETCH_SUCCESS_PERMISSION:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false,
|
||||
items: action.data
|
||||
});
|
||||
|
||||
case DELETE_PERMISSION_ERROR:
|
||||
case ADD_PERMISSION_ERROR:
|
||||
case UPDATE_ROLE_ERROR:
|
||||
case FETCH_ERROR_PERMISSION:
|
||||
return Object.assign({}, state, {
|
||||
isWaiting: false
|
||||
});
|
||||
|
||||
case DELETE_PERMISSION:
|
||||
case ADD_PERMISSION:
|
||||
case UPDATE_ROLE:
|
||||
case FETCH_PERMISSION:
|
||||
return Object.assign({}, state, { isWaiting: true});
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default permission;
|
||||
100
admin/src/client/System/CallChart.js
Normal file
100
admin/src/client/System/CallChart.js
Normal file
@@ -0,0 +1,100 @@
|
||||
import React, { Component } from "react";
|
||||
import { Group } from '@vx/group';
|
||||
import { curveStep} from '@vx/curve';
|
||||
import { LinePath } from '@vx/shape';
|
||||
import { scaleLinear, scaleBand, scaleTime } from '@vx/scale';
|
||||
import { timeParse, timeFormat } from 'd3-time-format';
|
||||
import { AxisBottom, AxisLeft } from '@vx/axis';
|
||||
import { Dimmer, Loader } from "semantic-ui-react";
|
||||
|
||||
|
||||
class CallChart extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
var callData = this.props.data;
|
||||
if (!callData) {
|
||||
return (
|
||||
|
||||
<Loader size='large'>Loading</Loader>
|
||||
|
||||
)
|
||||
}
|
||||
var callTotals = [];
|
||||
var errorTotals = [];
|
||||
|
||||
// Define the graph dimensions and margins
|
||||
const width = this.props.width;
|
||||
const height = 500;
|
||||
const margin = { top: 20, bottom: 40, left: 40, right: 20 };
|
||||
|
||||
// Then we'll create some bounds
|
||||
const xMax = width - margin.left - margin.right;
|
||||
const yMax = height - margin.top - margin.bottom;
|
||||
|
||||
// accessors
|
||||
const x = d => d.x;
|
||||
const y = d => d.y;
|
||||
|
||||
|
||||
|
||||
// Compose together the scale and accessor functions to get point functions
|
||||
const dotColor = n => {
|
||||
var colores_g = ["#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00", "#b82e2e", "#316395", "#994499", "#22aa99", "#aaaa11", "#6633cc", "#e67300", "#8b0707", "#651067", "#329262", "#5574a6", "#3b3eac"];
|
||||
return colores_g[n % colores_g.length];
|
||||
}
|
||||
|
||||
const compose = (scale, accessor) => (data) => scale(accessor(data));
|
||||
var xScale, yScale, xPoint, yPoint;
|
||||
if (callData) {
|
||||
// We'll use some mock data from `@vx/mock-data` for this.
|
||||
callTotals = callData.callTotals;
|
||||
errorTotals = callData.errorTotals;
|
||||
// scales
|
||||
xScale = scaleTime({
|
||||
range: [0, xMax],
|
||||
domain: [callData.minDate, callData.maxDate],
|
||||
tickFormat: () => (val) => formatDate(val)
|
||||
});
|
||||
yScale = scaleLinear({
|
||||
range: [yMax, 0],
|
||||
domain: [0, callData.maxValue],
|
||||
});
|
||||
xPoint = compose(xScale, x);
|
||||
yPoint = compose(yScale, y);
|
||||
}
|
||||
|
||||
return (
|
||||
<svg width={width} height={height}>
|
||||
<Group left={margin.left} top={margin.top} >
|
||||
<AxisBottom top={yMax} scale={xScale} numTicks={width > 520 ? 10 : 5} />
|
||||
<AxisLeft scale={yScale} />
|
||||
<LinePath
|
||||
data={callTotals}
|
||||
xScale={xScale}
|
||||
yScale={yScale}
|
||||
x={x}
|
||||
y={y}
|
||||
strokeWidth={2}
|
||||
curve={curveStep}
|
||||
/>
|
||||
<LinePath
|
||||
data={errorTotals}
|
||||
xScale={xScale}
|
||||
yScale={yScale}
|
||||
x={x}
|
||||
y={y}
|
||||
strokeWidth={2}
|
||||
stroke="red"
|
||||
curve={curveStep}
|
||||
/>
|
||||
</Group>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
export default CallChart;
|
||||
82
admin/src/client/System/CreateSystem.js
Normal file
82
admin/src/client/System/CreateSystem.js
Normal file
@@ -0,0 +1,82 @@
|
||||
import React, { Component } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Form,
|
||||
Grid,
|
||||
Segment,
|
||||
Input,
|
||||
Button,
|
||||
Divider,
|
||||
Message,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
|
||||
import SystemForm from "./SystemForm";
|
||||
|
||||
// ----------------------------------------------------
|
||||
const requestMessageStyle = {
|
||||
color: "red"
|
||||
};
|
||||
|
||||
// ----------------------------------------------------
|
||||
class CreateSystem extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
|
||||
}
|
||||
|
||||
state = {
|
||||
requestMessage: ""
|
||||
}
|
||||
|
||||
|
||||
|
||||
handleSubmit(system) {
|
||||
this.props
|
||||
.createSystem(system)
|
||||
.then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
} else {
|
||||
this.props.changeUrl("/list-systems")
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Container text>
|
||||
<Header as="h2">Join Us!</Header>
|
||||
<p>
|
||||
Record the your community's radio systems and share them! All it
|
||||
takes is a spare computer and a cheap SDR. The software you need,
|
||||
along with an explanation of how to set it up, is available{" "}
|
||||
<a href="https://github.com/robotastic/trunk-recorder">here</a>.
|
||||
</p>
|
||||
<p>
|
||||
After you have the Trunk Recorder software up and running, come
|
||||
back here and sign-up for an account so you can share your
|
||||
recordings
|
||||
</p>
|
||||
<p> - Luke</p>
|
||||
<Divider />
|
||||
<p></p>
|
||||
</Container>
|
||||
|
||||
<Container text>
|
||||
<Header as="h1">Create System</Header>
|
||||
<SystemForm onSubmit={this.handleSubmit} requestMessage={this.state.requestMessage} screenName={this.props.user.screenName}/>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default CreateSystem;
|
||||
14
admin/src/client/System/CreateSystemContainer.js
Normal file
14
admin/src/client/System/CreateSystemContainer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { connect } from "react-redux"
|
||||
import * as systemActions from "./system-actions"
|
||||
import CreateSystem from "./CreateSystem"
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
user: state.user
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
systemActions
|
||||
)(CreateSystem)
|
||||
48
admin/src/client/System/EditSystem.js
Normal file
48
admin/src/client/System/EditSystem.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import React, { Component } from "react"
|
||||
import SystemForm from "./SystemForm";
|
||||
import {
|
||||
Container,
|
||||
Header
|
||||
} from "semantic-ui-react";
|
||||
|
||||
class EditSystem extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSystemSubmit = this.handleSystemSubmit.bind(this);
|
||||
}
|
||||
|
||||
state = {
|
||||
requestMessage: ""
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { dispatch } = this.props
|
||||
this.props.fetchSystems()
|
||||
}
|
||||
|
||||
handleSystemSubmit(system) {
|
||||
this.props
|
||||
.updateSystem(system)
|
||||
.then(requestMessage => {
|
||||
if (requestMessage) {
|
||||
// report to the user is there was a problem during registration
|
||||
this.setState({
|
||||
requestMessage
|
||||
});
|
||||
} else {
|
||||
this.props.changeUrl("/system/"+system.shortName)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return(
|
||||
<Container text>
|
||||
<Header as="h1">Update System</Header>
|
||||
<SystemForm onSubmit={this.handleSystemSubmit} system={this.props.system} isEditing={true} requestMessage={this.state.requestMessage} screenName={this.props.user.screenName}/>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default EditSystem
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user