satellite/console: referral link for individual users (#2614)
* init * change give credit to be invitee credits for free credits * remove unused variables * fix tests
This commit is contained in:
parent
353b089927
commit
aaf3283b4e
@ -61,6 +61,8 @@ const (
|
||||
FieldNewPassword = "newPassword"
|
||||
// Secret is a field name for registration token for user creation during Vanguard release
|
||||
Secret = "secret"
|
||||
// ReferrerUserID is a field name for passing referrer's user id
|
||||
ReferrerUserID = "referrerUserID"
|
||||
)
|
||||
|
||||
// rootMutation creates mutation for graphql populated by AccountsClient
|
||||
@ -77,11 +79,15 @@ func rootMutation(log *zap.Logger, service *console.Service, mailService *mailse
|
||||
Secret: &graphql.ArgumentConfig{
|
||||
Type: graphql.NewNonNull(graphql.String),
|
||||
},
|
||||
ReferrerUserID: &graphql.ArgumentConfig{
|
||||
Type: graphql.String,
|
||||
},
|
||||
},
|
||||
// creates user and company from input params and returns userID if succeed
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
input, _ := p.Args[InputArg].(map[string]interface{})
|
||||
secretInput, _ := p.Args[Secret].(string)
|
||||
refUserID, _ := p.Args[ReferrerUserID].(string)
|
||||
|
||||
offerType := rewards.FreeCredit
|
||||
|
||||
@ -96,7 +102,7 @@ func rootMutation(log *zap.Logger, service *console.Service, mailService *mailse
|
||||
return nil, err
|
||||
}
|
||||
|
||||
user, err := service.CreateUser(p.Context, createUser, secret)
|
||||
user, err := service.CreateUser(p.Context, createUser, secret, refUserID)
|
||||
if err != nil {
|
||||
log.Error("register: failed to create account",
|
||||
zap.String("rawSecret", secretInput),
|
||||
|
@ -79,11 +79,12 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
},
|
||||
Password: "123a123",
|
||||
}
|
||||
refUserID := ""
|
||||
|
||||
regToken, err := service.CreateRegToken(ctx, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
rootUser, err := service.CreateUser(ctx, createUser, regToken.Secret)
|
||||
rootUser, err := service.CreateUser(ctx, createUser, regToken.Secret, refUserID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, createUser.PartnerID, rootUser.PartnerID.String())
|
||||
|
||||
@ -350,7 +351,7 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
Email: "u1@mail.test",
|
||||
},
|
||||
Password: "123a123",
|
||||
}, regTokenUser1.Secret)
|
||||
}, regTokenUser1.Secret, refUserID)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Activation", func(t *testing.T) {
|
||||
@ -376,7 +377,7 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
Email: "u2@mail.test",
|
||||
},
|
||||
Password: "123a123",
|
||||
}, regTokenUser2.Secret)
|
||||
}, regTokenUser2.Secret, refUserID)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Activation", func(t *testing.T) {
|
||||
|
@ -67,11 +67,12 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
},
|
||||
Password: "123a123",
|
||||
}
|
||||
refUserID := ""
|
||||
|
||||
regToken, err := service.CreateRegToken(ctx, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
rootUser, err := service.CreateUser(ctx, createUser, regToken.Secret)
|
||||
rootUser, err := service.CreateUser(ctx, createUser, regToken.Secret, refUserID)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Activation", func(t *testing.T) {
|
||||
@ -188,7 +189,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
Email: "muu1@mail.test",
|
||||
},
|
||||
Password: "123a123",
|
||||
}, regTokenUser1.Secret)
|
||||
}, regTokenUser1.Secret, refUserID)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Activation", func(t *testing.T) {
|
||||
@ -214,7 +215,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
Email: "muu2@mail.test",
|
||||
},
|
||||
Password: "123a123",
|
||||
}, regTokenUser2.Secret)
|
||||
}, regTokenUser2.Secret, refUserID)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Activation", func(t *testing.T) {
|
||||
@ -426,7 +427,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
Email: "user@mail.test",
|
||||
},
|
||||
Password: "123a123",
|
||||
}, regToken.Secret)
|
||||
}, regToken.Secret, refUserID)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -466,7 +467,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
Email: "user1@mail.test",
|
||||
},
|
||||
Password: "123a123",
|
||||
}, regToken.Secret)
|
||||
}, regToken.Secret, refUserID)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
@ -93,7 +93,7 @@ func NewService(log *zap.Logger, signer Signer, store DB, rewards rewards.DB, pm
|
||||
}
|
||||
|
||||
// CreateUser gets password hash value and creates new inactive User
|
||||
func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret RegistrationSecret) (u *User, err error) {
|
||||
func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret RegistrationSecret, refUserID string) (u *User, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
if err := user.IsValid(); err != nil {
|
||||
return nil, err
|
||||
|
@ -29,11 +29,11 @@ See LICENSE for copying information. -->
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-4">
|
||||
<label for="AwardCredit">Award Credit</label>
|
||||
<label for="InviteeCredit">Give Credit</label>
|
||||
<input type="number" class="form-control" name="AwardCredit" id="AwardCredit" placeholder="$50" min="1" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
<label for="AwardCreditDurationDays">Award Credit Exp</label>
|
||||
<label for="InviteeCreditDurationDays">Give Credit Exp</label>
|
||||
<input type="number" class="form-control" name="AwardCreditDurationDays" id="AwardCreditDurationDays" placeholder="14 days" min="1" required>
|
||||
</div>
|
||||
<div class="form-group col-md-4">
|
||||
|
@ -5,7 +5,7 @@ See LICENSE for copying information. -->
|
||||
<div class="offers-table mt-2 mb-5 container">
|
||||
<div class="row">
|
||||
<div class="col col-heading">Name</div>
|
||||
<div class="col col-heading">Award Credit</div>
|
||||
<div class="col col-heading">Give Credit</div>
|
||||
<div class="col col-heading">Redeemable Capacity</div>
|
||||
<div class="col col-heading">Created</div>
|
||||
<div class="col col-heading">Expiration</div>
|
||||
@ -18,7 +18,7 @@ See LICENSE for copying information. -->
|
||||
{{if not $defaultOffer.IsEmpty}}
|
||||
<div class="row data-row">
|
||||
<div class="col ml-3">{{$defaultOffer.Name}}</div>
|
||||
<div class="col">${{$defaultOffer.AwardCredit}}</div>
|
||||
<div class="col">${{$defaultOffer.InviteeCredit}}</div>
|
||||
<div class="col">{{$defaultOffer.RedeemableCap}}</div>
|
||||
<div class="col">{{printf "%.10s" $defaultOffer.CreatedAt}}</div>
|
||||
<div class="col">{{printf "%.10s" $defaultOffer.ExpiresAt}}</div>
|
||||
@ -32,7 +32,7 @@ See LICENSE for copying information. -->
|
||||
{{if not $currentOffer.IsEmpty}}
|
||||
<div class="row data-row">
|
||||
<div class="col ml-3">{{$currentOffer.Name}}</div>
|
||||
<div class="col">${{$currentOffer.AwardCredit}}</div>
|
||||
<div class="col">${{$currentOffer.InviteeCredit}}</div>
|
||||
<div class="col">{{$currentOffer.RedeemableCap}}</div>
|
||||
<div class="col">{{printf "%.10s" $currentOffer.CreatedAt}}</div>
|
||||
<div class="col">{{printf "%.10s" $currentOffer.ExpiresAt}}</div>
|
||||
@ -50,7 +50,7 @@ See LICENSE for copying information. -->
|
||||
{{range .FreeCredits.Done}}
|
||||
<div class="row data-row">
|
||||
<div class="col ml-3">{{.Name}}</div>
|
||||
<div class="col">${{.AwardCredit}}</div>
|
||||
<div class="col">${{.InviteeCredit}}</div>
|
||||
<div class="col">{{.RedeemableCap}}</div>
|
||||
<div class="col">{{printf "%.10s" .CreatedAt}}</div>
|
||||
<div class="col">{{printf "%.10s" .ExpiresAt}}</div>
|
||||
|
@ -97,7 +97,7 @@ export async function forgotPasswordRequest(email: string): Promise<RequestRespo
|
||||
}
|
||||
|
||||
// Performs Create user graqhQL request.
|
||||
export async function createUserRequest(user: User, password: string, secret: string): Promise<RequestResponse<string>> {
|
||||
export async function createUserRequest(user: User, password: string, secret: string, refUserId?: string): Promise<RequestResponse<string>> {
|
||||
let result: RequestResponse<string> = new RequestResponse<string>();
|
||||
|
||||
let response = await apolloManager.mutate(
|
||||
@ -112,6 +112,7 @@ export async function createUserRequest(user: User, password: string, secret: st
|
||||
shortName: "${user.shortName}",
|
||||
partnerId: "${user.partnerId}",
|
||||
},
|
||||
refUserId: "${refUserId || ""}",
|
||||
secret: "${secret}",
|
||||
){email, id}
|
||||
}`
|
||||
|
@ -38,6 +38,7 @@
|
||||
private isTermsAcceptedError: boolean = false;
|
||||
private secret: string = '';
|
||||
private partnerId: string = '';
|
||||
private refUserId: string = '';
|
||||
private loadingClassName: string = LOADING_CLASSES.LOADING_OVERLAY;
|
||||
|
||||
mounted(): void {
|
||||
@ -49,7 +50,7 @@
|
||||
let referralIds = ids ? JSON.parse(atob(ids)) : undefined;
|
||||
if (referralIds) {
|
||||
this.$data.partnerId = referralIds.partnerId;
|
||||
this.$data.referrerId = referralIds.userId;
|
||||
this.$data.refUserId = referralIds.userId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +125,7 @@
|
||||
}
|
||||
private async createUser(): Promise<void> {
|
||||
let user = new User(this.fullName.trim(), this.shortName.trim(), this.email.trim(), this.partnerId);
|
||||
let response = await createUserRequest(user, this.password, this.secret);
|
||||
let response = await createUserRequest(user, this.password, this.secret, this.refUserId);
|
||||
if (!response.isSuccess) {
|
||||
this.$store.dispatch(NOTIFICATION_ACTIONS.ERROR, response.errorMessage);
|
||||
this.loadingClassName = LOADING_CLASSES.LOADING_OVERLAY;
|
||||
|
Loading…
Reference in New Issue
Block a user