Enable updating WM payment pointer via API and Customize page

Ref T773
This commit is contained in:
Matt Baer 2020-09-30 14:40:13 -04:00
parent 13eb51913e
commit ec7b299fd3
4 changed files with 36 additions and 13 deletions

View File

@ -839,6 +839,9 @@ func viewEditCollection(app *App, u *User, w http.ResponseWriter, r *http.Reques
return ErrCollectionNotFound return ErrCollectionNotFound
} }
// Add collection properties
c.Monetization = app.db.GetCollectionAttribute(c.ID, "monetization_pointer")
silenced, err := app.db.IsUserSilenced(u.ID) silenced, err := app.db.IsUserSilenced(u.ID)
if err != nil { if err != nil {
log.Error("view edit collection %v", err) log.Error("view edit collection %v", err)

View File

@ -56,6 +56,8 @@ type (
PublicOwner bool `datastore:"public_owner" json:"-"` PublicOwner bool `datastore:"public_owner" json:"-"`
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
Monetization string `json:"monetization_pointer,omitempty"`
db *datastore db *datastore
hostName string hostName string
} }
@ -87,14 +89,15 @@ type (
Handle string `schema:"handle" json:"handle"` Handle string `schema:"handle" json:"handle"`
// Actual collection values updated in the DB // Actual collection values updated in the DB
Alias *string `schema:"alias" json:"alias"` Alias *string `schema:"alias" json:"alias"`
Title *string `schema:"title" json:"title"` Title *string `schema:"title" json:"title"`
Description *string `schema:"description" json:"description"` Description *string `schema:"description" json:"description"`
StyleSheet *sql.NullString `schema:"style_sheet" json:"style_sheet"` StyleSheet *sql.NullString `schema:"style_sheet" json:"style_sheet"`
Script *sql.NullString `schema:"script" json:"script"` Script *sql.NullString `schema:"script" json:"script"`
Signature *sql.NullString `schema:"signature" json:"signature"` Signature *sql.NullString `schema:"signature" json:"signature"`
Visibility *int `schema:"visibility" json:"public"` Monetization *string `schema:"monetization_pointer" json:"monetization_pointer"`
Format *sql.NullString `schema:"format" json:"format"` Visibility *int `schema:"visibility" json:"public"`
Format *sql.NullString `schema:"format" json:"format"`
} }
CollectionFormat struct { CollectionFormat struct {
Format string Format string

View File

@ -905,6 +905,15 @@ func (db *datastore) UpdateCollection(c *SubmittedCollection, alias string) erro
} }
} }
// Update Monetization value
if c.Monetization != nil {
_, err = db.Exec("INSERT INTO collectionattributes (collection_id, attribute, value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE value = ?", collID, "monetization_pointer", *c.Monetization, *c.Monetization)
if err != nil {
log.Error("Unable to insert monetization_pointer value: %v", err)
return err
}
}
// Update rest of the collection data // Update rest of the collection data
res, err = db.Exec("UPDATE collections SET "+q.Updates+" WHERE "+q.Conditions, q.Params...) res, err = db.Exec("UPDATE collections SET "+q.Updates+" WHERE "+q.Conditions, q.Params...)
if err != nil { if err != nil {
@ -2649,11 +2658,11 @@ func (db *datastore) GetIDForRemoteUser(ctx context.Context, remoteUserID, provi
} }
type oauthAccountInfo struct { type oauthAccountInfo struct {
Provider string Provider string
ClientID string ClientID string
RemoteUserID string RemoteUserID string
DisplayName string DisplayName string
AllowDisconnect bool AllowDisconnect bool
} }
func (db *datastore) GetOauthAccounts(ctx context.Context, userID int64) ([]oauthAccountInfo, error) { func (db *datastore) GetOauthAccounts(ctx context.Context, userID int64) ([]oauthAccountInfo, error) {

View File

@ -146,6 +146,14 @@ textarea.section.norm {
</div> </div>
</div> </div>
<div class="option">
<h2>Web Monetization</h2>
<div class="section">
<p class="explain">Web Monetization enables you to receive micropayments from readers that have a <a href="https://coil.com">Coil membership</a>. Add your payment pointer to enable Web Monetization on your blog.</p>
<input type="text" name="monetization_pointer" style="width:100%" value="{{.Monetization}}" placeholder="$wallet.example.com/alice" />
</div>
</div>
<div class="option" style="text-align: center; margin-top: 4em;"> <div class="option" style="text-align: center; margin-top: 4em;">
<input type="submit" id="save-changes" value="Save changes" /> <input type="submit" id="save-changes" value="Save changes" />
<p><a href="{{if .SingleUser}}/{{else}}/{{.Alias}}/{{end}}">View Blog</a></p> <p><a href="{{if .SingleUser}}/{{else}}/{{.Alias}}/{{end}}">View Blog</a></p>