mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-14 01:37:48 -05:00
mostly seems to be working!
This commit is contained in:
@@ -1 +1,2 @@
|
||||
/node_modules
|
||||
/node_modules
|
||||
/build
|
||||
File diff suppressed because one or more lines are too long
@@ -1,12 +0,0 @@
|
||||
REACT_APP_BACKEND_SERVER=https://api.openmhz.com
|
||||
REACT_APP_FRONTEND_SERVER=https://openmhz.com
|
||||
REACT_APP_SOCKET_SERVER=wss://api.openmhz.com
|
||||
REACT_APP_ACCOUNT_SERVER=https://account.openmhz.com
|
||||
REACT_APP_ADMIN_SERVER=localhost:3000
|
||||
REACT_APP_ADMIN_EMAIL=luke@robotastic.com
|
||||
REACT_APP_SITE_NAME=OpenMHz
|
||||
REACT_APP_ARCHIVE_DAYS=30
|
||||
REACT_APP_PRO_PLAN=1
|
||||
REACT_APP_FREE_PLAN=0
|
||||
REACT_APP_PRO_PLAN_ARCHIVE=30
|
||||
REACT_APP_FREE_PLAN_ARCHIVE=7
|
||||
@@ -2,11 +2,19 @@
|
||||
FROM node:13.12.0-alpine as build
|
||||
WORKDIR /app
|
||||
ENV PATH /app/node_modules/.bin:$PATH
|
||||
ARG REACT_APP_BACKEND_SERVER
|
||||
ARG REACT_APP_ADMIN_SERVER
|
||||
ARG REACT_APP_ACCOUNT_SERVER
|
||||
ARG REACT_APP_FRONTEND_SERVER
|
||||
ARG REACT_APP_SITE_NAME
|
||||
ARG REACT_APP_ADMIN_EMAIL
|
||||
ARG NODE_ENV
|
||||
COPY package.json ./
|
||||
RUN npm install
|
||||
RUN npm install react-scripts@3.4.1 -g --silent
|
||||
COPY . ./
|
||||
RUN npm run build
|
||||
RUN env
|
||||
|
||||
# production environment
|
||||
FROM node:13.12.0-alpine
|
||||
@@ -14,6 +22,7 @@ RUN mkdir -p /app/public
|
||||
COPY ./package.json /tmp
|
||||
RUN cd /tmp && npm install
|
||||
RUN cp -a /tmp/node_modules /app
|
||||
RUN env
|
||||
WORKDIR /app
|
||||
COPY server /app
|
||||
COPY --from=build /app/build /app/public
|
||||
|
||||
@@ -6,8 +6,12 @@ const connectMongo = require("connect-mongo");
|
||||
const secrets = require("./secrets");
|
||||
|
||||
const MongoStore = connectMongo(session)
|
||||
var cookie_domain = process.env['COOKIE_DOMAIN'] != null ? process.env['COOKIE_DOMAIN'] : '.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
|
||||
var cookie_domain = process.env['REACT_APP_COOKIE_DOMAIN'] != null ? process.env['REACT_APP_COOKIE_DOMAIN'] : '.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
var backend_server = process.env['REACT_APP_BACKEND_SERVER'] != null ? process.env['REACT_APP_BACKEND_SERVER'] : 'https://api.openmhz.com';
|
||||
var frontend_server = process.env['REACT_APP_FRONTEND_SERVER'] != null ? process.env['REACT_APP_FRONTEND_SERVER'] : 'https://openmhz.com';
|
||||
var socket_server = process.env['REACT_APP_SOCKET_SERVER'] != null ? process.env['REACT_APP_SOCKET_SERVER'] : 'wss://socket.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
var account_server = process.env['REACT_APP_ACCOUNT_SERVER'] != null ? process.env['REACT_APP_ACCOUNT_SERVER'] : 'https://account.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
var dev_server = frontend_server + ":3000"
|
||||
|
||||
module.exports = function(app, passport) {
|
||||
app.set("port", 3009)
|
||||
@@ -22,7 +26,6 @@ module.exports = function(app, passport) {
|
||||
app.use(express.static(path.join(process.cwd(), 'public')));
|
||||
|
||||
const sess = {
|
||||
secret: 'secret',
|
||||
/*saveUninitialized: false,
|
||||
resave: false,*/
|
||||
resave: true,
|
||||
@@ -56,5 +59,34 @@ module.exports = function(app, passport) {
|
||||
|
||||
app.use(passport.initialize())
|
||||
app.use(passport.session())
|
||||
|
||||
app.use('/*', function(req, res, next) {
|
||||
var allowedOrigins = [ account_server];
|
||||
allowedOrigins.push(frontend_server);
|
||||
allowedOrigins.push(backend_server);
|
||||
allowedOrigins.push(socket_server);
|
||||
allowedOrigins.push(dev_server);
|
||||
var origin = req.headers.origin;
|
||||
|
||||
|
||||
if (allowedOrigins.indexOf(origin) > -1) {
|
||||
res.setHeader('Access-Control-Allow-Origin', origin);
|
||||
} else if (req.headers["user-agent"] == 'TrunkRecorder1.0') {
|
||||
res.setHeader('Access-Control-Allow-Origin', "*");
|
||||
} else {
|
||||
res.setHeader('Access-Control-Allow-Origin', "*");
|
||||
if (origin) {
|
||||
console.warn("forcing CORS for: " + origin + " referer: " + req.headers.referer);
|
||||
}
|
||||
}
|
||||
res.header("Access-Control-Allow-Headers", "X-Requested-With");
|
||||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS,WEBSOCKET');
|
||||
res.header('Access-Control-Allow-Credentials', 'true');
|
||||
res.header("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Access-Control-Allow-Credentials, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Access-Control-Max-Age");
|
||||
res.header('Access-Control-Max-Age', '600');
|
||||
next();
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,11 +21,15 @@ const local = new LocalStrategy({
|
||||
}
|
||||
}]
|
||||
}, (err, user) => {
|
||||
if(!user) return done(null, false, { message: `Email ${email} not found` })
|
||||
if(!user) {
|
||||
console.error("Auth Error - user not found: " + email);
|
||||
return done(null, false, { message: `Invalid email or password` })
|
||||
}
|
||||
user.comparePassword(password, (err, isMatch) => {
|
||||
if (isMatch) {
|
||||
return done(null, user)
|
||||
} else {
|
||||
console.error("Auth Error - password mismatch: " + email);
|
||||
return done(null, false, { message: "Invalid email or password" })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -7,10 +7,10 @@ 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';
|
||||
var admin_email = process.env['REACT_APP_ADMIN_EMAIL'] != null ? process.env['REACT_ADMIN_ADMIN_EMAIL'] : "luke@openmhz.com";
|
||||
var site_name = process.env['REACT_APP_SITE_NAME'] != null ? process.env['REACT_APP_SITE_NAME'] : "OpenMHz";
|
||||
var account_server = process.env['REACT_APP_ACCOUNT_SERVER'] != null ? process.env['REACT_APP_ACCOUNT_SERVER'] : "https://account.openmhz.com";
|
||||
var cookie_domain = process.env['REACT_APP_COOKIE_DOMAIN'] != null ? process.env['REACT_APP_COOKIE_DOMAIN'] : '.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
|
||||
exports.isLoggedIn = function (req, res, next) {
|
||||
if (req.isAuthenticated()) return next();
|
||||
|
||||
@@ -7,10 +7,10 @@ process.env['MAILJET_KEY'],
|
||||
);
|
||||
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';
|
||||
var admin_email = process.env['REACT_APP_ADMIN_EMAIL'] != null ? process.env['REACT_APP_ADMIN_EMAIL'] : "luke@openmhz.com";
|
||||
var site_name = process.env['REACT_APP_SITE_NAME'] != null ? process.env['REACT_APP_SITE_NAME'] : "OpenMHz";
|
||||
var account_server = process.env['REACT_APP_ACCOUNT_SERVER'] != null ? process.env['REACT_APP_ACCOUNT_SERVER'] : "https://account.openmhz.com";
|
||||
var cookie_domain = process.env['REACT_APP_COOKIE_DOMAIN'] != null ? process.env['REACT_APP_COOKIE_DOMAIN'] : '.openmhz.com'; //'https://s3.amazonaws.com/robotastic';
|
||||
|
||||
exports.isLoggedIn = function(req, res, next) {
|
||||
if (req.isAuthenticated()) return next();
|
||||
@@ -21,8 +21,7 @@ exports.isLoggedIn = function(req, res, next) {
|
||||
|
||||
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);
|
||||
console.log("account/server/controllers/users.js - exports.authenticated() Auth check for user: " + req.user + " is: " + req.isAuthenticated());
|
||||
if (req.isAuthenticated()) {
|
||||
var clientUser = (({
|
||||
firstName,
|
||||
@@ -42,11 +41,7 @@ exports.authenticated = function(req, res, next) {
|
||||
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
|
||||
@@ -93,7 +88,7 @@ exports.login = function(req, res, next) {
|
||||
userId: user.id
|
||||
});
|
||||
}
|
||||
console.log(user);
|
||||
console.log("account/server/controllers/users.js - req.login() Authenicated: " + user.email);
|
||||
// go ahead and create the new user
|
||||
var clientUser = (({
|
||||
firstName,
|
||||
@@ -454,6 +449,7 @@ exports.terms = function(req, res, next) {
|
||||
|
||||
|
||||
exports.validateProfile = function(req, res, next) {
|
||||
console.log("Validating user profile: "+ req.body.email);
|
||||
if (!req.body.firstName || (req.body.firstName.length < 2)) {
|
||||
console.error("ERROR: Validate System - req.body.firstName");
|
||||
res.json({
|
||||
@@ -549,6 +545,8 @@ exports.updateProfile = function(req, res, next) {
|
||||
// -------------------------------------------
|
||||
|
||||
exports.register = function(req, res, next) {
|
||||
console.log("Registration request for: " + req.body.email);
|
||||
|
||||
User.findOne({
|
||||
$or: [{
|
||||
email: req.body.email
|
||||
@@ -585,16 +583,16 @@ exports.register = function(req, res, next) {
|
||||
);
|
||||
user.password = req.body.password;
|
||||
user.email = req.body.email;
|
||||
|
||||
|
||||
User.create(user).then(function(dbUser) {
|
||||
console.log(dbUser);
|
||||
console.log("Successfully registered: " + dbUser.email + ", now sending confirmation email.");
|
||||
// Since regiestration worked, send a confirmation email.
|
||||
return handleSendConfirmEmail(dbUser);
|
||||
}).then(function(result) {
|
||||
res.json(result);
|
||||
return;
|
||||
}).catch(function(err) {
|
||||
console.error(err);
|
||||
console.error("Error creating user: " + user.email + " Error: " +err);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
|
||||
@@ -15,19 +15,44 @@ const app = express()
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
const connect = () => {
|
||||
mongoose.connect(secrets.db, (err, res) => {
|
||||
async function connect() {
|
||||
|
||||
// Demonstrate the readyState and on event emitters
|
||||
console.log(mongoose.connection.readyState); //logs 0
|
||||
mongoose.connection.on('connecting', () => {
|
||||
console.log('Mongoose is connecting')
|
||||
console.log(mongoose.connection.readyState); //logs 2
|
||||
});
|
||||
mongoose.connection.on('connected', () => {
|
||||
console.log('Mongoose is connected');
|
||||
console.log(mongoose.connection.readyState); //logs 1
|
||||
});
|
||||
mongoose.connection.on('disconnecting', () => {
|
||||
console.log('Mongoose is disconnecting');
|
||||
console.log(mongoose.connection.readyState); // logs 3
|
||||
});
|
||||
|
||||
// Connect to a MongoDB server running on 'localhost:27017' and use the
|
||||
// 'test' database.
|
||||
await mongoose.connect(secrets.db, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true }, (err, res) => {
|
||||
if (err) {
|
||||
console.log(`Error connecting to ${secrets.db}. ${err}`)
|
||||
console.log(`Mongoose - Error connecting to ${secrets.db}. ${err}`)
|
||||
} else {
|
||||
console.log(`Successfully connected to ${secrets.db}.`)
|
||||
console.log(`Mongoose Successfully connected to ${secrets.db}.`)
|
||||
}
|
||||
})
|
||||
console.log("All Done");
|
||||
}
|
||||
connect()
|
||||
|
||||
mongoose.connection.on("error", console.error)
|
||||
mongoose.connection.on("disconnected", connect)
|
||||
connect();
|
||||
mongoose.connection.on('error', err => {
|
||||
console.error("Mongoose Error!")
|
||||
console.error(err);
|
||||
});
|
||||
mongoose.connection.on('disconnected', () => {
|
||||
console.log('Mongoose disconnected');
|
||||
console.log(mongoose.connection.readyState); //logs 0
|
||||
connect();
|
||||
});
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ const UserSchema = new mongoose.Schema({
|
||||
/**
|
||||
* Password hash middleware.
|
||||
*/
|
||||
/*
|
||||
UserSchema.pre("save", function(next) {
|
||||
var user = this
|
||||
if (!user.isModified("password")) return next()
|
||||
@@ -70,11 +71,23 @@ UserSchema.pre("save", function(next) {
|
||||
next()
|
||||
})
|
||||
})
|
||||
})
|
||||
})*/
|
||||
|
||||
UserSchema.pre("save", function(next) {
|
||||
if(!this.isModified("password")) {
|
||||
return next();
|
||||
}
|
||||
hashed = bcrypt.hashSync(this.password, 8);
|
||||
this.password = hashed;
|
||||
this.local.password = hashed;
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
/*
|
||||
Defining our own custom document instance method
|
||||
*/
|
||||
/*
|
||||
UserSchema.methods = {
|
||||
comparePassword: function(candidatePassword, cb) {
|
||||
bcrypt.compare(candidatePassword, this.local.password, (err, isMatch) => {
|
||||
@@ -82,7 +95,12 @@ UserSchema.pre("save", function(next) {
|
||||
cb(null, isMatch)
|
||||
})
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
UserSchema.methods.comparePassword = function(plaintext, callback) {
|
||||
return callback(null, bcrypt.compareSync(plaintext, this.local.password));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Statics
|
||||
|
||||
@@ -23,7 +23,7 @@ class Navigation extends Component {
|
||||
{this.props.user.authenticated ? (
|
||||
<Menu style={navStyle}>
|
||||
<Menu.Item name="systems" header>
|
||||
OpenMHz
|
||||
{process.env.REACT_APP_SITE_NAME}
|
||||
</Menu.Item>
|
||||
<Menu.Menu position="right">
|
||||
{/* <Link to="/update-plans">
|
||||
|
||||
@@ -156,7 +156,7 @@ export function manualLogin(
|
||||
return dispatch => {
|
||||
dispatch(beginLogin());
|
||||
|
||||
return makeUserRequest("post", data, "/login", { withCredentials: true })
|
||||
return makeUserRequest("post", data, process.env.REACT_APP_ACCOUNT_SERVER + "/login", { withCredentials: true })
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const user = response.data.user
|
||||
@@ -252,7 +252,7 @@ export function manualLogout() {
|
||||
export function confirmEmail(userId, token) {
|
||||
return dispatch => {
|
||||
dispatch(beginConfirm());
|
||||
return makeUserRequest("post", {}, "/users/" + userId + "/confirm/" + token).then(
|
||||
return makeUserRequest("post", {}, process.env.REACT_APP_ACCOUNT_SERVER + "/users/" + userId + "/confirm/" + token).then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(confirmSuccess());
|
||||
@@ -271,7 +271,7 @@ export function confirmEmail(userId, token) {
|
||||
export function resetPassword(userId, token, password) {
|
||||
return dispatch => {
|
||||
dispatch(beginResetPassword());
|
||||
return makeUserRequest("post", { password: password }, "/users/" + userId + "/reset-password/" + token).then(
|
||||
return makeUserRequest("post", { password: password }, process.env.REACT_APP_ACCOUNT_SERVER + "/users/" + userId + "/reset-password/" + token).then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(resetPasswordSuccess());
|
||||
@@ -289,7 +289,7 @@ export function resetPassword(userId, token, password) {
|
||||
export function sendResetPassword(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginSendResetPassword());
|
||||
return makeUserRequest("post", data, "/api/send-reset-password").then(
|
||||
return makeUserRequest("post", data, process.env.REACT_APP_ACCOUNT_SERVER + "/api/send-reset-password").then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(sendResetPasswordSuccess());
|
||||
@@ -307,7 +307,7 @@ export function sendResetPassword(data) {
|
||||
export function sendConfirmEmail(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginSendConfirm());
|
||||
return makeUserRequest("post", data, "/users/" + data + "/send-confirm").then(
|
||||
return makeUserRequest("post", data, process.env.REACT_APP_ACCOUNT_SERVER + "/users/" + data + "/send-confirm").then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(sendConfirmSuccess());
|
||||
@@ -325,7 +325,7 @@ export function sendConfirmEmail(data) {
|
||||
export function acceptTerms(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginAgreeTerms());
|
||||
return makeUserRequest("post", data, "/users/" + data + "/terms").then(
|
||||
return makeUserRequest("post", data, process.env.REACT_APP_ACCOUNT_SERVER + "/users/" + data + "/terms").then(
|
||||
response => {
|
||||
if (response.data.success) {
|
||||
dispatch(agreeTermsSuccess());
|
||||
@@ -343,7 +343,7 @@ export function updateProfile(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginUpdateProfile());
|
||||
|
||||
return makeUserRequest("post", data, "/users/" + data.userId)
|
||||
return makeUserRequest("post", data, process.env.REACT_APP_ACCOUNT_SERVER + "/users/" + data.userId)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const user = response.data.user
|
||||
@@ -367,8 +367,8 @@ export function updateProfile(data) {
|
||||
export function manualRegister(data) {
|
||||
return dispatch => {
|
||||
dispatch(beginRegister());
|
||||
|
||||
return makeUserRequest("post", data, "/register")
|
||||
console.log("It is: " + process.env.REACT_APP_ACCOUNT_SERVER );
|
||||
return makeUserRequest("post", data, process.env.REACT_APP_ACCOUNT_SERVER + "/register")
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
data.userId = response.data.userId;
|
||||
|
||||
@@ -20,6 +20,8 @@ import TermsContainer from "./User/TermsContainer"
|
||||
|
||||
const store = configureStore(/* provide initial state if any */)
|
||||
|
||||
console.log(process.env);
|
||||
//This thssi
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
<ConnectedRouter history={history}> { /* place ConnectedRouter under Provider */ }
|
||||
|
||||
Reference in New Issue
Block a user