Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ STAGE=prod
# A Slack webhook to send notifications to (optional)
#SLACK=https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ

# Require author email address - string is error message to display.
#REQEMAIL='Email is required.'

# Require author name - string is error message to display.
#REQNAME='Name is required.'

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ STAGE=prod

# A Slack webhook to send notifications to (optional)
#SLACK=https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ
```

# Require author email address - string is error message to display.
#REQEMAIL='Email is required.'

# Require author name - string is error message to display.
#REQNAME='Name is required.'

We use [dotenv](https://github.com/motdotla/dotenv) so it is also possible to
configure the project by setting environment variables.
Expand Down
9 changes: 9 additions & 0 deletions deploy/apex/webpack.config.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ if (process.env.SLACK) {
defines['process.env.SLACK'] = `'${process.env.SLACK}'`
}

if (process.env.REQEMAIL) {
defines['process.env.REQEMAIL'] = `'${process.env.REQEMAIL}'`
}

if (process.env.REQNAME) {
defines['process.env.REQNAME'] = `'${process.env.REQNAME}'`
}


export default {
entry: {
[lambdaDirNames['QueueComment']]: [
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/ui/postCommentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default class PostCommentForm extends Component {
}
<input
type="text"
placeholder="Name (optional)"
placeholder="Name"
className={
authorName.touched && authorName.error && hasError
}
Expand All @@ -189,7 +189,7 @@ export default class PostCommentForm extends Component {
}
<input
type="email"
placeholder="Email (optional, not shown)"
placeholder="Email (not shown)"
className={
authorEmail.touched && authorEmail.error && hasError
}
Expand Down
7 changes: 7 additions & 0 deletions packages/lambda/src/queueComment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { apiKey } from '../../../../deploy/state/apiKey.json'
dotenv.config({ silent: true })

const hmac = jwa('HS256')
const { REQEMAIL: authorEmailRequired, REQNAME: authorNameRequired } = process.env

let akismet = null

Expand Down Expand Up @@ -56,6 +57,12 @@ function validate (payload) {
if (commentContent && commentContent.length < 3) {
errors.commentContent = 'Must be at least 3 characters'
}
if (authorNameRequired && !authorName) {
errors.authorName = authorNameRequired
}
if (authorEmailRequired && !authorEmail) {
errors.authorEmail = authorEmailRequired
}
if (authorEmail && !isEmail(authorEmail)) {
errors.authorEmail = 'Email format not valid'
}
Expand Down