瀏覽代碼

Setup subscription endpoint

master
Immanuel Onyeka 1 年之前
父節點
當前提交
adb49143ee
共有 3 個文件被更改,包括 59 次插入5 次删除
  1. +52
    -3
      grav-admin/user/js/registration/registration.vue
  2. +1
    -0
      migrations/0_29092022_setup_tables.sql
  3. +6
    -2
      skouter.go

+ 52
- 3
grav-admin/user/js/registration/registration.vue 查看文件

@@ -7,12 +7,36 @@
</template> </template>


<script setup> <script setup>
import { ref } from "vue"
import { ref, onMounted } from "vue"
import Account from "./account.vue" import Account from "./account.vue"
import Billing from "./billing.vue" import Billing from "./billing.vue"


let err = ref("") let err = ref("")
const step = ref(0) const step = ref(0)
const token = ref("")

function getCookie(name) {
var re = new RegExp(name + "=([^;]+)")
var value = re.exec(document.cookie)

return (value != null) ? unescape(value[1]) : null
}

function getUser() {
token.value = getCookie("skouter")

return fetch(`/api/user`,
{method: 'GET',
headers: {
"Accept": "application/json",
"Authorization": `Bearer ${token.value}`,
},
}).then(response => {
if (response.ok) {
return response.json()
}
})
}


function create(user) { function create(user) {
console.log(user) console.log(user)
@@ -24,14 +48,39 @@ function create(user) {
"Accept": "application/json", "Accept": "application/json",
}, },
}).then(resp => { }).then(resp => {
console.log(resp)
if (resp.ok) {
return resp.json().then(u => { err.value = "" }).
then( () => intent(user) )
} else {
resp.text().then( e => err.value = e)
}
})
}

function intent(user) {
console.log(user)
return fetch(`/api/user/subscribe`,
{method: 'POST',
body: JSON.stringify(user),
headers: {
"Accept": "application/json",
"Authorization": `Bearer ${token.value}`,
},
}).then(resp => {
if (resp.ok) { if (resp.ok) {
return resp.json().then(u => { err.value = "" }) return resp.json().then(u => { err.value = "" })
} else { } else {
resp.text().then( e => err.value = e) resp.text().then( e => err.value = e)
} }
}).then(u => console.log(u))
})
} }

onMounted(() => {
getUser().then( u => {
intent(u)
})
})
</script> </script>


<style scoped> <style scoped>


+ 1
- 0
migrations/0_29092022_setup_tables.sql 查看文件

@@ -28,6 +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) 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,


+ 6
- 2
skouter.go 查看文件

@@ -1123,12 +1123,12 @@ func queryUser(db *sql.DB, id int) (User, error) {
u.country, u.country,
u.title, u.title,
coalesce(u.status, ''), coalesce(u.status, ''),
coalesce(u.customer_id, '')
coalesce(u.customer_id, ''),
u.verified, u.verified,
u.role, u.role,
u.address, u.address,
u.phone u.phone
FROM user u WHERE u.id = CASE @e := ? WHEN 0 THEN u.id ELSE @e END
FROM user u WHERE u.id = ?
` `
row := db.QueryRow(query, id) row := db.QueryRow(query, id)


@@ -2988,6 +2988,10 @@ func api(w http.ResponseWriter, r *http.Request) {
r.Method == http.MethodPost && r.Method == http.MethodPost &&
guard(r, 1): guard(r, 1):
changePassword(w, db, r) changePassword(w, db, r)
case match(p, "/api/user/subscribe", &args) &&
r.Method == http.MethodPost &&
guard(r, 1):
createSubscription(w, db, r)
case match(p, "/api/fees", &args) && case match(p, "/api/fees", &args) &&
r.Method == http.MethodGet && r.Method == http.MethodGet &&
guard(r, 1): guard(r, 1):


Loading…
取消
儲存