Pārlūkot izejas kodu

Fix user retrieval errors

Empty branch IDs and missing payment information caused network errors
and a missing billing component.
master
Immanuel Onyeka pirms 11 mēnešiem
vecāks
revīzija
10b88f12bc
4 mainītis faili ar 13 papildinājumiem un 9 dzēšanām
  1. +0
    -1
      grav-admin/user/js/registration/billing.vue
  2. +5
    -3
      grav-admin/user/js/registration/registration.vue
  3. +1
    -1
      migrations/0_29092022_setup_tables.sql
  4. +7
    -4
      skouter.go

+ 0
- 1
grav-admin/user/js/registration/billing.vue Parādīt failu

@@ -29,7 +29,6 @@ function submit() {
} }


onMounted(() => { onMounted(() => {
checkPayment()
payEl.mount("#payment-element") payEl.mount("#payment-element")
}) })
</script> </script>


+ 5
- 3
grav-admin/user/js/registration/registration.vue Parādīt failu

@@ -69,11 +69,11 @@ function create(user) {
}) })
} }


function intent(user) {
function intent(u) {
return fetch(`/api/user/subscribe`, return fetch(`/api/user/subscribe`,
{method: 'POST', {method: 'POST',
body: JSON.stringify(user),
body: JSON.stringify(u),
headers: { headers: {
"Accept": "application/json", "Accept": "application/json",
"Authorization": `Bearer ${token.value}`, "Authorization": `Bearer ${token.value}`,
@@ -84,9 +84,11 @@ function intent(user) {
err.value = "" err.value = ""
console.log(s) console.log(s)
sub.value = s sub.value = s
step.value++
if (["processing", "succeeded"].includes(s.paymentStatus) && if (["processing", "succeeded"].includes(s.paymentStatus) &&
clientSecret == s.clientSecret) { clientSecret == s.clientSecret) {
step.value = step.value + 2
} else if (s.paymentStatus == "requires_payment_method") {
step.value++ step.value++
} else { } else {
step.value = 0 step.value = 0


+ 1
- 1
migrations/0_29092022_setup_tables.sql Parādīt failu

@@ -28,7 +28,7 @@ CREATE TABLE user (
email VARCHAR(40) UNIQUE NOT NULL, email VARCHAR(40) UNIQUE NOT NULL,
first_name VARCHAR(30) NOT NULL, first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL, last_name VARCHAR(30) NOT NULL,
customer_id VARCHAR(255) UNIQUE NOT NULL DEFAULT '',
customer_id VARCHAR(255) NOT NULL DEFAULT '',
phone VARCHAR(20) NOT NULL DEFAULT '', phone VARCHAR(20) NOT NULL DEFAULT '',
address INT NOT NULL, address INT NOT NULL,
password CHAR(64) NOT NULL, password CHAR(64) NOT NULL,


+ 7
- 4
skouter.go Parādīt failu

@@ -902,7 +902,7 @@ func setTokenCookie(id int, role string, w http.ResponseWriter) error {
cookie := http.Cookie{Name: "skouter", cookie := http.Cookie{Name: "skouter",
Value: tokenStr, Value: tokenStr,
Path: "/", Path: "/",
Expires: time.Now().Add(time.Hour * 24)}
Expires: time.Now().Add(time.Hour * 1)}
http.SetCookie(w, &cookie) http.SetCookie(w, &cookie)
return nil return nil
@@ -1165,9 +1165,11 @@ func queryUser(db *sql.DB, id int) (User, error) {
return user, err return user, err
} }


user.Branch, err = queryBranch(db, user.Branch.Id)
if err != nil {
return user, err
if user.Branch.Id > 0 {
user.Branch, err = queryBranch(db, user.Branch.Id)
if err != nil {
return user, err
}
} }


return user, nil return user, nil
@@ -3027,6 +3029,7 @@ func createSubscription(cid string) (*stripe.Subscription, error) {
func subscribe(w http.ResponseWriter, db *sql.DB, r *http.Request) { func subscribe(w http.ResponseWriter, db *sql.DB, r *http.Request) {
claims, err := getClaims(r) claims, err := getClaims(r)
user, err := queryUser(db, claims.Id) user, err := queryUser(db, claims.Id)

if err != nil { if err != nil {
w.WriteHeader(422) w.WriteHeader(422)
return return


Notiek ielāde…
Atcelt
Saglabāt