Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #475 from RTradeLtd/verifix
Browse files Browse the repository at this point in the history
.
  • Loading branch information
bonedaddy authored Apr 14, 2020
2 parents 95c711b + 49f3b65 commit 137c749
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 14 deletions.
3 changes: 3 additions & 0 deletions api/v2/routes_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ func (api *API) upgradeAccount(c *gin.Context) {
api.LogError(c, err, eh.UserSearchError)(http.StatusBadRequest)
return
}
if usages.Tier == models.Unverified {
Fail(c, errors.New("unverified account upgrade process must be done via email verification"))
}
// prevent people from repeatedly calling this granting perpetual credits
if usages.Tier != models.Free {
Fail(c, errors.New("user account is already upgrade"))
Expand Down
4 changes: 2 additions & 2 deletions api/v2/routes_ens.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (api *API) ClaimENSName(c *gin.Context) {
return
}
// prevent processing if account is free tier
if usage.Tier == models.Free {
if usage.Tier == models.Free || usage.Tier == models.Unverified {
Fail(c, errors.New("free accounts not eligible for ens claim"), http.StatusBadRequest)
return
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func (api *API) UpdateContentHash(c *gin.Context) {
return
}
// prevent processing if account is free tier
if usage.Tier == models.Free {
if usage.Tier == models.Free || usage.Tier == models.Unverified {
Fail(c, errors.New("free accounts not eligible for ens claim"), http.StatusBadRequest)
return
}
Expand Down
2 changes: 1 addition & 1 deletion api/v2/routes_rtfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (api *API) addFile(c *gin.Context) {
// if the user is within the free tier, then we throttle on-demand encryption
// free accounts are limited to a file upload size of 275MB when performing
// on-demand encryption. Non free accounts do not have this limit
if userUsage.Tier == models.Free {
if userUsage.Tier == models.Free || userUsage.Tier == models.Unverified {
megabytesUint := datasize.MB.Bytes()
maxSize := megabytesUint * 275
if fileHandler.Size > int64(maxSize) {
Expand Down
2 changes: 1 addition & 1 deletion api/v2/routes_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (api *API) handleUserCreate(c *gin.Context, forms map[string]string, create
"<br>",
"<br>",
"Lastly let's talk about emails! We try our best to not spam your inbox, so we limit emails to a few things: payment notifications, pin expiration warnings, password/username retrieval and processing failures.\n",
"But before we do this, you must validate your email. Note that email validation is not required unless you want these notifications\n",
"But before we do this, you must validate your email. Additionally before validating your email, you are in the 'unverified' tier which is limited to 100MB of data consumption. Email verification is now mandatory\n",
"To validate your email, just click the following "+link+"\n",
"<br>",
"<br>",
Expand Down
27 changes: 22 additions & 5 deletions api/v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ func (api *API) verifyEmailJWTToken(jwtString, username string) error {
if _, err := api.um.ValidateEmailVerificationToken(username, emailVerificationString); err != nil {
return err
}
// upgrade to free tier if unverified
usg, err := api.usage.FindByUserName(username)
if err != nil {
return err
}
// only update tier if they are an unverified user
// this is to provide backwards compatability where some unverified users
// may already be in a different tier
if usg.Tier == models.Unverified {
api.usage.UpdateTier(username, models.Free)
}
return nil
}

Expand Down Expand Up @@ -247,18 +258,24 @@ func (api *API) validateHoldTime(username, holdTime string) (int64, error) {
if err != nil {
return 0, err
}
if usageTier.Tier == models.Free && holdTimeInt > freeHoldTimeLimitInMonths {
return 0, errors.New("free accounts are limited to maximum hold times of 12 month")
} else if usageTier.Tier != models.Free && holdTimeInt > nonFreeHoldTimeLimitInMonths {
return 0, errors.New("non free accounts are limited to a maximum hold time of 24 months")
switch usageTier.Tier {
case models.Free, models.Unverified:
if holdTimeInt > freeHoldTimeLimitInMonths {
return 0, errors.New("free accounts are limited to maximum hold times of 12 month")

}
default:
if holdTimeInt > nonFreeHoldTimeLimitInMonths {
return 0, errors.New("non free accounts are limited to a maximum hold time of 24 months")
}
}
return holdTimeInt, nil
}

func (api *API) ensureLEMaxPinTime(upload *models.Upload, holdTime int64, tier models.DataUsageTier) error {
var limit time.Time
switch tier {
case models.Free:
case models.Free, models.Unverified:
limit = time.Now().AddDate(1, 0, 0)
case models.Paid, models.Partner, models.WhiteLabeled:
limit = time.Now().AddDate(2, 0, 0)
Expand Down
5 changes: 5 additions & 0 deletions api/v2/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ func Test_Ensure_Two_Year_Max(t *testing.T) {
{"12-Months-paid", args{12, models.Paid}, false},
{"22-Months-paid", args{22, models.Paid}, false},
{"25-Months-paid", args{25, models.Paid}, true},
{"10-Months-unverified", args{10, models.Unverified}, false},
{"11-Months-unverified", args{11, models.Unverified}, false},
{"12-Months-unverified", args{12, models.Unverified}, true},
{"22-Months-unverified", args{22, models.Unverified}, true},
{"25-Months-unverified", args{25, models.Unverified}, true},
{"10-Months-free", args{10, models.Free}, false},
{"11-Months-free", args{11, models.Free}, false},
{"12-Months-free", args{12, models.Free}, true},
Expand Down
5 changes: 5 additions & 0 deletions cmd/temporal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ var commands = map[string]cmd.Cmd{
fmt.Println("failed to create user account", err)
os.Exit(1)
}
// update tier
if err := models.NewUsageManager(d.DB).UpdateTier(args["user"], models.Free); err != nil {
fmt.Println("failed to update user account tier", err)
os.Exit(1)
}
// add credits
if _, err := models.NewUserManager(d.DB).AddCredits(args["user"], 99999999); err != nil {
fmt.Println("failed to grant credits to user account", err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/RTradeLtd/cmd/v2 v2.1.0
github.com/RTradeLtd/config/v2 v2.2.0
github.com/RTradeLtd/crypto/v2 v2.1.1
github.com/RTradeLtd/database/v2 v2.7.4
github.com/RTradeLtd/database/v2 v2.7.5-rc1
github.com/RTradeLtd/entropy-mnemonics v0.0.0-20170316012907-7b01a644a636
github.com/RTradeLtd/go-ipfs-api v0.0.0-20190522213636-8e3700e602fd
github.com/RTradeLtd/gpaginator v0.0.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ github.com/RTradeLtd/crypto v2.0.0+incompatible h1:3+UEo0upD0p3A+7yLJ14UJpT6aZEh
github.com/RTradeLtd/crypto v2.0.0+incompatible/go.mod h1:xhKwg748pxs2as6Ts65TiBBFrYzntioTqBIZEa1BUio=
github.com/RTradeLtd/crypto/v2 v2.1.1 h1:P59zYkkNkl6K1KiTRvW52AYwLvwmtzuzZ9+AjLWmKsU=
github.com/RTradeLtd/crypto/v2 v2.1.1/go.mod h1:saIQ67Btn4JWsOdzjn9U6Dl+aZlg+YKgg4RsQKXxjf4=
github.com/RTradeLtd/database/v2 v2.7.4 h1:7kYdfjMpvnccrzxt/l29DUTRXsfiWBzuNmGsY+BmVJA=
github.com/RTradeLtd/database/v2 v2.7.4/go.mod h1:2Q64z+Gdas9wgMpO72iKYW3tCsHs2SJHPzdROcj6MLE=
github.com/RTradeLtd/database/v2 v2.7.5-rc1 h1:1z8eFMSEleC8Rr8mRISdq+3+2NI23FBf8eBzrNVQdk8=
github.com/RTradeLtd/database/v2 v2.7.5-rc1/go.mod h1:2Q64z+Gdas9wgMpO72iKYW3tCsHs2SJHPzdROcj6MLE=
github.com/RTradeLtd/entropy-mnemonics v0.0.0-20170316012907-7b01a644a636 h1:i/+1LBA+YMfD1m9UnQP52A7S6y2U3C0xpMBehPkDRug=
github.com/RTradeLtd/entropy-mnemonics v0.0.0-20170316012907-7b01a644a636/go.mod h1:zpzHNRdCMCG9PM9QO5jVSldXCRMJ7lY42yJ5TEe//7M=
github.com/RTradeLtd/go-ipfs-api v0.0.0-20190308091756-8b7099fd5e21/go.mod h1:ipDfy60LjYDddlX/zluSwRVtfGR0EB1HqADazGNMUmE=
Expand Down
4 changes: 2 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func CalculatePinCost(username, contentHash string, holdTimeInMonths int64, im r
return 0, err
}
// if they are free tier, they don't incur data charges
if usage.Tier == models.Free || usage.Tier == models.WhiteLabeled {
if usage.Tier == models.Free || usage.Tier == models.WhiteLabeled || usage.Tier == models.Unverified {
return 0, nil
}
// dynamic pricing based on their usage tier
Expand All @@ -49,7 +49,7 @@ func CalculateFileCost(username string, holdTimeInMonths, size int64, um *models
return 0, err
}
// if they are free tier, they don't incur data charges
if usage.Tier == models.Free || usage.Tier == models.WhiteLabeled {
if usage.Tier == models.Free || usage.Tier == models.WhiteLabeled || usage.Tier == models.Unverified {
return 0, nil
}
// dynamic pricing based on their usage tier
Expand Down

0 comments on commit 137c749

Please sign in to comment.