github.com/decred/politeia@v1.4.0/politeiawww/legacy/wwwpiuser.go (about) 1 // Copyright (c) 2017-2020 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package legacy 6 7 import ( 8 "encoding/json" 9 "net/http" 10 11 www "github.com/decred/politeia/politeiawww/api/www/v1" 12 "github.com/decred/politeia/util" 13 ) 14 15 // handleUserRegistrationPayment checks whether the provided transaction 16 // is on the blockchain and meets the requirements to consider the user 17 // registration fee as paid. 18 func (p *Politeiawww) handleUserRegistrationPayment(w http.ResponseWriter, r *http.Request) { 19 log.Tracef("handleUserRegistrationPayment") 20 21 user, err := p.sessions.GetSessionUser(w, r) 22 if err != nil { 23 RespondWithError(w, r, 0, 24 "handleUserRegistrationPayment: getSessionUser %v", err) 25 return 26 } 27 28 vuptr, err := p.processUserRegistrationPayment(r.Context(), user) 29 if err != nil { 30 RespondWithError(w, r, 0, 31 "handleUserRegistrationPayment: processUserRegistrationPayment %v", 32 err) 33 return 34 } 35 36 util.RespondWithJSON(w, http.StatusOK, vuptr) 37 } 38 39 // handleUserProposalPaywall returns paywall details that allows the user to 40 // purchase proposal credits. 41 func (p *Politeiawww) handleUserProposalPaywall(w http.ResponseWriter, r *http.Request) { 42 log.Tracef("handleUserProposalPaywall") 43 44 user, err := p.sessions.GetSessionUser(w, r) 45 if err != nil { 46 RespondWithError(w, r, 0, 47 "handleUserProposalPaywall: getSessionUser %v", err) 48 return 49 } 50 51 reply, err := p.processUserProposalPaywall(user) 52 if err != nil { 53 RespondWithError(w, r, 0, 54 "handleUserProposalPaywall: processUserProposalPaywall %v", err) 55 return 56 } 57 58 util.RespondWithJSON(w, http.StatusOK, reply) 59 } 60 61 // handleUserProposalPaywallTx returns the payment details for a pending 62 // proposal paywall payment. 63 func (p *Politeiawww) handleUserProposalPaywallTx(w http.ResponseWriter, r *http.Request) { 64 log.Tracef("handleUserProposalPaywallTx") 65 66 user, err := p.sessions.GetSessionUser(w, r) 67 if err != nil { 68 RespondWithError(w, r, 0, 69 "handleUserProposalPaywallTx: getSessionUser %v", err) 70 return 71 } 72 73 reply, err := p.processUserProposalPaywallTx(user) 74 if err != nil { 75 RespondWithError(w, r, 0, 76 "handleUserProposalPaywallTx: "+ 77 "processUserProposalPaywallTx %v", err) 78 return 79 } 80 81 util.RespondWithJSON(w, http.StatusOK, reply) 82 } 83 84 // handleUserProposalCredits returns the spent and unspent proposal credits for 85 // the logged in user. 86 func (p *Politeiawww) handleUserProposalCredits(w http.ResponseWriter, r *http.Request) { 87 log.Tracef("handleUserProposalCredits") 88 89 user, err := p.sessions.GetSessionUser(w, r) 90 if err != nil { 91 RespondWithError(w, r, 0, 92 "handleUserProposalCredits: getSessionUser %v", err) 93 return 94 } 95 96 reply, err := p.processUserProposalCredits(user) 97 if err != nil { 98 RespondWithError(w, r, 0, 99 "handleUserProposalCredits: processUserProposalCredits %v", err) 100 return 101 } 102 103 util.RespondWithJSON(w, http.StatusOK, reply) 104 } 105 106 // handleUserPaymentsRescan allows an admin to rescan a user's paywall address 107 // to check for any payments that may have been missed by paywall polling. 108 func (p *Politeiawww) handleUserPaymentsRescan(w http.ResponseWriter, r *http.Request) { 109 log.Tracef("handleUserPaymentsRescan") 110 111 var upr www.UserPaymentsRescan 112 decoder := json.NewDecoder(r.Body) 113 if err := decoder.Decode(&upr); err != nil { 114 RespondWithError(w, r, 0, "handleUserPaymentsRescan: unmarshal", 115 www.UserError{ 116 ErrorCode: www.ErrorStatusInvalidInput, 117 }) 118 return 119 } 120 121 reply, err := p.processUserPaymentsRescan(r.Context(), upr) 122 if err != nil { 123 RespondWithError(w, r, 0, 124 "handleUserPaymentsRescan: processUserPaymentsRescan: %v", 125 err) 126 return 127 } 128 129 util.RespondWithJSON(w, http.StatusOK, reply) 130 }