# New Invitation Flow
## User Flow
### Accepting an Invite
1. When someone goes to a referral link, the popup opens
2. The popup has a button to click, where you sign a message. Once the user signs the message, their profile is created in the backend.
### Generating an Invitation
1. Create a invitation code, the default will be your connected wallet address. This invitation code is saved to database
2. When the user modifies and saves their invitation code, they use that new invitation code
## Endpoints
### GET /user
Fetch the UserPoints object from the database
DONE: see `api/v1/user/points/:address`
### POST /save-referral-code
Save the referral code for that user their UserPoints object
### POST /accept-invite
Update the referrer.referred field with the user address that just accepted the invite.
Check to make sure user object has not already been created
Create a new user profile with:
- `terms_of_service_signature` field
- `referrer` field updated with referrer address
- Every other field in UserPoints initialized to default values
## Storage
### Invite code to user mapping
Create a mapping between invite codes and users, such that we can:
1. Check if any user currently uses this invite code
2. Map between an invite code and a user address
### Changes to existing UserPoints object
Add these following fields
```
referrer: Address; // Address that referred this user
referred: Address[]; // Addresses that this user referred
referral_code: string; // Referral URL that the user chooses
terms_of_service_signature: Hex; // generated when they accept the invite
```
## Worker
### Referral Daily Updates
Every Day:
for each user:
total_referrals = 0
for each referred_account:
if referred_account.num_points > 1:
total_referrals += 1
user.referral_count = total_referrals
Add a backend endpoint to update the user object with the following fields address, referrer, signature