Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
angular-meteor
api
Commits
3b23497b
Commit
3b23497b
authored
Dec 14, 2019
by
GD-A-150752
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom-email
parent
6fd1e96b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
2 deletions
+79
-2
config.ts
server/config.ts
+4
-0
email.enum.ts
server/enum/email.enum.ts
+14
-0
env.ts
server/env.ts
+1
-0
emails.method.ts
server/methods/emails.method.ts
+13
-0
users.method.ts
server/methods/users.method.ts
+5
-2
email.service.ts
server/services/email.service.ts
+42
-0
No files found.
server/config.ts
View file @
3b23497b
...
...
@@ -6,3 +6,7 @@ export const PERMISSIONS = {
CAN_SEE_ALL_USERS
:
'CAN_SEE_ALL_USERS'
,
CAN_ACCESS_DASHBOARD_PAGE
:
'CAN_ACCESS_DASHBOARD_PAGE'
,
};
export
const
CONFIG
=
{
SiteName
:
'JIBC'
,
};
server/enum/email.enum.ts
0 → 100644
View file @
3b23497b
export
const
emailEnum
=
{
REGISTER_HEADING
:
(
platform
:
string
)
=>
{
return
`Welcome to
${
platform
}
`
;
},
REGISTER_EMAIL_BODY
:
(
name
:
string
,
role
:
string
,
link
:
string
)
=>
{
return
`Hi
${
name
}
! You are our
${
role
}
now. Please click on the link <a href="
${
link
}
" target="_blank">
${
link
}
</a> to verify your account.`
;
},
RESET_HEADING
:
(
platform
:
string
)
=>
{
return
`Reset Password for
${
platform
}
`
;
},
RESET_EMAIL_BODY
:
(
name
:
string
,
link
:
string
)
=>
{
return
`Hi
${
name
}
! Don't worry. Reset your password by clicking on the following link <a href="
${
link
}
" target="_blank">
${
link
}
</a>.`
;
},
};
server/env.ts
View file @
3b23497b
process
.
env
.
S3
=
'{"path": "files", "key":"AKIAWEWXPEPGGRRUHLH4","secret":"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","bucket":"siingio","region":"us-east-1"}'
;
process
.
env
.
MAIL_URL
=
'smtp://postmaster%40mail.vqode.com:VQode1234@smtp.mailgun.org:587'
;
process
.
env
.
appUrl
=
'http://localhost:4200/'
;
server/methods/emails.method.ts
0 → 100644
View file @
3b23497b
import
{
Meteor
}
from
'meteor/meteor'
;
import
{
EmailService
}
from
'../services/email.service'
;
Meteor
.
methods
({
sendForgotPasswordEmail
(
email
:
string
):
boolean
{
const
user
:
Meteor
.
User
=
Accounts
.
findUserByEmail
(
email
);
if
(
user
)
{
EmailService
.
sendForgotPasswordEmail
(
user
,
email
);
return
true
;
}
throw
new
Meteor
.
Error
(
422
,
'Email address doesn
\'
t exist.'
);
},
});
server/methods/users.method.ts
View file @
3b23497b
...
...
@@ -3,6 +3,7 @@ import { Roles } from '../collections/role.collection';
import
{
PERMISSIONS
}
from
'../config'
;
import
{
UtilsService
}
from
'../services/utils.service'
;
import
{
QueryModel
}
from
'../models/query.model'
;
import
{
EmailService
}
from
'../services/email.service'
;
Meteor
.
methods
({
...
...
@@ -17,7 +18,6 @@ Meteor.methods({
registerUser
(
user
:
any
):
string
{
const
defaultRole
=
Roles
.
findOne
({
title
:
user
.
role
});
if
(
!
Accounts
.
findUserByEmail
(
user
.
email
))
{
const
userObj
=
{
email
:
user
.
email
,
password
:
user
.
password
,
...
...
@@ -27,7 +27,10 @@ Meteor.methods({
role
:
defaultRole
.
_id
,
},
};
return
Accounts
.
createUser
(
userObj
);
const
userId
=
Accounts
.
createUser
(
userObj
);
EmailService
.
sendVerificationEmail
(
user
,
userId
);
return
userId
;
}
throw
new
Meteor
.
Error
(
422
,
'Email address already in use.'
);
},
...
...
server/services/email.service.ts
0 → 100644
View file @
3b23497b
import
{
CONFIG
}
from
'../config'
;
import
{
emailEnum
}
from
'../enum/email.enum'
;
export
class
EmailService
{
static
sendVerificationEmail
(
user
:
any
,
userId
:
string
):
void
{
Accounts
.
emailTemplates
.
siteName
=
CONFIG
.
SiteName
;
// Will uncomment it later with domain email
// Accounts.emailTemplates.from = CONFIG.DomainEmail;
Accounts
.
emailTemplates
.
verifyEmail
=
{
subject
()
{
return
emailEnum
.
REGISTER_HEADING
(
CONFIG
.
SiteName
);
},
html
(
usr
,
url
)
{
const
token
=
url
.
substr
(
url
.
lastIndexOf
(
'/'
)
+
1
);
const
link
=
`
${
process
.
env
.
appUrl
}
#/auth/verify-email/
${
token
}
`
;
return
emailEnum
.
REGISTER_EMAIL_BODY
(
user
.
name
,
user
.
role
,
link
);
},
};
Accounts
.
sendVerificationEmail
(
userId
,
user
.
email
);
}
static
sendForgotPasswordEmail
(
user
:
Meteor
.
User
,
email
:
string
):
void
{
Accounts
.
emailTemplates
.
siteName
=
CONFIG
.
SiteName
;
// Will uncomment it later with domain email
// Accounts.emailTemplates.from = CONFIG.DomainEmail;
Accounts
.
emailTemplates
.
resetPassword
=
{
subject
()
{
return
emailEnum
.
RESET_HEADING
(
CONFIG
.
SiteName
);
},
html
(
usr
,
url
)
{
const
token
=
url
.
substr
(
url
.
lastIndexOf
(
'/'
)
+
1
);
const
link
=
`
${
process
.
env
.
appUrl
}
#/auth/reset-password/
${
token
}
`
;
return
emailEnum
.
RESET_EMAIL_BODY
(
user
.
profile
.
name
,
link
);
},
};
Accounts
.
sendResetPasswordEmail
(
user
.
_id
,
email
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment