@@ -57,7 +57,7 @@ async function create(type, email, accountId) {
5757 * @param {ObjectId } accountId
5858 * @returns {string } JWT Token containing accountId and accountConfirmationId
5959 */
60- function generateToken ( accountConfirmationId , accountId ) {
60+ function generateToken ( accountConfirmationId , accountId = null ) {
6161 const token = jwt . sign ( {
6262 accountConfirmationId : accountConfirmationId ,
6363 accountId : accountId
@@ -68,34 +68,48 @@ function generateToken(accountConfirmationId, accountId) {
6868}
6969
7070/**
71- * Generates the link that the user will use to access the page to finish account creation
71+ * Generates the link that the user will use to access the page to begin account creationg
7272 * @param {'http'|'https' } httpOrHttps
7373 * @param {string } domain the domain of the current
7474 * @param {string } type the model that the
7575 * @param {string } token the reset token
7676 * @returns {string } the string, of form: [http|https]://{domain}/{model}/create?token={token}
7777 */
78- function generateTokenLink ( httpOrHttps , domain , type , token ) {
78+ function generateCreateAccountTokenLink ( httpOrHttps , domain , type , token ) {
7979 const link = `${ httpOrHttps } ://${ domain } /${ type } /create?token=${ token } ` ;
8080 return link ;
8181}
8282
8383/**
84- * Generates the mailData for the account confirmation Email.
84+ * Generates the link that the user will use to confirm account and proceed with account creationg
85+ * @param {'http'|'https' } httpOrHttps
86+ * @param {string } domain the domain of the current
87+ * @param {string } type the model that the
88+ * @param {string } token the reset token
89+ * @returns {string } the string, of form: [http|https]://{domain}/{model}/create?token={token}
90+ */
91+ function generateConfirmTokenLink ( httpOrHttps , domain , type , token ) {
92+ const link = `${ httpOrHttps } ://${ domain } /${ type } /confirm?token=${ token } ` ;
93+ return link ;
94+ }
95+ /**
96+ * Generates the mailData for the account confirmation Email. This really only applies to
97+ * hackers as all other accounts are intrinsically confirmed via the email they recieve to invite them
8598 * @param {string } hostname The hostname that this service is running on
8699 * @param {string } receiverEmail The receiver of the email
100+ * @param {string } type the user type
87101 * @param {string } token The account confirmation token
88102 */
89103function generateAccountConfirmationEmail ( hostname , receiverEmail , type , token ) {
90104 const httpOrHttps = ( hostname === "localhost" ) ? "http" : "https" ;
91105 const address = ( hostname === "localhost" ) ? `localhost:${ process . env . PORT } ` : hostname ;
92- const tokenLink = generateTokenLink ( httpOrHttps , address , type , token ) ;
106+ const tokenLink = generateConfirmTokenLink ( httpOrHttps , address , type , token ) ;
93107 var emailSubject = "" ;
94108 if ( token === undefined || tokenLink === undefined ) {
95109 return undefined ;
96110 }
97111 if ( type === Constants . HACKER ) {
98- emailSubject = Constants . CONFIRM_ACC_EMAIL_SUBJECTS [ Constants . HACKER ] ;
112+ emailSubject = Constants . CONFIRM_ACC_EMAIL_SUBJECT
99113 }
100114 const handlebarPath = path . join ( __dirname , `../assets/email/AccountConfirmation.hbs` ) ;
101115
@@ -109,10 +123,50 @@ function generateAccountConfirmationEmail(hostname, receiverEmail, type, token)
109123 } ;
110124 return mailData ;
111125}
126+
127+ /*
128+ * Generates the mailData for the account invitation Email.
129+ * @param {string } hostname The hostname that this service is running on
130+ * @param {string } receiverEmail The receiver of the email
131+ * @param {string } type The user type
132+ * @param {string } token The account confirmation token
133+ */
134+ function generateAccountInvitationEmail ( hostname , receiverEmail , type , token ) {
135+ const httpOrHttps = ( hostname === "localhost" ) ? "http" : "https" ;
136+ const address = ( hostname === "localhost" ) ? `localhost:${ process . env . PORT } ` : hostname ;
137+ const tokenLink = generateCreateAccountTokenLink ( httpOrHttps , address , type , token ) ;
138+ var emailSubject = "" ;
139+ if ( token === undefined || tokenLink === undefined ) {
140+ return undefined ;
141+ }
142+ if ( type === Constants . HACKER ) {
143+ emailSubject = Constants . CREATE_ACC_EMAIL_SUBJECTS [ Constants . HACKER ] ;
144+ }
145+ else if ( type === Constants . VOLUNTEER ) {
146+ emailSubject = Constants . CREATE_ACC_EMAIL_SUBJECTS [ Constants . VOLUNTEER ] ;
147+ }
148+ else if ( Constants . SPONSOR_TIERS . includes ( type ) ) {
149+ emailSubject = Constants . CREATE_ACC_EMAIL_SUBJECTS [ Constants . SPONSOR ] ;
150+ }
151+ else if ( type === Constants . STAFF ) {
152+ emailSubject = Constants . CREATE_ACC_EMAIL_SUBJECTS [ Constants . STAFF ] ;
153+ }
154+ const handlebarPath = path . join ( __dirname , `../assets/email/AccountInvitation.hbs` ) ;
155+ const mailData = {
156+ from : process . env . NO_REPLY_EMAIL ,
157+ to : receiverEmail ,
158+ subject : emailSubject ,
159+ html : Services . Email . renderEmail ( handlebarPath , {
160+ link : tokenLink
161+ } )
162+ } ;
163+ return mailData ;
164+ }
112165module . exports = {
113166 findById : findById ,
114167 findByAccountId : findByAccountId ,
115168 create : create ,
116169 generateToken : generateToken ,
117170 generateAccountConfirmationEmail : generateAccountConfirmationEmail ,
171+ generateAccountInvitationEmail : generateAccountInvitationEmail
118172}
0 commit comments