Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
X
xpub-faraday
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
xpub
xpub-faraday
Merge requests
!10
Sprint #12
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Sprint #12
develop
into
master
Overview
0
Commits
164
Pipelines
0
Changes
185
Merged
Bogdan Cochior
requested to merge
develop
into
master
6 years ago
Overview
0
Commits
164
Pipelines
0
Changes
185
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
356b1120
164 commits,
6 years ago
185 files
+
4274
−
5003
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
185
Search (e.g. *.vue) (Ctrl+P)
packages/component-email/src/helpers/Email.js
+
10
−
29
Options
@@ -3,35 +3,12 @@ const logger = require('@pubsweet/logger')
const
helpers
=
require
(
'
./helpers
'
)
module
.
exports
=
{
setupAssignEmail
:
async
(
req
,
email
,
res
,
role
)
=>
{
const
url
=
`
${
req
.
protocol
}
://
${
req
.
get
(
'
host
'
)}
`
let
emailType
switch
(
role
)
{
case
'
handlingEditor
'
:
emailType
=
'
assign-handling-editor
'
break
case
'
author
'
:
emailType
=
'
add-author
'
break
default
:
return
res
.
status
(
400
)
.
json
({
error
:
`Role
${
role
}
cannot be used with an assigned email`
})
}
try
{
await
mailService
.
setupAssignEmail
(
email
,
emailType
,
url
)
return
res
.
status
(
200
).
json
({})
}
catch
(
e
)
{
logger
.
error
(
e
)
return
res
.
status
(
500
).
json
({
error
:
'
Email could not be sent.
'
})
}
},
setupNewUserEmail
:
async
(
req
,
res
,
email
,
role
,
UserModel
)
=>
{
setupNewUserEmail
:
async
({
dashboardUrl
,
res
,
email
,
role
,
UserModel
})
=>
{
let
user
try
{
user
=
await
UserModel
.
findByEmail
(
email
)
}
catch
(
e
)
{
const
notFoundError
=
await
helpers
.
handleNotFoundError
(
e
,
'
u
ser
'
)
const
notFoundError
=
await
helpers
.
handleNotFoundError
(
e
,
'
U
ser
'
)
return
res
.
status
(
notFoundError
.
status
).
json
({
error
:
notFoundError
.
message
,
})
@@ -39,9 +16,8 @@ module.exports = {
if
(
user
.
passwordResetToken
===
undefined
)
{
return
res
.
status
(
400
)
.
json
({
error
:
'
User does not have a password reset token
'
})
.
json
({
error
:
'
User does not have a password reset token
.
'
})
}
const
url
=
`
${
req
.
protocol
}
://
${
req
.
get
(
'
host
'
)}
`
let
emailType
switch
(
role
)
{
case
'
handlingEditor
'
:
@@ -54,11 +30,16 @@ module.exports = {
break
default
:
return
res
.
status
(
400
).
json
({
error
:
`Role
${
role
}
cannot be used with a password reset email`
,
error
:
`Role
${
role
}
cannot be used with a password reset email
.
`
,
})
}
try
{
await
mailService
.
setupInviteEmail
(
user
,
emailType
,
url
)
await
mailService
.
sendSimpleEmail
({
toEmail
:
user
.
email
,
user
,
emailType
,
dashboardUrl
,
})
return
res
.
status
(
200
).
json
({})
}
catch
(
e
)
{
logger
.
error
(
e
)