Skip to content

Commit

Permalink
feat: disable delete button for active subscription users
Browse files Browse the repository at this point in the history
  • Loading branch information
LuccaBitfly committed Jan 22, 2025
1 parent 80a6576 commit 914b214
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
10 changes: 10 additions & 0 deletions handlers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ func UserSettings(w http.ResponseWriter, r *http.Request) {
}
}

// disable delete button if user has active subscription
hasUserActiveSubscription, err := getHasUserActiveSubscription(user.UserID)
if err != nil {
logger.Errorf("Error retrieving the active subscription for user: %v %v", user.UserID, err)
utils.SetFlash(w, r, "", "Error: Something went wrong.")
http.Redirect(w, r, "/user/settings", http.StatusSeeOther)
return
}
userSettingsData.IsUserDeleteDisabled = hasUserActiveSubscription

userSettingsData.ApiStatistics.MaxDaily = &maxDaily
userSettingsData.ApiStatistics.MaxMonthly = &maxMonthly

Expand Down
10 changes: 7 additions & 3 deletions templates/user/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,13 @@ <h3 class="h5">Delete Account <i class="fas fa-exclamation-triangle text-warning
</div>
<div class="card-body">
<div class="d-flex justify-content-between">
<span> Warning, you will not be able to recover your account! </span>
<!-- Button trigger modal -->
<button type="button" class="btn btn-sm btn-outline-danger" data-toggle="modal" data-target="#deleteAccountModal">Delete</button>
{{ if .IsUserDeleteDisabled }}
<span> Warning, you will not be able to recover your account! </span>
<!-- Button trigger modal -->
<button type="button" class="btn btn-sm btn-outline-danger" data-toggle="modal" data-target="#deleteAccountModal">Delete</button>
{{ else }}
<span> You currently have an active premium subscription or premium API plan. To delete your account please cancel your subscription or contact our <a href="https://dsc.gg/beaconchain">support</a> </span>
{{ end }}
</div>
</div>
</div>
Expand Down
17 changes: 9 additions & 8 deletions types/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -1220,14 +1220,15 @@ type CsrfData struct {
type UserSettingsPageData struct {
CsrfField template.HTML
AuthData
Subscription UserSubscription
Premium UserPremiumSubscription
PairedDevices []PairedDevice
Sapphire *string
Emerald *string
Diamond *string
ShareMonitoringData bool
ApiStatistics *ApiStatistics
Subscription UserSubscription
Premium UserPremiumSubscription
PairedDevices []PairedDevice
Sapphire *string
Emerald *string
Diamond *string
ShareMonitoringData bool
ApiStatistics *ApiStatistics
IsUserDeleteDisabled bool
}

type PairedDevice struct {
Expand Down

0 comments on commit 914b214

Please sign in to comment.