We want to be able to share resources inside our web application with new or other users. We want to do this by implementing an invitation code. I have seen this implemented many times before in other applications (google docs for example), where you send an invitation code to another user and that other user will have whatever access the first user agreed.
I am sure there has to be a pattern, or best approach already documented somewhere, I just need the right words to look for it. Will someone be able to point me in the right direction? Below is the use case:
- User one (user1) has an account with multiple spaces.
- User1 wants to share a specific space (space9) with User2 (which is or not on the user table).
- User1 sends an invitation code to the email of user2.
- User2 registers and enters the invitation code or clicks on the link to register with the invitation code.
- User2 has access to space9 and only to space9, not to any other space register for user1.
Edit 1: (Possible Algorithm to Use based on Mark Answer):
In my domain model I have User and Account and each user has 0 or more accounts. Then we also have SharedSpace, each user has 0 or more share space and each account may have 0 or more sharespace. Now Sharespace will contain (inviationCode, spaceCode, active (yes), expiration, email (share with).
Any user who has an account (acct1) is able to share space with
acct1.shareSpace("spaceCodeToShare","Emailofusertosharewith");
The method shareSpace(string,string) will do the following:
- Create and send invitation Code to email
- If user is registered, he activates his code either clicking or entering it (using authorize or customAuthorize attribute and IPrincipal to prevent unauthorized access).
- IF user is not registered then he logs in and after a user entry for this user is created then he activates the code.
- If user never activates the code the the code expires and the active status toggles to false.
Do you think I am missing anything, it looks more simple than I thought it would be?