@@ -63,18 +63,37 @@ export default class Project {
6363 const roles = this . parseRoles ( rolesString )
6464 const projectTitle = this . data ?. label ?? this . data ?. title ?? 'TPEN Project'
6565 let message = `You have been invited to the TPEN project ${ projectTitle } .
66- View project <a href='https://three.t-pen.org/ project/${ this . data . _id } '>here</a>.`
66+ View project <a href='${ process . env . TPENINTERFACES } project/${ this . data . _id } '>here</a>.`
6767 if ( user ) {
6868 await this . inviteExistingTPENUser ( user . _id , roles )
69- } else {
70- const inviteCode = await this . inviteNewTPENUser ( email , roles )
71- // We will replace this URL with the correct url
72- const url = `https://three.t-pen.org/login?invite-code=${ inviteCode } `
73- message += `<p>Click the button below to get started with your project</p>
74- <button class = "buttonStyle" ><a href=${ url } >Get Started</a> </button>
75- or copy the following link into your web browser <a href=${ url } >${ url } </a> </p>`
69+ }
70+ else {
71+ const inviteData = await this . inviteNewTPENUser ( email , roles )
72+ const returnTo = encodeURIComponent ( `${ process . env . TPENINTERFACES } project?projectID=${ this . data . _id } &inviteCode=${ inviteData . tpenUserID } ` )
73+ // Signup starting at the TPEN3 public site
74+ const signup = `${ process . env . TPENTHREE } login
75+ ?inviteCode=${ inviteData . tpenUserID }
76+ &returnTo=${ returnTo }
77+ `
78+ // TODO decline endpoint in TPEN Services
79+ const decline = `${ process . env . TPENINTERFACES } project/decline
80+ ?inviteCode=${ inviteData . tpenUserID }
81+ &groupID=${ inviteData . tpenGroupID }
82+ `
83+ message += `
84+ <p>
85+ Click the button below to get started with your project</p>
86+ <button class="buttonStyle" ><a href="${ signup } ">Get Started</a></button>
87+ or copy the following link into your web browser <a href="${ signup } ">${ signup } </a>
88+ </p>
89+ <p>
90+ This E-mail address may be visible to members of the project so that they know
91+ about the potential of new members. You may decline this invitation which will keep
92+ you out of the project and remove the visibility of this E-mail address from project details. <br>
93+ <a href="${ decline } ">Click here to decline the invitation.</a>
94+ </p>
95+ `
7696 }
77-
7897 await sendMail ( email , `Invitation to ${ projectTitle } ` , message )
7998 return this
8099 } catch ( error ) {
@@ -133,15 +152,14 @@ export default class Project {
133152
134153 async inviteNewTPENUser ( email , roles ) {
135154 const user = new User ( )
136- const inviteCode = this . #generateInviteCode ( user . _id )
155+ const inviteCode = user . _id
137156 const agent = `https://store.rerum.io/v1/id/${ user . _id } `
138157 const profile = { displayName : email . split ( "@" ) [ 0 ] }
139158 const _sub = `temp-${ user . _id } ` // This is a temporary sub for the user until they verify their email
140159 user . data = { email, _sub, profile, agent, inviteCode }
141160 await user . save ( )
142161 await this . inviteExistingTPENUser ( user . _id , roles )
143-
144- return inviteCode
162+ return { "tpenUserID" :user . _id , "tpenGroupID" :this . data . group }
145163 }
146164
147165 async removeMember ( userId ) {
@@ -238,15 +256,6 @@ export default class Project {
238256 return await database . save ( this . data , process . env . TPENPROJECTS )
239257 }
240258
241- #generateInviteCode( userId ) {
242- const date = Date . now ( ) . toString ( )
243- const data = `${ date } :${ userId } `
244-
245- const hash = createHash ( "sha256" )
246- hash . update ( data )
247- return hash . digest ( "hex" )
248- }
249-
250259 async #load( ) {
251260 return database . getById ( this . _id , "projects" ) . then ( ( resp ) => {
252261 this . data = resp
0 commit comments