diff --git a/app.json b/app.json index 3eff82c9..e69489b8 100644 --- a/app.json +++ b/app.json @@ -38,6 +38,10 @@ "description": "A secret key for...? Not sure where used.", "generator": "secret" }, + "EXAMPLE_USERNAME": { + "description": "Username of the default account.", + "value": "p5" + }, "EXAMPLE_USER_EMAIL": { "description": "The email address for the account holding the default Example sketches", "value": "examples@p5js.org" diff --git a/client/modules/IDE/components/Editor.jsx b/client/modules/IDE/components/Editor.jsx index d93e6635..e31ff525 100644 --- a/client/modules/IDE/components/Editor.jsx +++ b/client/modules/IDE/components/Editor.jsx @@ -321,11 +321,18 @@ class Editor extends React.Component { 'editor--options': this.props.editorOptionsVisible }); + console.log(this.props.file); const editorHolderClass = classNames({ 'editor-holder': true, 'editor-holder--hidden': this.props.file.fileType === 'folder' || this.props.file.url }); + let preview = ''; + if (this.props.file.fileType === 'file' && this.props.file.url) { + // TODO check if it's an image + preview = (
preview
); + } + return (
@@ -360,6 +367,7 @@ class Editor extends React.Component {
{ this.codemirrorContainer = element; }} className={editorHolderClass} >
+ {preview} diff --git a/client/modules/Mobile/MobileDashboardView.jsx b/client/modules/Mobile/MobileDashboardView.jsx index 0fd7cfe4..b6e6302e 100644 --- a/client/modules/Mobile/MobileDashboardView.jsx +++ b/client/modules/Mobile/MobileDashboardView.jsx @@ -22,7 +22,7 @@ import FooterTabSwitcher from '../../components/mobile/TabSwitcher'; import FooterTab from '../../components/mobile/Tab'; import Loader from '../App/components/loader'; -const EXAMPLE_USERNAME = 'p5'; +const EXAMPLE_USERNAME = process.env.EXAMPLE_USERNAME || 'p5'; // @ghalestrilo 08/13/2020: I'm sorry const ContentWrapper = styled(Content)` diff --git a/client/modules/User/pages/AccountView.jsx b/client/modules/User/pages/AccountView.jsx index f9f46cc8..70a6c77b 100644 --- a/client/modules/User/pages/AccountView.jsx +++ b/client/modules/User/pages/AccountView.jsx @@ -60,7 +60,7 @@ class AccountView extends React.Component { - + {/* */} diff --git a/client/modules/User/pages/LoginView.jsx b/client/modules/User/pages/LoginView.jsx index f490f5f6..3d560b3a 100644 --- a/client/modules/User/pages/LoginView.jsx +++ b/client/modules/User/pages/LoginView.jsx @@ -42,11 +42,11 @@ class LoginView extends React.Component {

{this.props.t('LoginView.Login')}

-

{this.props.t('LoginView.LoginOr')}

+ {/*

{this.props.t('LoginView.LoginOr')}

-
+
*/}

{this.props.t('LoginView.DontHaveAccount')} {this.props.t('LoginView.SignUp')} diff --git a/client/modules/User/pages/SignupView.jsx b/client/modules/User/pages/SignupView.jsx index 55ef1ae1..ed3d8054 100644 --- a/client/modules/User/pages/SignupView.jsx +++ b/client/modules/User/pages/SignupView.jsx @@ -34,11 +34,11 @@ class SignupView extends React.Component {

{this.props.t('SignupView.Description')}

-

{this.props.t('SignupView.Or')}

+ {/*

{this.props.t('SignupView.Or')}

-
+
*/}

{this.props.t('SignupView.AlreadyHave')} {this.props.t('SignupView.Login')} diff --git a/index.js b/index.js index b00b7227..be538ba3 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +console.log('environment:',process.env.NODE_ENV); + if (process.env.NODE_ENV === 'production') { process.env.webpackAssets = JSON.stringify(require('./dist/static/manifest.json')); require('./dist/server.bundle.js'); diff --git a/server/config/passport.js b/server/config/passport.js index 163db374..7411aee3 100644 --- a/server/config/passport.js +++ b/server/config/passport.js @@ -3,9 +3,9 @@ import friendlyWords from 'friendly-words'; import lodash from 'lodash'; import passport from 'passport'; -import GitHubStrategy from 'passport-github'; +// import GitHubStrategy from 'passport-github'; import LocalStrategy from 'passport-local'; -import GoogleStrategy from 'passport-google-oauth20'; +// import GoogleStrategy from 'passport-google-oauth20'; import { BasicStrategy } from 'passport-http'; import User from '../models/user'; @@ -82,101 +82,101 @@ const getPrimaryEmail = githubEmails => ( /** * Sign in with GitHub. */ -passport.use(new GitHubStrategy({ - clientID: process.env.GITHUB_ID, - clientSecret: process.env.GITHUB_SECRET, - callbackURL: '/auth/github/callback', - passReqToCallback: true, - scope: ['user:email'], -}, (req, accessToken, refreshToken, profile, done) => { - User.findOne({ github: profile.id }, (findByGithubErr, existingUser) => { - if (existingUser) { - done(null, existingUser); - return; - } +// passport.use(new GitHubStrategy({ +// clientID: process.env.GITHUB_ID, +// clientSecret: process.env.GITHUB_SECRET, +// callbackURL: '/auth/github/callback', +// passReqToCallback: true, +// scope: ['user:email'], +// }, (req, accessToken, refreshToken, profile, done) => { +// User.findOne({ github: profile.id }, (findByGithubErr, existingUser) => { +// if (existingUser) { +// done(null, existingUser); +// return; +// } - const emails = getVerifiedEmails(profile.emails); - const primaryEmail = getPrimaryEmail(profile.emails); +// const emails = getVerifiedEmails(profile.emails); +// const primaryEmail = getPrimaryEmail(profile.emails); - User.findByEmail(emails, (findByEmailErr, existingEmailUser) => { - if (existingEmailUser) { - existingEmailUser.email = existingEmailUser.email || primaryEmail; - existingEmailUser.github = profile.id; - existingEmailUser.username = existingEmailUser.username || profile.username; - existingEmailUser.tokens.push({ kind: 'github', accessToken }); - existingEmailUser.name = existingEmailUser.name || profile.displayName; - existingEmailUser.verified = User.EmailConfirmation.Verified; - existingEmailUser.save(saveErr => done(null, existingEmailUser)); - } else { - const user = new User(); - user.email = primaryEmail; - user.github = profile.id; - user.username = profile.username; - user.tokens.push({ kind: 'github', accessToken }); - user.name = profile.displayName; - user.verified = User.EmailConfirmation.Verified; - user.save(saveErr => done(null, user)); - } - }); - }); -})); +// User.findByEmail(emails, (findByEmailErr, existingEmailUser) => { +// if (existingEmailUser) { +// existingEmailUser.email = existingEmailUser.email || primaryEmail; +// existingEmailUser.github = profile.id; +// existingEmailUser.username = existingEmailUser.username || profile.username; +// existingEmailUser.tokens.push({ kind: 'github', accessToken }); +// existingEmailUser.name = existingEmailUser.name || profile.displayName; +// existingEmailUser.verified = User.EmailConfirmation.Verified; +// existingEmailUser.save(saveErr => done(null, existingEmailUser)); +// } else { +// const user = new User(); +// user.email = primaryEmail; +// user.github = profile.id; +// user.username = profile.username; +// user.tokens.push({ kind: 'github', accessToken }); +// user.name = profile.displayName; +// user.verified = User.EmailConfirmation.Verified; +// user.save(saveErr => done(null, user)); +// } +// }); +// }); +// })); -/** - * Sign in with Google. - */ -passport.use(new GoogleStrategy({ - clientID: process.env.GOOGLE_ID, - clientSecret: process.env.GOOGLE_SECRET, - callbackURL: '/auth/google/callback', - passReqToCallback: true, - scope: ['openid email'], -}, (req, accessToken, refreshToken, profile, done) => { - User.findOne({ google: profile._json.emails[0].value }, (findByGoogleErr, existingUser) => { - if (existingUser) { - done(null, existingUser); - return; - } +// /** +// * Sign in with Google. +// */ +// passport.use(new GoogleStrategy({ +// clientID: process.env.GOOGLE_ID, +// clientSecret: process.env.GOOGLE_SECRET, +// callbackURL: '/auth/google/callback', +// passReqToCallback: true, +// scope: ['openid email'], +// }, (req, accessToken, refreshToken, profile, done) => { +// User.findOne({ google: profile._json.emails[0].value }, (findByGoogleErr, existingUser) => { +// if (existingUser) { +// done(null, existingUser); +// return; +// } - const primaryEmail = profile._json.emails[0].value; +// const primaryEmail = profile._json.emails[0].value; - User.findByEmail(primaryEmail, (findByEmailErr, existingEmailUser) => { - let username = profile._json.emails[0].value.split('@')[0]; - User.findByUsername(username, (findByUsernameErr, existingUsernameUser) => { - if (existingUsernameUser) { - const adj = friendlyWords.predicates[Math.floor(Math.random() * friendlyWords.predicates.length)]; - username = slugify(`${username} ${adj}`); - } - // what if a username is already taken from the display name too? - // then, append a random friendly word? - if (existingEmailUser) { - existingEmailUser.email = existingEmailUser.email || primaryEmail; - existingEmailUser.google = profile._json.emails[0].value; - existingEmailUser.username = existingEmailUser.username || username; - existingEmailUser.tokens.push({ kind: 'google', accessToken }); - existingEmailUser.name = existingEmailUser.name || profile._json.displayName; - existingEmailUser.verified = User.EmailConfirmation.Verified; - existingEmailUser.save((saveErr) => { - if (saveErr) { - console.log(saveErr); - } - done(null, existingEmailUser); - }); - } else { - const user = new User(); - user.email = primaryEmail; - user.google = profile._json.emails[0].value; - user.username = username; - user.tokens.push({ kind: 'google', accessToken }); - user.name = profile._json.displayName; - user.verified = User.EmailConfirmation.Verified; - user.save((saveErr) => { - if (saveErr) { - console.log(saveErr); - } - done(null, user); - }); - } - }); - }); - }); -})); +// User.findByEmail(primaryEmail, (findByEmailErr, existingEmailUser) => { +// let username = profile._json.emails[0].value.split('@')[0]; +// User.findByUsername(username, (findByUsernameErr, existingUsernameUser) => { +// if (existingUsernameUser) { +// const adj = friendlyWords.predicates[Math.floor(Math.random() * friendlyWords.predicates.length)]; +// username = slugify(`${username} ${adj}`); +// } +// // what if a username is already taken from the display name too? +// // then, append a random friendly word? +// if (existingEmailUser) { +// existingEmailUser.email = existingEmailUser.email || primaryEmail; +// existingEmailUser.google = profile._json.emails[0].value; +// existingEmailUser.username = existingEmailUser.username || username; +// existingEmailUser.tokens.push({ kind: 'google', accessToken }); +// existingEmailUser.name = existingEmailUser.name || profile._json.displayName; +// existingEmailUser.verified = User.EmailConfirmation.Verified; +// existingEmailUser.save((saveErr) => { +// if (saveErr) { +// console.log(saveErr); +// } +// done(null, existingEmailUser); +// }); +// } else { +// const user = new User(); +// user.email = primaryEmail; +// user.google = profile._json.emails[0].value; +// user.username = username; +// user.tokens.push({ kind: 'google', accessToken }); +// user.name = profile._json.displayName; +// user.verified = User.EmailConfirmation.Verified; +// user.save((saveErr) => { +// if (saveErr) { +// console.log(saveErr); +// } +// done(null, user); +// }); +// } +// }); +// }); +// }); +// })); diff --git a/server/server.js b/server/server.js index d82aa6d8..4cca3cbf 100644 --- a/server/server.js +++ b/server/server.js @@ -90,6 +90,18 @@ app.use( app.use(Express.static(path.resolve(__dirname, '../dist/static'), { maxAge: process.env.STATIC_MAX_AGE || (process.env.NODE_ENV === 'production' ? '1d' : '0') })); +app.use( + '/assets', + Express.static( + path.resolve(__dirname, '../dist/static/assets'), + { + // Browsers must revalidate for changes to the locale files + // It doesn't actually mean "don't cache this file" + // See: https://jakearchibald.com/2016/caching-best-practices/ + setHeaders: res => res.setHeader('Cache-Control', 'no-cache') + } + ) +); app.use(bodyParser.urlencoded({ limit: '50mb', extended: true })); app.use(bodyParser.json({ limit: '50mb' })); @@ -135,15 +147,15 @@ app.use('/', serverRoutes); app.use(assetRoutes); app.use('/', embedRoutes); -app.get('/auth/github', passport.authenticate('github')); -app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login' }), (req, res) => { - res.redirect('/'); -}); +// app.get('/auth/github', passport.authenticate('github')); +// app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login' }), (req, res) => { +// res.redirect('/'); +// }); -app.get('/auth/google', passport.authenticate('google')); -app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/login' }), (req, res) => { - res.redirect('/'); -}); +// app.get('/auth/google', passport.authenticate('google')); +// app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/login' }), (req, res) => { +// res.redirect('/'); +// }); // configure passport require('./config/passport'); diff --git a/server/utils/mail.js b/server/utils/mail.js index 42c9b317..3523a13e 100644 --- a/server/utils/mail.js +++ b/server/utils/mail.js @@ -3,7 +3,7 @@ */ import nodemailer from 'nodemailer'; -import mg from 'nodemailer-mailgun-transport'; +// import mg from 'nodemailer-mailgun-transport'; const auth = { api_key: process.env.MAILGUN_KEY, @@ -12,7 +12,10 @@ const auth = { class Mail { constructor() { - this.client = nodemailer.createTransport(mg({ auth })); + this.client = nodemailer.createTransport({ + streamTransport: true, + // newline: 'windows' + }); this.sendOptions = { from: process.env.EMAIL_SENDER, }; diff --git a/server/views/index.js b/server/views/index.js index ecc269c0..3a6486bc 100644 --- a/server/views/index.js +++ b/server/views/index.js @@ -29,6 +29,7 @@ export function renderIndex() { window.process.env.CLIENT = true; window.process.env.LOGIN_ENABLED = ${process.env.LOGIN_ENABLED === 'false' ? false : true}; window.process.env.EXAMPLES_ENABLED = ${process.env.EXAMPLES_ENABLED === 'false' ? false : true}; + window.process.env.EXAMPLE_USERNAME = '${process.env.EXAMPLE_USERNAME || 'p5'}'; window.process.env.UI_ACCESS_TOKEN_ENABLED = ${process.env.UI_ACCESS_TOKEN_ENABLED === 'false' ? false : true}; window.process.env.UI_COLLECTIONS_ENABLED = ${process.env.UI_COLLECTIONS_ENABLED === 'false' ? false : true}; window.process.env.UPLOAD_LIMIT = ${process.env.UPLOAD_LIMIT ? `${process.env.UPLOAD_LIMIT}` : undefined}; @@ -42,13 +43,13 @@ export function renderIndex() {